Mercurial > mplayer.hg
annotate libmpcodecs/native/fli.c @ 6714:be17a987e0a1
fix tv bazze
author | atmos4 |
---|---|
date | Fri, 12 Jul 2002 03:26:46 +0000 |
parents | e6c8285a4bd8 |
children | efb1ac9d44d7 |
rev | line source |
---|---|
3155 | 1 /* |
2 FLI Decoder for MPlayer | |
3 | |
4 (C) 2001 Mike Melanson | |
3185 | 5 |
6 32bpp support (c) alex | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
7 |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
8 Additional code and bug fixes by Roberto Togni |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
9 |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
10 For information on the FLI format, as well as various traps to |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
11 avoid while programming one, visit: |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
12 http://www.pcisys.net/~melanson/codecs/ |
3155 | 13 */ |
14 | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
15 #include <stdio.h> |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
16 #include <stdlib.h> |
6131
e6c8285a4bd8
memset and memcpy were used without #include <string.h> in a few places.
arpi
parents:
5602
diff
changeset
|
17 #include <string.h> |
3509
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3185
diff
changeset
|
18 #include "config.h" |
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3185
diff
changeset
|
19 #include "bswap.h" |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
20 #include "mp_msg.h" |
3509
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3185
diff
changeset
|
21 |
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3185
diff
changeset
|
22 #define LE_16(x) (le2me_16(*(unsigned short *)(x))) |
21c7b77b3e83
fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents:
3185
diff
changeset
|
23 #define LE_32(x) (le2me_32(*(unsigned int *)(x))) |
3155 | 24 |
25 #define FLI_256_COLOR 4 | |
26 #define FLI_DELTA 7 | |
27 #define FLI_COLOR 11 | |
28 #define FLI_LC 12 | |
29 #define FLI_BLACK 13 | |
30 #define FLI_BRUN 15 | |
31 #define FLI_COPY 16 | |
32 #define FLI_MINI 18 | |
33 | |
34 // 256 RGB entries; 25% of these bytes will be unused, but it's faster | |
35 // to index 4-byte entries | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
36 #define PALETTE_SIZE 1024 |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
37 static unsigned char palette[PALETTE_SIZE]; |
3155 | 38 |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
39 void *init_fli_decoder(int width, int height) |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
40 { |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
41 memset(palette, 0, PALETTE_SIZE); |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
42 |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
43 return malloc(width * height * sizeof (unsigned char)); |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
44 } |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
45 |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
46 void decode_fli_frame( |
3155 | 47 unsigned char *encoded, |
48 int encoded_size, | |
49 unsigned char *decoded, | |
50 int width, | |
51 int height, | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
52 int bytes_per_pixel, |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
53 void *context) |
3155 | 54 { |
55 int stream_ptr = 0; | |
4887 | 56 int stream_ptr_after_color_chunk; |
3155 | 57 int pixel_ptr; |
58 int palette_ptr1; | |
59 int palette_ptr2; | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
60 unsigned char palette_idx1; |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
61 unsigned char palette_idx2; |
3155 | 62 |
63 unsigned int frame_size; | |
64 int num_chunks; | |
65 | |
66 unsigned int chunk_size; | |
67 int chunk_type; | |
68 | |
69 int i, j; | |
70 | |
71 int color_packets; | |
72 int color_changes; | |
73 int color_scale; | |
74 | |
75 int lines; | |
76 int compressed_lines; | |
77 int starting_line; | |
78 signed short line_packets; | |
79 int y_ptr; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
80 int line_inc = width * bytes_per_pixel; |
3155 | 81 signed char byte_run; |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
82 int pixel_skip; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
83 int update_whole_frame = 0; // Palette change flag |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
84 unsigned char *fli_ghost_image = (unsigned char *)context; |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
85 int ghost_pixel_ptr; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
86 int ghost_y_ptr; |
4887 | 87 |
3155 | 88 frame_size = LE_32(&encoded[stream_ptr]); |
89 stream_ptr += 6; // skip the magic number | |
90 num_chunks = LE_16(&encoded[stream_ptr]); | |
91 stream_ptr += 10; // skip padding | |
92 | |
93 // iterate through the chunks | |
94 frame_size -= 16; | |
95 while ((frame_size > 0) && (num_chunks > 0)) | |
96 { | |
97 chunk_size = LE_32(&encoded[stream_ptr]); | |
98 stream_ptr += 4; | |
99 chunk_type = LE_16(&encoded[stream_ptr]); | |
100 stream_ptr += 2; | |
101 | |
102 switch (chunk_type) | |
103 { | |
104 case FLI_256_COLOR: | |
105 case FLI_COLOR: | |
4887 | 106 stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6; |
3155 | 107 if (chunk_type == FLI_COLOR) |
108 color_scale = 4; | |
109 else | |
110 color_scale = 1; | |
111 // set up the palette | |
112 color_packets = LE_16(&encoded[stream_ptr]); | |
113 stream_ptr += 2; | |
114 palette_ptr1 = 0; | |
115 for (i = 0; i < color_packets; i++) | |
116 { | |
117 // first byte is how many colors to skip | |
118 palette_ptr1 += (encoded[stream_ptr++] * 4); | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
119 // wrap around, for good measure |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
120 if (palette_ptr1 >= PALETTE_SIZE) |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
121 palette_ptr1 = 0; |
3155 | 122 // next byte indicates how many entries to change |
123 color_changes = encoded[stream_ptr++]; | |
124 // if there are 0 color changes, there are actually 256 | |
125 if (color_changes == 0) | |
126 color_changes = 256; | |
127 for (j = 0; j < color_changes; j++) | |
128 { | |
129 palette[palette_ptr1++] = encoded[stream_ptr + 2] * color_scale; | |
130 palette[palette_ptr1++] = encoded[stream_ptr + 1] * color_scale; | |
131 palette[palette_ptr1++] = encoded[stream_ptr + 0] * color_scale; | |
132 palette_ptr1++; | |
133 stream_ptr += 3; | |
134 } | |
135 } | |
4887 | 136 |
137 // color chunks sometimes have weird 16-bit alignment issues; | |
138 // therefore, take the hardline approach and set the stream_ptr | |
139 // to the value calculate w.r.t. the size specified by the color | |
140 // chunk header | |
141 stream_ptr = stream_ptr_after_color_chunk; | |
142 | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
143 /* Palette has changed, must update frame */ |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
144 update_whole_frame = 1; |
3155 | 145 break; |
146 | |
147 case FLI_DELTA: | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
148 y_ptr = ghost_y_ptr = 0; |
3155 | 149 compressed_lines = LE_16(&encoded[stream_ptr]); |
150 stream_ptr += 2; | |
151 while (compressed_lines > 0) | |
152 { | |
153 line_packets = LE_16(&encoded[stream_ptr]); | |
154 stream_ptr += 2; | |
155 if (line_packets < 0) | |
156 { | |
157 line_packets = -line_packets; | |
158 y_ptr += (line_packets * line_inc); | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
159 ghost_y_ptr += (line_packets * width); |
3155 | 160 } |
161 else | |
162 { | |
163 pixel_ptr = y_ptr; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
164 ghost_pixel_ptr = ghost_y_ptr; |
3155 | 165 for (i = 0; i < line_packets; i++) |
166 { | |
167 // account for the skip bytes | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
168 pixel_skip = encoded[stream_ptr++]; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
169 pixel_ptr += pixel_skip * bytes_per_pixel; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
170 ghost_pixel_ptr += pixel_skip; |
3155 | 171 byte_run = encoded[stream_ptr++]; |
172 if (byte_run < 0) | |
173 { | |
174 byte_run = -byte_run; | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
175 palette_ptr1 = (palette_idx1 = encoded[stream_ptr++]) * 4; |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
176 palette_ptr2 = (palette_idx2 = encoded[stream_ptr++]) * 4; |
3155 | 177 for (j = 0; j < byte_run; j++) |
178 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
179 fli_ghost_image[ghost_pixel_ptr++] = palette_idx1; |
3155 | 180 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
181 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; | |
182 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; | |
3185 | 183 if (bytes_per_pixel == 4) /* 32bpp */ |
184 pixel_ptr++; | |
3155 | 185 |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
186 fli_ghost_image[ghost_pixel_ptr++] = palette_idx2; |
3155 | 187 decoded[pixel_ptr++] = palette[palette_ptr2 + 0]; |
188 decoded[pixel_ptr++] = palette[palette_ptr2 + 1]; | |
189 decoded[pixel_ptr++] = palette[palette_ptr2 + 2]; | |
3185 | 190 if (bytes_per_pixel == 4) /* 32bpp */ |
191 pixel_ptr++; | |
3155 | 192 } |
193 } | |
194 else | |
195 { | |
196 for (j = 0; j < byte_run * 2; j++) | |
197 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
198 palette_ptr1 = (palette_idx1 = encoded[stream_ptr++]) * 4; |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
199 fli_ghost_image[ghost_pixel_ptr++] = palette_idx1; |
3155 | 200 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
201 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; | |
202 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; | |
3185 | 203 if (bytes_per_pixel == 4) /* 32bpp */ |
204 pixel_ptr++; | |
3155 | 205 } |
206 } | |
207 } | |
208 y_ptr += line_inc; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
209 ghost_y_ptr += width; |
3155 | 210 compressed_lines--; |
211 } | |
212 } | |
213 break; | |
214 | |
215 case FLI_LC: | |
216 // line compressed | |
217 starting_line = LE_16(&encoded[stream_ptr]); | |
218 stream_ptr += 2; | |
219 y_ptr = starting_line * line_inc; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
220 ghost_y_ptr = starting_line * width; |
3155 | 221 |
222 compressed_lines = LE_16(&encoded[stream_ptr]); | |
223 stream_ptr += 2; | |
224 while (compressed_lines > 0) | |
225 { | |
226 pixel_ptr = y_ptr; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
227 ghost_pixel_ptr = ghost_y_ptr; |
3155 | 228 line_packets = encoded[stream_ptr++]; |
229 if (line_packets > 0) | |
230 { | |
231 for (i = 0; i < line_packets; i++) | |
232 { | |
233 // account for the skip bytes | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
234 pixel_skip = encoded[stream_ptr++]; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
235 pixel_ptr += pixel_skip * bytes_per_pixel; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
236 ghost_pixel_ptr += pixel_skip; |
3155 | 237 byte_run = encoded[stream_ptr++]; |
238 if (byte_run > 0) | |
239 { | |
240 for (j = 0; j < byte_run; j++) | |
241 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
242 palette_ptr1 = (palette_idx1 = encoded[stream_ptr++]) * 4; |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
243 fli_ghost_image[ghost_pixel_ptr++] = palette_idx1; |
3155 | 244 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
245 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; | |
246 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; | |
3185 | 247 if (bytes_per_pixel == 4) /* 32bpp */ |
248 pixel_ptr++; | |
3155 | 249 } |
250 } | |
251 else | |
252 { | |
253 byte_run = -byte_run; | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
254 palette_ptr1 = (palette_idx1 = encoded[stream_ptr++]) * 4; |
3155 | 255 for (j = 0; j < byte_run; j++) |
256 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
257 fli_ghost_image[ghost_pixel_ptr++] = palette_idx1; |
3155 | 258 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
259 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; | |
260 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; | |
3185 | 261 if (bytes_per_pixel == 4) /* 32bpp */ |
262 pixel_ptr++; | |
3155 | 263 } |
264 } | |
265 } | |
266 } | |
267 | |
268 y_ptr += line_inc; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
269 ghost_y_ptr += width; |
3155 | 270 compressed_lines--; |
271 } | |
272 break; | |
273 | |
274 case FLI_BLACK: | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
275 // set the whole frame to color 0 (which is usually black) by |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
276 // clearing the ghost image and trigger a full frame update |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
277 memset(fli_ghost_image, 0, width * height * sizeof(unsigned char)); |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
278 update_whole_frame = 1; |
3155 | 279 break; |
280 | |
281 case FLI_BRUN: | |
282 // byte run compression | |
283 y_ptr = 0; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
284 ghost_y_ptr = 0; |
3155 | 285 for (lines = 0; lines < height; lines++) |
286 { | |
287 pixel_ptr = y_ptr; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
288 ghost_pixel_ptr = ghost_y_ptr; |
3155 | 289 line_packets = encoded[stream_ptr++]; |
290 for (i = 0; i < line_packets; i++) | |
291 { | |
292 byte_run = encoded[stream_ptr++]; | |
293 if (byte_run > 0) | |
294 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
295 palette_ptr1 = (palette_idx1 = encoded[stream_ptr++]) * 4; |
3155 | 296 for (j = 0; j < byte_run; j++) |
297 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
298 fli_ghost_image[ghost_pixel_ptr++] = palette_idx1; |
3155 | 299 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
300 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; | |
301 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; | |
3185 | 302 if (bytes_per_pixel == 4) /* 32bpp */ |
303 pixel_ptr++; | |
3155 | 304 } |
305 } | |
306 else // copy bytes if byte_run < 0 | |
307 { | |
308 byte_run = -byte_run; | |
309 for (j = 0; j < byte_run; j++) | |
310 { | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
311 palette_ptr1 = (palette_idx1 = encoded[stream_ptr++]) * 4; |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
312 fli_ghost_image[ghost_pixel_ptr++] = palette_idx1; |
3155 | 313 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
314 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; | |
315 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; | |
3185 | 316 if (bytes_per_pixel == 4) /* 32bpp */ |
317 pixel_ptr++; | |
3155 | 318 } |
319 } | |
320 } | |
321 | |
322 y_ptr += line_inc; | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
323 ghost_y_ptr += width; |
3155 | 324 } |
325 break; | |
326 | |
327 case FLI_COPY: | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
328 // copy the chunk (uncompressed frame) to the ghost image and |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
329 // schedule the whole frame to be updated |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
330 if (chunk_size - 6 > width * height) |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
331 { |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
332 mp_msg(MSGT_DECVIDEO, MSGL_WARN, |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
333 "FLI: in chunk FLI_COPY : source data (%d bytes) bigger than image," \ |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
334 " skipping chunk\n", |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
335 chunk_size - 6); |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
336 break; |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
337 } |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
338 else |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
339 memcpy(fli_ghost_image, &encoded[stream_ptr], chunk_size - 6); |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
340 stream_ptr += chunk_size - 6; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
341 update_whole_frame = 1; |
3155 | 342 break; |
343 | |
344 case FLI_MINI: | |
345 // sort of a thumbnail? disregard this chunk... | |
346 stream_ptr += chunk_size - 6; | |
347 break; | |
348 | |
349 default: | |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
350 mp_msg (MSGT_DECVIDEO, MSGL_WARN, |
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
351 "FLI: Unrecognized chunk type: %d\n", chunk_type); |
3155 | 352 break; |
353 } | |
354 | |
355 frame_size -= chunk_size; | |
356 num_chunks--; | |
357 } | |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
358 |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
359 if (update_whole_frame) |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
360 { |
4692 | 361 pixel_ptr = ghost_pixel_ptr = 0; |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
362 while (pixel_ptr < (width * height * bytes_per_pixel)) |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
363 { |
4719
62eb233b12ed
shrink the size of the ghost image, courtesy of Roberto Togni
melanson
parents:
4692
diff
changeset
|
364 palette_ptr1 = fli_ghost_image[ghost_pixel_ptr++] * 4; |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
365 decoded[pixel_ptr++] = palette[palette_ptr1 + 0]; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
366 decoded[pixel_ptr++] = palette[palette_ptr1 + 1]; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
367 decoded[pixel_ptr++] = palette[palette_ptr1 + 2]; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
368 if (bytes_per_pixel == 4) /* 32bpp */ |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
369 pixel_ptr++; |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
370 } |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
371 } |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
372 |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
373 // by the end of the chunk, the stream ptr should equal the frame |
4688 | 374 // size (minus 1, possibly); if it doesn't, issue a warning |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
375 if ((stream_ptr != encoded_size) && (stream_ptr != encoded_size - 1)) |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
376 mp_msg(MSGT_DECVIDEO, MSGL_WARN, |
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
377 " warning: processed FLI chunk where encoded size = %d\n" \ |
4688 | 378 " and final chunk ptr = %d\n", |
4687
2973e997c4a5
some obscure bug fixes to the FLI decoder, with many thanks to Roberto
melanson
parents:
3737
diff
changeset
|
379 encoded_size, stream_ptr); |
3155 | 380 } |