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