1 /****************************************************************************
4 Copyright (c) 2001 Jerome Jacovella-St-Louis
7 ****************************************************************************/
14 uint size __attribute__((packed));
15 uint16 magic __attribute__((packed));
16 uint16 frame __attribute__((packed));
17 uint16 width __attribute__((packed));
18 uint16 height __attribute__((packed));
19 uint16 depth __attribute__((packed));
20 uint16 flags __attribute__((packed));
21 uint16 speed __attribute__((packed));
22 uint next __attribute__((packed));
23 uint frit __attribute__((packed));
29 uint size __attribute__((packed));
30 uint16 magic __attribute__((packed));
31 uint16 chunknum __attribute__((packed));
37 uint size __attribute__((packed));
38 uint16 type __attribute__((packed));
43 #define FLI_COLOR 11 //RGB ranging from 0-63
44 #define FLI_BLACK 13 //When creating a new frame
45 #define FLI_COPY 16 //Raw
47 #define FLI_LC 12 //Line compression (common)
48 #define FLI_BRUN 15 //First frame only
49 #define FLI_DELTA 7 //Delta (common)
50 #define FLI_256_COLOR 4 //RGB ranging from 0-255
51 #define FLI_MINI 18 //That's shit
61 void FliColor(Bitmap bitmap)
67 f.Read(&num,sizeof(uint16),1);
79 f.Read(palette+skip*3,1,3*put);
81 if(chunk.type!=FLI_256_COLOR)
82 for(c=0; c<put*3; c++)
84 for(c=skip; c<skip+put; c++)
85 this.palette[c] = ColorAlpha {255, Color{palette[c*3],palette[c*3+1],palette[c*3+2]}};
86 CopyBytesBy4(bitmap.palette+skip,this.palette+skip,put);
92 void Lc(Bitmap bitmap)
95 short skipline, putline;
100 f.Read(&skipline,sizeof(uint16),1);
101 f.Read(&putline,sizeof(uint16),1);
102 for(; putline>0; putline--, skipline++)
105 offset=skipline*bitmap.width;
116 f.Read(bitmap.picture+offset,1,put);
121 f.Getc((char *)&value);
122 FillBytes(bitmap.picture+offset,value,-put);
129 void Delta(Bitmap bitmap)
140 f.Read(&putline,sizeof(uint16),1);
142 for(y=0; putline>0; )
144 f.Read(&num,sizeof(uint16),1);
148 offset=y*bitmap.width;
158 f.Read(bitmap.picture+offset,1,put*2);
163 f.Read(&value,sizeof(uint16),1);
164 FillBytesBy2(bitmap.picture+offset,value,-put);
176 void Brun(Bitmap bitmap)
183 for(y=0; y<bitmap.height; y++)
193 FillBytes(bitmap.picture,ch,bitmap.size);
196 offset=bitmap.width*y;
197 // for(; num>0 && x < bitmap.width; num--)
198 for(; x < bitmap.width; )
204 f.Read(bitmap.picture+offset,1,-put);
210 f.Getc((char *)&value);
211 if(offset > bitmap.width * bitmap.height)
213 FillBytes(bitmap.picture+offset,value,put);
224 ColorAlpha palette[256];
229 property int width { get { return width; } }
230 property int height { get { return height; } }
231 property double speed { get { return speed; } }
232 property ColorAlpha * palette { get { return palette; } }
233 property int numFrames { get { return numFrames; } }
234 property int frame { get { return frame; } set { frame = value; } }
235 property bool palUpdate { get { return palUpdate; } set { palUpdate = value; }}
237 bool Load(const char *fileName)
240 //f=FileOpen(fileName, read);
241 f = FileOpenBuffered(fileName, read);
244 f.Read(&header,sizeof(FLIheader),1);
245 if(header.magic<0xAF12)
246 header.speed = header.speed * 100 / 7;
247 speed = header.speed / 1000.0;
250 width = header.width;
251 height = header.height;
252 FillBytesBy4(palette,0,256);
253 numFrames = header.frame;
260 void PlayFrame(Bitmap bitmap)
265 if(frame==header.frame)
270 f.Read(&fliFrame,sizeof(FLIFrame),1);
271 nextf=f.Tell()+fliFrame.size-sizeof(FLIFrame);
272 for(; fliFrame.chunknum>0; fliFrame.chunknum--)
274 f.Read(&chunk,sizeof(FLIchunk),1);
275 nextc=f.Tell()+chunk.size-sizeof(FLIchunk);
278 case FLI_COLOR: FliColor(bitmap); break;
279 case FLI_256_COLOR: FliColor(bitmap); break;
280 case FLI_BRUN: Brun(bitmap); break;
281 case FLI_LC: Lc(bitmap); break;
282 case FLI_DELTA: Delta(bitmap); break;
283 case FLI_BLACK: FillBytes(bitmap.picture,0,bitmap.size); break;
284 case FLI_COPY: f.Read(bitmap.picture,1,bitmap.size); break;
286 f.Seek(nextc, start);
288 f.Seek(nextf, start);
292 bool Save(char *fileName, Bitmap bitmap, int frames, int speed)
294 f=FileOpen(fileName, write);
297 header.size=sizeof(FLIheader)+
298 sizeof(FLIchunk)+768+
299 (sizeof(FLIFrame)+sizeof(FLIchunk)+bitmap.size)*frames;
302 header.frame=(uint16)frames;
303 header.width=(uint16)bitmap.width;
304 header.height=(uint16)bitmap.height;
307 header.speed=(uint16)speed;
310 FillBytes(header.expand,0,102);
311 f.Write(&header,sizeof(FLIheader),1);
313 FillBytesBy4(palette,0,256);
317 void SaveFrame(Bitmap bitmap, ColorAlpha * palette)
321 fliFrame.magic=0xF1FA;
323 fliFrame.size=sizeof(FLIFrame)+sizeof(FLIchunk)+bitmap.size;
327 fliFrame.size+=sizeof(FLIchunk)+772;
329 FillBytes(fliFrame.nothing,0,8);
330 f.Write(&fliFrame,sizeof(FLIFrame),1);
335 CopyBytesBy4(palette,palette,256);
336 chunk.size=sizeof(FLIchunk)+772;
337 chunk.type=FLI_COLOR;
338 f.Write(&chunk,sizeof(FLIchunk),1);
340 f.Write(&num,sizeof(uint16),1);
342 f.Write(&num,sizeof(uint16),1);
345 f.Putc(palette[c].color.r);
346 f.Putc(palette[c].color.g);
347 f.Putc(palette[c].color.b);
351 chunk.size=sizeof(FLIchunk)+bitmap.size;
353 f.Write(&chunk,sizeof(FLIchunk),1);
354 f.Write(bitmap.picture,1,bitmap.size);