1 #ifndef __gif_image_h
2 #define __gif_image_h
3 
4 typedef unsigned char	byte;
5 typedef int					boolean;
6 
7 #define	OPTION_EXTENSION		(0x10)
8 #define	REMOVETILE_EXTENSION	(0x11)
9 #define	FLATTILE_EXTENSION	(0x12)
10 #define	SUBSIZE_EXTENSION		(0x13)
11 #define	SCALEINFO_START		(0x20)
12 #define	COMMENT_EXTENSION		(0xFE)
13 
14 class Extension {
15 	public:
Extension(unsigned char code_in,class Extension * n)16 		Extension(unsigned char code_in,class Extension *n)
17 			{ code=code_in; data=new char[1]; len=0; next=n; }
~Extension()18 		~Extension()		{
19 				if (next)	delete next;
20 				if (data)	delete data;
21 		}
22 		void AddData( char *ndata, int nlen );
23 
24 	private:
25 		unsigned char		code;
26 		char					*data;
27 		int					len;
28 		class Extension	*next;
29 
30 	friend class GifImage;
31 };
32 
33 class GifImage {
34 	public:
35 		GifImage( const char *filename, int autocrop=1 );
36 		GifImage();
37 		~GifImage();
38 
Name()39 		const char *Name()	{ return name; }
Width()40 		int Width()				{ return width; }
Height()41 		int Height()			{ return height; }
Data()42 		const byte* Data()	{ return data; }
43 
44 		const char *GetExtensionData( unsigned char code );
45 		void GetSize( int *h, int *w );
46 		long GetAverageColor();
47 
48 		int CropImage(int x1,int y1, int x2, int y2);
49 		int CropImage();
50 
51 		void AddLock(class GifXImage *locker);
52 		void RemoveLock(class GifXImage *locker);
53 
54 		void Recolor( class GifImage *gif_p );
55 		void AddAt( int x, int y, class GifImage *gif2 );
56 
57 		void Rotate90();
58 
59 	protected:
60 		int LoadGIF(const char *fname);
61 		int ReadImageData(FILE *fp);			// read raw raster data into buffer
62 		int DecodeImage();						// decode data into image
63 		static int ReadCode();
64 		void AddToPixel(byte Index);
65 #if (0)
66 		int ColorDicking();
67 #endif
68 		void ReadColormap(FILE *fp);
69 		void CloseGif();
70 
71 	protected:
72 		char	*name;
73 		int	width, height;								// image dimensions
74 		byte	*data;										// image data
75 		byte	Red[256], Green[256], Blue[256];		// Colormap-Data
76 		boolean	HasColormap;
77 		int		ColorMapSize;						/* number of colors */
78 		int		Background;							/* background color */
79 
80 		int		lockcount;							/* number of lockers */
81 
82 		Extension	*first;
83 
84 	public:
GetNCols()85 		int	GetNCols()	{ return ColorMapSize; }
86 		int	GetColor(int id, unsigned short *red, unsigned short *green, unsigned short *blue);
87 
88 friend class GifXImage;
89 };
90 
91 #endif
92