annotate qtrle.c @ 5580:6366586083bb

Added support for choosing weather to use double-buffering or single buffering
author mark
date Sat, 13 Apr 2002 00:14:59 +0000
parents 7fb817c9060b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3687
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
1 /*
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
2 Quicktime Animation (RLE) Decoder for MPlayer
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
3
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
4 (C) 2001 Mike Melanson
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
5 */
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
6
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
7 #include "config.h"
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
8 #include "bswap.h"
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
9
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
10 #define BE_16(x) (be2me_16(*(unsigned short *)(x)))
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
11 #define BE_32(x) (be2me_32(*(unsigned int *)(x)))
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
12
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
13 // 256 RGB entries; 25% of these bytes will be unused, but it's faster
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
14 // to index 4-byte entries
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
15 static unsigned char palette[256 * 4];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
16
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
17 void qt_decode_rle24(
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
18 unsigned char *encoded,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
19 int encoded_size,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
20 unsigned char *decoded,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
21 int width,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
22 int height,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
23 int bytes_per_pixel)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
24 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
25 int stream_ptr;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
26 int header;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
27 int start_line;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
28 int lines_to_change;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
29 signed char rle_code;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
30 int row_ptr, pixel_ptr;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
31 int row_inc = bytes_per_pixel * width;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
32 unsigned char r, g, b;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
33
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
34 // check if this frame is even supposed to change
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
35 if (encoded_size < 8)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
36 return;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
37
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
38 // start after the chunk size
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
39 stream_ptr = 4;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
40
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
41 // fetch the header
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
42 header = BE_16(&encoded[stream_ptr]);
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
43 stream_ptr += 2;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
44
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
45 // if a header is present, fetch additional decoding parameters
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
46 if (header & 0x0008)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
47 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
48 start_line = BE_16(&encoded[stream_ptr]);
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
49 stream_ptr += 4;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
50 lines_to_change = BE_16(&encoded[stream_ptr]);
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
51 stream_ptr += 4;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
52 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
53 else
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
54 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
55 start_line = 0;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
56 lines_to_change = height;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
57 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
58
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
59 row_ptr = row_inc * start_line;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
60 while (lines_to_change--)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
61 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
62 pixel_ptr = row_ptr + ((encoded[stream_ptr++] - 1) * bytes_per_pixel);
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
63
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
64 while ((rle_code = (signed char)encoded[stream_ptr++]) != -1)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
65 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
66 if (rle_code == 0)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
67 // there's another skip code in the stream
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
68 pixel_ptr += ((encoded[stream_ptr++] - 1) * bytes_per_pixel);
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
69 else if (rle_code < 0)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
70 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
71 // decode the run length code
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
72 rle_code = -rle_code;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
73 r = encoded[stream_ptr++];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
74 g = encoded[stream_ptr++];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
75 b = encoded[stream_ptr++];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
76 while (rle_code--)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
77 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
78 decoded[pixel_ptr++] = b;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
79 decoded[pixel_ptr++] = g;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
80 decoded[pixel_ptr++] = r;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
81 if (bytes_per_pixel == 4)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
82 pixel_ptr++;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
83 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
84 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
85 else
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
86 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
87 // copy pixels directly to output
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
88 while (rle_code--)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
89 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
90 decoded[pixel_ptr++] = encoded[stream_ptr + 2];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
91 decoded[pixel_ptr++] = encoded[stream_ptr + 1];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
92 decoded[pixel_ptr++] = encoded[stream_ptr + 0];
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
93 stream_ptr += 3;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
94 if (bytes_per_pixel == 4)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
95 pixel_ptr++;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
96 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
97 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
98 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
99
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
100 row_ptr += row_inc;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
101 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
102 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
103
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
104 void qt_decode_rle(
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
105 unsigned char *encoded,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
106 int encoded_size,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
107 unsigned char *decoded,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
108 int width,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
109 int height,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
110 int encoded_bpp,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
111 int bytes_per_pixel)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
112 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
113 switch (encoded_bpp)
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
114 {
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
115 case 24:
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
116 qt_decode_rle24(
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
117 encoded,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
118 encoded_size,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
119 decoded,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
120 width,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
121 height,
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
122 bytes_per_pixel);
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
123 break;
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
124 }
7fb817c9060b This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff changeset
125 }