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