annotate fli.c @ 3199:1632d6824a68

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