1 /******************************************************************************
2 * In order to make life a little bit easier when using the GIF file format,   *
3 * this library was written, and which does all the dirty work...              *
4 *                                                                             *
5 *                                        Written by Gershon Elber,  Jun. 1989 *
6 *                                        Hacks by Eric S. Raymond,  Sep. 1992 *
7 *******************************************************************************
8 * History:                                                                    *
9 * 14 Jun 89 - Version 1.0 by Gershon Elber.                                   *
10 *  3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)  *
11 * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)   *
12 * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)             *
13 * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)     *
14 ******************************************************************************/
15 
16 #ifndef _GIF_LIB_H
17 #define _GIF_LIB_H
18 
19 #   include	<sioGeneral.h>
20 #   include	"bmcolor.h"
21 
22 /*************************/
23 /*************************/
24 /*************************/
25 
26 # define EGifCloseFile bm_EGifCloseFile
27 # define EGifOpenFileHandle bm_EGifOpenFileHandle
28 # define EGifPutComment bm_EGifPutComment
29 # define EGifPutExtension bm_EGifPutExtension
30 # define EGifPutExtensionFirst bm_EGifPutExtensionFirst
31 # define EGifPutExtensionLast bm_EGifPutExtensionLast
32 # define EGifPutExtensionNext bm_EGifPutExtensionNext
33 # define EGifPutImageDesc bm_EGifPutImageDesc
34 # define EGifPutScreenDesc bm_EGifPutScreenDesc
35 # define EGifSpew bm_EGifSpew
36 
37 # define DGifCloseFile bm_DGifCloseFile
38 # define DGifOpenFileHandle bm_DGifOpenFileHandle
39 # define DGifGetExtension bm_DGifGetExtension
40 # define DGifGetExtensionNext bm_DGifGetExtensionNext
41 # define DGifGetImageDesc bm_DGifGetImageDesc
42 # define bmGifGetRecordType bm_DGifGetRecordType
43 
44 # define _GifError bm__GifError
45 
46 /*************************/
47 /*************************/
48 /*************************/
49 
50 #define	GIF_ERROR	0
51 #define GIF_OK		1
52 
53 #define GIF87_STAMP	"GIF87a"        /* First chars in file - GIF stamp.  */
54 #define GIF89_STAMP	"GIF89a"        /* First chars in file - GIF stamp.  */
55 
56 typedef unsigned char	GifByteType;
57 
58 typedef struct GifColorMap
59     {
60     int		gcmColorCount;
61     int		gcmBitsPerPixel;
62     RGB8Color	gcmColors[256];
63     } GifColorMap;
64 
65 typedef struct GifImageDesc
66     {
67     int		Left;
68     int		Top;
69     int		Width;
70     int		Height;
71     int		Interlace;		/*  Sequential/Interlaced lines	*/
72     GifColorMap	gidImageColorMap;
73     } GifImageDesc;
74 
75 typedef struct GifScreenDescriptor
76     {
77     int			gsdScreenWide;
78     int			gsdScreenHigh;
79     int			gsdScreenBitsPerPixel;
80 
81     unsigned char	gsdPackedFields;
82 
83     int			gsdScreenBackgroundColor;
84     int			gsdScreenAspectRatio;
85 
86     GifColorMap		gsdScreenColorMap;
87     } GifScreenDescriptor;
88 
89 typedef struct GifFileType
90     {
91     char			gftVersionString[6+1];
92     GifScreenDescriptor		gftScreenDescriptor;
93     GifImageDesc		gftCurrentImageDescriptor;
94 
95     /**/
96     SimpleOutputStream *	gftSos;
97     SimpleOutputStream *	gftSosBlocked;
98     SimpleOutputStream *	gftSosLzw;
99 
100     SimpleInputStream *		gftSis;
101     SimpleInputStream *		gftSisBlocked;
102     SimpleInputStream *		gftSisLzw;
103 
104     long			gftPixelCount;
105 				    /************************************/
106 				    /*  Number of pixels that has not	*/
107 				    /*  yet been written to the current	*/
108 				    /*  image.				*/
109 				    /*  OR				*/
110 				    /*  Number of pixels that has not	*/
111 				    /*  yet been read from the current	*/
112 				    /*  image.				*/
113 				    /************************************/
114     } GifFileType;
115 
116 typedef enum GifRecordType
117     {
118     UNDEFINED_RECORD_TYPE,
119     SCREEN_DESC_RECORD_TYPE,
120     IMAGE_DESC_RECORD_TYPE,		/* Begin with ',' */
121     EXTENSION_RECORD_TYPE,		/* Begin with '!' */
122     TERMINATE_RECORD_TYPE		/* Begin with ';' */
123     } GifRecordType;
124 
125 extern void bmGifInitGifColorMap(      GifColorMap *   gcm );
126 
127 /******************************************************************************
128 *  GIF89 extension function codes                                             *
129 ******************************************************************************/
130 
131 #define COMMENT_EXT_FUNC_CODE		0xfe	/* comment */
132 #define GRAPHICS_EXT_FUNC_CODE		0xf9	/* graphics control */
133 #define PLAINTEXT_EXT_FUNC_CODE		0x01	/* plaintext */
134 #define APPLICATION_EXT_FUNC_CODE	0xff	/* application block */
135 
136 /******************************************************************************
137 * O.K., here are the routines one can access in order to encode GIF file:     *
138 * (GIF_LIB file EGIF_LIB.C).						      *
139 ******************************************************************************/
140 
141 extern GifFileType *EGifOpenFileHandle(	SimpleOutputStream *	sos );
142 
143 extern void bmGifSetVersion(		GifFileType *		gft,
144 					const char *		version );
145 
146 int EGifPutScreenDesc(GifFileType *GifFile,
147 	int GifWidth, int GifHeight, int GifColorRes, int GifBackGround,
148 	const GifColorMap *gcm);
149 int EGifPutImageDesc(GifFileType *GifFile,
150 	int GifLeft, int GifTop, int Width, int GifHeight, int GifInterlace,
151 	const GifColorMap * gcm);
152 
153 extern int bmGifPutPixels(	GifFileType *		GifFile,
154 				const unsigned char *	buffer,
155 				int			count );
156 
157 int EGifPutComment(GifFileType *GifFile, const char *GifComment);
158 int EGifPutExtensionFirst(GifFileType *GifFile, int GifExtCode, int GifExtLen,
159                            const void * GifExtension);
160 int EGifPutExtensionNext(GifFileType *GifFile, int GifExtCode, int GifExtLen,
161                            const void * GifExtension);
162 int EGifPutExtensionLast(GifFileType *GifFile, int GifExtCode, int GifExtLen,
163                            const void * GifExtension);
164 int EGifPutExtension(GifFileType *GifFile, int GifExtCode, int GifExtLen,
165 							const void * GifExtension);
166 
167 int EGifCloseFile(GifFileType *GifFile);
168 
169 #define	E_GIF_ERR_OPEN_FAILED	1		/* And EGif possible errors. */
170 #define	E_GIF_ERR_WRITE_FAILED	2
171 #define E_GIF_ERR_HAS_SCRN_DSCR	3
172 #define E_GIF_ERR_HAS_IMAG_DSCR	4
173 #define E_GIF_ERR_NO_COLOR_MAP	5
174 #define E_GIF_ERR_DATA_TOO_BIG	6
175 #define E_GIF_ERR_NOT_ENOUGH_MEM 7
176 #define E_GIF_ERR_DISK_IS_FULL	8
177 #define E_GIF_ERR_CLOSE_FAILED	9
178 #define E_GIF_ERR_NOT_WRITEABLE	10
179 
180 /******************************************************************************
181 * O.K., here are the routines one can access in order to decode GIF file:     *
182 * (GIF_LIB file DGIF_LIB.C).						      *
183 ******************************************************************************/
184 
185 GifFileType *DGifOpenFileHandle(	SimpleInputStream *	sis );
186 int bmGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
187 int DGifGetImageDesc(GifFileType *GifFile);
188 
189 int DGifGetComment(GifFileType *GifFile, char *GifComment);
190 int DGifCloseFile(GifFileType *GifFile);
191 
192 extern int bmGifGetPixels(	GifFileType *	gft,
193 				int *		pFoundTransparent,
194 				unsigned char *	buffer,
195 				int		count,
196 				int		transparentColor );
197 
198 extern int DGifGetExtension(		GifFileType *	GifFile,
199 					int *		ExtCode,
200 					GifByteType	Extension[256] );
201 
202 extern int DGifGetExtensionNext(	GifFileType *	GifFile,
203 					int *		pGot,
204 					GifByteType	Extension[256] );
205 
206 #define	D_GIF_ERR_OPEN_FAILED	101		/* And DGif possible errors. */
207 #define	D_GIF_ERR_READ_FAILED	102
208 #define	D_GIF_ERR_NOT_GIF_FILE	103
209 #define D_GIF_ERR_NO_SCRN_DSCR	104
210 #define D_GIF_ERR_NO_IMAG_DSCR	105
211 #define D_GIF_ERR_NO_COLOR_MAP	106
212 #define D_GIF_ERR_WRONG_RECORD	107
213 #define D_GIF_ERR_DATA_TOO_BIG	108
214 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
215 #define D_GIF_ERR_CLOSE_FAILED	110
216 #define D_GIF_ERR_NOT_READABLE	111
217 #define D_GIF_ERR_IMAGE_DEFECT	112
218 #define D_GIF_ERR_EOF_TOO_SOON	113
219 
220 extern int _GifError;
221 
222 #endif /* _GIF_LIB_H */
223