Mercurial > mplayer.hg
annotate libmpcodecs/native/qtrle.c @ 6690:e8f7dbe19df0
Sync by Jiri Svoboda <jiri.svoboda at seznam.cz>
author | atmos4 |
---|---|
date | Wed, 10 Jul 2002 03:19:28 +0000 |
parents | 92b29c3ed0c0 |
children | 180e27f21ff2 |
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 |
6656 | 64 while (stream_ptr < encoded_size && |
65 (rle_code = (signed char)encoded[stream_ptr++]) != -1) | |
3687
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
66 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
67 if (rle_code == 0) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
68 // there's another skip code in the stream |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
69 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
|
70 else if (rle_code < 0) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
71 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
72 // decode the run length code |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
73 rle_code = -rle_code; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
74 r = encoded[stream_ptr++]; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
75 g = encoded[stream_ptr++]; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
76 b = encoded[stream_ptr++]; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
77 while (rle_code--) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
78 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
79 decoded[pixel_ptr++] = b; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
80 decoded[pixel_ptr++] = g; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
81 decoded[pixel_ptr++] = r; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
82 if (bytes_per_pixel == 4) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
83 pixel_ptr++; |
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 } |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
86 else |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
87 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
88 // copy pixels directly to output |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
89 while (rle_code--) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
90 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
91 decoded[pixel_ptr++] = encoded[stream_ptr + 2]; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
92 decoded[pixel_ptr++] = encoded[stream_ptr + 1]; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
93 decoded[pixel_ptr++] = encoded[stream_ptr + 0]; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
94 stream_ptr += 3; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
95 if (bytes_per_pixel == 4) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
96 pixel_ptr++; |
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 |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
101 row_ptr += row_inc; |
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 |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
105 void qt_decode_rle( |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
106 unsigned char *encoded, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
107 int encoded_size, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
108 unsigned char *decoded, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
109 int width, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
110 int height, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
111 int encoded_bpp, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
112 int bytes_per_pixel) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
113 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
114 switch (encoded_bpp) |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
115 { |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
116 case 24: |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
117 qt_decode_rle24( |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
118 encoded, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
119 encoded_size, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
120 decoded, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
121 width, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
122 height, |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
123 bytes_per_pixel); |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
124 break; |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
125 } |
7fb817c9060b
This commit adds initial support for Quicktime Animation (RLE) video. It
melanson
parents:
diff
changeset
|
126 } |