annotate fli.c @ 4559:5dc383bb1c82

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