annotate fli.c @ 3639:64ee21b3bd09

Modified the sync code once again, commented out hardware pts sync (I'll likely burn in hell before understanding how to get this bastard to sync well) Added automagic setup of aspect ratio, will remove the "aspect-bug" (I hope). As well as please you rich 16:9 doods ;)
author mswitch
date Thu, 20 Dec 2001 20:50:35 +0000
parents 21c7b77b3e83
children 7fb817c9060b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
1 /*
9200edf69d1d initial commit
melanson
parents:
diff changeset
2 FLI Decoder for MPlayer
9200edf69d1d initial commit
melanson
parents:
diff changeset
3
9200edf69d1d initial commit
melanson
parents:
diff changeset
4 (C) 2001 Mike Melanson
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
5
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
6 32bpp support (c) alex
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
7 */
9200edf69d1d initial commit
melanson
parents:
diff changeset
8
3509
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
9 #include "config.h"
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
10 #include "bswap.h"
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
11
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
12 #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
13 #define LE_32(x) (le2me_32(*(unsigned int *)(x)))
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
14
9200edf69d1d initial commit
melanson
parents:
diff changeset
15 #define FLI_256_COLOR 4
9200edf69d1d initial commit
melanson
parents:
diff changeset
16 #define FLI_DELTA 7
9200edf69d1d initial commit
melanson
parents:
diff changeset
17 #define FLI_COLOR 11
9200edf69d1d initial commit
melanson
parents:
diff changeset
18 #define FLI_LC 12
9200edf69d1d initial commit
melanson
parents:
diff changeset
19 #define FLI_BLACK 13
9200edf69d1d initial commit
melanson
parents:
diff changeset
20 #define FLI_BRUN 15
9200edf69d1d initial commit
melanson
parents:
diff changeset
21 #define FLI_COPY 16
9200edf69d1d initial commit
melanson
parents:
diff changeset
22 #define FLI_MINI 18
9200edf69d1d initial commit
melanson
parents:
diff changeset
23
9200edf69d1d initial commit
melanson
parents:
diff changeset
24 // 256 RGB entries; 25% of these bytes will be unused, but it's faster
9200edf69d1d initial commit
melanson
parents:
diff changeset
25 // to index 4-byte entries
9200edf69d1d initial commit
melanson
parents:
diff changeset
26 static unsigned char palette[256 * 4];
9200edf69d1d initial commit
melanson
parents:
diff changeset
27
9200edf69d1d initial commit
melanson
parents:
diff changeset
28 void AVI_Decode_Fli(
9200edf69d1d initial commit
melanson
parents:
diff changeset
29 unsigned char *encoded,
9200edf69d1d initial commit
melanson
parents:
diff changeset
30 int encoded_size,
9200edf69d1d initial commit
melanson
parents:
diff changeset
31 unsigned char *decoded,
9200edf69d1d initial commit
melanson
parents:
diff changeset
32 int width,
9200edf69d1d initial commit
melanson
parents:
diff changeset
33 int height,
9200edf69d1d initial commit
melanson
parents:
diff changeset
34 int bytes_per_pixel)
9200edf69d1d initial commit
melanson
parents:
diff changeset
35 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
36 int stream_ptr = 0;
9200edf69d1d initial commit
melanson
parents:
diff changeset
37 int pixel_ptr;
9200edf69d1d initial commit
melanson
parents:
diff changeset
38 int palette_ptr1;
9200edf69d1d initial commit
melanson
parents:
diff changeset
39 int palette_ptr2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
40
9200edf69d1d initial commit
melanson
parents:
diff changeset
41 unsigned int frame_size;
9200edf69d1d initial commit
melanson
parents:
diff changeset
42 int num_chunks;
9200edf69d1d initial commit
melanson
parents:
diff changeset
43
9200edf69d1d initial commit
melanson
parents:
diff changeset
44 unsigned int chunk_size;
9200edf69d1d initial commit
melanson
parents:
diff changeset
45 int chunk_type;
9200edf69d1d initial commit
melanson
parents:
diff changeset
46
9200edf69d1d initial commit
melanson
parents:
diff changeset
47 int i, j;
9200edf69d1d initial commit
melanson
parents:
diff changeset
48
9200edf69d1d initial commit
melanson
parents:
diff changeset
49 int color_packets;
9200edf69d1d initial commit
melanson
parents:
diff changeset
50 int color_changes;
9200edf69d1d initial commit
melanson
parents:
diff changeset
51 int color_scale;
9200edf69d1d initial commit
melanson
parents:
diff changeset
52
9200edf69d1d initial commit
melanson
parents:
diff changeset
53 int lines;
9200edf69d1d initial commit
melanson
parents:
diff changeset
54 int compressed_lines;
9200edf69d1d initial commit
melanson
parents:
diff changeset
55 int starting_line;
9200edf69d1d initial commit
melanson
parents:
diff changeset
56 signed short line_packets;
9200edf69d1d initial commit
melanson
parents:
diff changeset
57 int y_ptr;
9200edf69d1d initial commit
melanson
parents:
diff changeset
58 int line_inc;
9200edf69d1d initial commit
melanson
parents:
diff changeset
59 signed char byte_run;
9200edf69d1d initial commit
melanson
parents:
diff changeset
60
9200edf69d1d initial commit
melanson
parents:
diff changeset
61 frame_size = LE_32(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
62 stream_ptr += 6; // skip the magic number
9200edf69d1d initial commit
melanson
parents:
diff changeset
63 num_chunks = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
64 stream_ptr += 10; // skip padding
9200edf69d1d initial commit
melanson
parents:
diff changeset
65
9200edf69d1d initial commit
melanson
parents:
diff changeset
66 // iterate through the chunks
9200edf69d1d initial commit
melanson
parents:
diff changeset
67 frame_size -= 16;
9200edf69d1d initial commit
melanson
parents:
diff changeset
68 while ((frame_size > 0) && (num_chunks > 0))
9200edf69d1d initial commit
melanson
parents:
diff changeset
69 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
70 chunk_size = LE_32(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
71 stream_ptr += 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
72 chunk_type = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
73 stream_ptr += 2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
74
9200edf69d1d initial commit
melanson
parents:
diff changeset
75 switch (chunk_type)
9200edf69d1d initial commit
melanson
parents:
diff changeset
76 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
77 case FLI_256_COLOR:
9200edf69d1d initial commit
melanson
parents:
diff changeset
78 case FLI_COLOR:
9200edf69d1d initial commit
melanson
parents:
diff changeset
79 if (chunk_type == FLI_COLOR)
9200edf69d1d initial commit
melanson
parents:
diff changeset
80 color_scale = 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
81 else
9200edf69d1d initial commit
melanson
parents:
diff changeset
82 color_scale = 1;
9200edf69d1d initial commit
melanson
parents:
diff changeset
83 // set up the palette
9200edf69d1d initial commit
melanson
parents:
diff changeset
84 color_packets = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
85 stream_ptr += 2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
86 palette_ptr1 = 0;
9200edf69d1d initial commit
melanson
parents:
diff changeset
87 for (i = 0; i < color_packets; i++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
88 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
89 // first byte is how many colors to skip
9200edf69d1d initial commit
melanson
parents:
diff changeset
90 palette_ptr1 += (encoded[stream_ptr++] * 4);
9200edf69d1d initial commit
melanson
parents:
diff changeset
91 // next byte indicates how many entries to change
9200edf69d1d initial commit
melanson
parents:
diff changeset
92 color_changes = encoded[stream_ptr++];
9200edf69d1d initial commit
melanson
parents:
diff changeset
93 // if there are 0 color changes, there are actually 256
9200edf69d1d initial commit
melanson
parents:
diff changeset
94 if (color_changes == 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
95 color_changes = 256;
9200edf69d1d initial commit
melanson
parents:
diff changeset
96 for (j = 0; j < color_changes; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
97 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
98 palette[palette_ptr1++] = encoded[stream_ptr + 2] * color_scale;
9200edf69d1d initial commit
melanson
parents:
diff changeset
99 palette[palette_ptr1++] = encoded[stream_ptr + 1] * color_scale;
9200edf69d1d initial commit
melanson
parents:
diff changeset
100 palette[palette_ptr1++] = encoded[stream_ptr + 0] * color_scale;
9200edf69d1d initial commit
melanson
parents:
diff changeset
101 palette_ptr1++;
9200edf69d1d initial commit
melanson
parents:
diff changeset
102 stream_ptr += 3;
9200edf69d1d initial commit
melanson
parents:
diff changeset
103 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
104 }
3509
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
105 // 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
106 // 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
107 if (stream_ptr & 0x01)
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
108 stream_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
109 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
110
9200edf69d1d initial commit
melanson
parents:
diff changeset
111 case FLI_DELTA:
9200edf69d1d initial commit
melanson
parents:
diff changeset
112 line_inc = width * bytes_per_pixel;
9200edf69d1d initial commit
melanson
parents:
diff changeset
113 y_ptr = 0;
9200edf69d1d initial commit
melanson
parents:
diff changeset
114 compressed_lines = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
115 stream_ptr += 2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
116 while (compressed_lines > 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
117 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
118 line_packets = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
119 stream_ptr += 2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
120 if (line_packets < 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
121 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
122 line_packets = -line_packets;
9200edf69d1d initial commit
melanson
parents:
diff changeset
123 y_ptr += (line_packets * line_inc);
9200edf69d1d initial commit
melanson
parents:
diff changeset
124 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
125 else
9200edf69d1d initial commit
melanson
parents:
diff changeset
126 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
127 pixel_ptr = y_ptr;
9200edf69d1d initial commit
melanson
parents:
diff changeset
128 for (i = 0; i < line_packets; i++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
129 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
130 // account for the skip bytes
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
131 pixel_ptr += encoded[stream_ptr++] * bytes_per_pixel;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
132 byte_run = encoded[stream_ptr++];
9200edf69d1d initial commit
melanson
parents:
diff changeset
133 if (byte_run < 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
134 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
135 byte_run = -byte_run;
9200edf69d1d initial commit
melanson
parents:
diff changeset
136 palette_ptr1 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
137 palette_ptr2 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
138 for (j = 0; j < byte_run; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
139 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
140 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
141 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
142 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
143 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
144 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
145
9200edf69d1d initial commit
melanson
parents:
diff changeset
146 decoded[pixel_ptr++] = palette[palette_ptr2 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
147 decoded[pixel_ptr++] = palette[palette_ptr2 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
148 decoded[pixel_ptr++] = palette[palette_ptr2 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
149 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
150 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
151 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
152 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
153 else
9200edf69d1d initial commit
melanson
parents:
diff changeset
154 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
155 for (j = 0; j < byte_run * 2; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
156 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
157 palette_ptr1 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
158 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
159 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
160 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
161 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
162 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
163 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
164 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
165 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
166 y_ptr += line_inc;
9200edf69d1d initial commit
melanson
parents:
diff changeset
167 compressed_lines--;
9200edf69d1d initial commit
melanson
parents:
diff changeset
168 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
169 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
170 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
171
9200edf69d1d initial commit
melanson
parents:
diff changeset
172 case FLI_LC:
9200edf69d1d initial commit
melanson
parents:
diff changeset
173 // line compressed
9200edf69d1d initial commit
melanson
parents:
diff changeset
174 line_inc = width * bytes_per_pixel;
9200edf69d1d initial commit
melanson
parents:
diff changeset
175 starting_line = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
176 stream_ptr += 2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
177 y_ptr = starting_line * line_inc;
9200edf69d1d initial commit
melanson
parents:
diff changeset
178
9200edf69d1d initial commit
melanson
parents:
diff changeset
179 compressed_lines = LE_16(&encoded[stream_ptr]);
9200edf69d1d initial commit
melanson
parents:
diff changeset
180 stream_ptr += 2;
9200edf69d1d initial commit
melanson
parents:
diff changeset
181 while (compressed_lines > 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
182 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
183 pixel_ptr = y_ptr;
9200edf69d1d initial commit
melanson
parents:
diff changeset
184 line_packets = encoded[stream_ptr++];
9200edf69d1d initial commit
melanson
parents:
diff changeset
185 if (line_packets > 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
186 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
187 for (i = 0; i < line_packets; i++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
188 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
189 // account for the skip bytes
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
190 pixel_ptr += encoded[stream_ptr++] * bytes_per_pixel;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
191 byte_run = encoded[stream_ptr++];
9200edf69d1d initial commit
melanson
parents:
diff changeset
192 if (byte_run > 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
193 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
194 for (j = 0; j < byte_run; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
195 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
196 palette_ptr1 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
197 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
198 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
199 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
200 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
201 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
202 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
203 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
204 else
9200edf69d1d initial commit
melanson
parents:
diff changeset
205 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
206 byte_run = -byte_run;
9200edf69d1d initial commit
melanson
parents:
diff changeset
207 palette_ptr1 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
208 for (j = 0; j < byte_run; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
209 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
210 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
211 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
212 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
213 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
214 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
215 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
216 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
217 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
218 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
219
9200edf69d1d initial commit
melanson
parents:
diff changeset
220 y_ptr += line_inc;
9200edf69d1d initial commit
melanson
parents:
diff changeset
221 compressed_lines--;
9200edf69d1d initial commit
melanson
parents:
diff changeset
222 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
223 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
224
9200edf69d1d initial commit
melanson
parents:
diff changeset
225 case FLI_BLACK:
9200edf69d1d initial commit
melanson
parents:
diff changeset
226 // set the whole frame to color 0 (which is usually black)
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
227 for (pixel_ptr = 0; pixel_ptr < (width * height * bytes_per_pixel); pixel_ptr++)
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
228 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
229 decoded[pixel_ptr++] = palette[0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
230 decoded[pixel_ptr++] = palette[1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
231 decoded[pixel_ptr++] = palette[2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
232 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
233 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
234 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
235 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
236
9200edf69d1d initial commit
melanson
parents:
diff changeset
237 case FLI_BRUN:
9200edf69d1d initial commit
melanson
parents:
diff changeset
238 // byte run compression
9200edf69d1d initial commit
melanson
parents:
diff changeset
239 line_inc = width * bytes_per_pixel;
9200edf69d1d initial commit
melanson
parents:
diff changeset
240 y_ptr = 0;
9200edf69d1d initial commit
melanson
parents:
diff changeset
241 for (lines = 0; lines < height; lines++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
242 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
243 pixel_ptr = y_ptr;
9200edf69d1d initial commit
melanson
parents:
diff changeset
244 line_packets = encoded[stream_ptr++];
9200edf69d1d initial commit
melanson
parents:
diff changeset
245 for (i = 0; i < line_packets; i++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
246 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
247 byte_run = encoded[stream_ptr++];
9200edf69d1d initial commit
melanson
parents:
diff changeset
248 if (byte_run > 0)
9200edf69d1d initial commit
melanson
parents:
diff changeset
249 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
250 palette_ptr1 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
251 for (j = 0; j < byte_run; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
252 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
253 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
254 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
255 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
256 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
257 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
258 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
259 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
260 else // copy bytes if byte_run < 0
9200edf69d1d initial commit
melanson
parents:
diff changeset
261 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
262 byte_run = -byte_run;
9200edf69d1d initial commit
melanson
parents:
diff changeset
263 for (j = 0; j < byte_run; j++)
9200edf69d1d initial commit
melanson
parents:
diff changeset
264 {
9200edf69d1d initial commit
melanson
parents:
diff changeset
265 palette_ptr1 = encoded[stream_ptr++] * 4;
9200edf69d1d initial commit
melanson
parents:
diff changeset
266 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
9200edf69d1d initial commit
melanson
parents:
diff changeset
267 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
9200edf69d1d initial commit
melanson
parents:
diff changeset
268 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
3185
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
269 if (bytes_per_pixel == 4) /* 32bpp */
a1205b22a5f4 32bpp support added
alex
parents: 3155
diff changeset
270 pixel_ptr++;
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
271 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
272 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
273 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
274
9200edf69d1d initial commit
melanson
parents:
diff changeset
275 y_ptr += line_inc;
9200edf69d1d initial commit
melanson
parents:
diff changeset
276 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
277 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
278
9200edf69d1d initial commit
melanson
parents:
diff changeset
279 case FLI_COPY:
3509
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
280 // copy the chunk (uncompressed frame)
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
281 for (pixel_ptr = 0; pixel_ptr < chunk_size - 6; pixel_ptr++)
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
282 {
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
283 palette_ptr1 = encoded[stream_ptr++] * 4;
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
284 decoded[pixel_ptr++] = palette[palette_ptr1 + 0];
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
285 decoded[pixel_ptr++] = palette[palette_ptr1 + 1];
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
286 decoded[pixel_ptr++] = palette[palette_ptr1 + 2];
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
287 if (bytes_per_pixel == 4) /* 32bpp */
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
288 pixel_ptr++;
21c7b77b3e83 fixed endian-ness for FLI and MS Video 1 decoders; fixed padding bug in
melanson
parents: 3185
diff changeset
289 }
3155
9200edf69d1d initial commit
melanson
parents:
diff changeset
290 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
291
9200edf69d1d initial commit
melanson
parents:
diff changeset
292 case FLI_MINI:
9200edf69d1d initial commit
melanson
parents:
diff changeset
293 // sort of a thumbnail? disregard this chunk...
9200edf69d1d initial commit
melanson
parents:
diff changeset
294 stream_ptr += chunk_size - 6;
9200edf69d1d initial commit
melanson
parents:
diff changeset
295 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
296
9200edf69d1d initial commit
melanson
parents:
diff changeset
297 default:
9200edf69d1d initial commit
melanson
parents:
diff changeset
298 printf ("FLI: Unrecognized chunk type: %d\n", chunk_type);
9200edf69d1d initial commit
melanson
parents:
diff changeset
299 break;
9200edf69d1d initial commit
melanson
parents:
diff changeset
300 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
301
9200edf69d1d initial commit
melanson
parents:
diff changeset
302 frame_size -= chunk_size;
9200edf69d1d initial commit
melanson
parents:
diff changeset
303 num_chunks--;
9200edf69d1d initial commit
melanson
parents:
diff changeset
304 }
9200edf69d1d initial commit
melanson
parents:
diff changeset
305 }