annotate src/gifrlib.h @ 325:f2b5d7006b0a r21-0-60

Import from CVS: tag r21-0-60
author cvs
date Mon, 13 Aug 2007 10:47:35 +0200
parents 19dcec799385
children 8626e4521993
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
1 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
2 * In order to make life a little bit easier when using the GIF file format, *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
3 * this library was written, and which does all the dirty work... *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
4 * *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
5 * Written by Gershon Elber, Jun. 1989 *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
6 * Hacks by Eric S. Raymond, Sep. 1992 *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
7 * and Jareth Hein, Jan. 1998 *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
8 *******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
9 * History: *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
10 * 14 Jun 89 - Version 1.0 by Gershon Elber. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
11 * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names). *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
12 * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp) *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
13 * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support) *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
14 * 19 Jan 98 - Version 3.1 by Jareth Hein (Support for user-defined I/O). *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
15 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
16
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
17 #ifndef GIF_LIB_H
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
18 #define GIF_LIB_H
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
19
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
20 #define GIF_ERROR 0
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
21 #define GIF_OK 1
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
22
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
23 #ifndef TRUE
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
24 #define TRUE 1
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
25 #define FALSE 0
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
26 #endif
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
27
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
28 #ifndef NULL
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
29 #define NULL 0
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
30 #endif /* NULL */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
31
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
32 #define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
33
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
34 typedef int GifBooleanType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
35 typedef unsigned char GifPixelType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
36 typedef unsigned char * GifRowType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
37 typedef unsigned char GifByteType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
38
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
39 #ifdef SYSV
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
40 #define VoidPtr char *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
41 #else
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
42 #define VoidPtr void *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
43 #endif /* SYSV */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
44
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
45 typedef struct GifColorType {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
46 GifByteType Red, Green, Blue;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
47 } GifColorType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
48
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
49 typedef struct ColorMapObject
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
50 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
51 int ColorCount;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
52 int BitsPerPixel;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
53 GifColorType *Colors; /* on malloc(3) heap */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
54 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
55 ColorMapObject;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
56
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
57 typedef struct GifImageDesc {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
58 int Left, Top, Width, Height, /* Current image dimensions. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
59 Interlace; /* Sequential/Interlaced lines. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
60 ColorMapObject *ColorMap; /* The local color map */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
61 } GifImageDesc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
62
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
63 /* I/O operations. If you roll your own, they need to be semantically equivilent to
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
64 fread/fwrite, with an additional paramater to hold data local to your method. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
65 typedef size_t (*Gif_rw_func)(GifByteType *buffer, size_t size, VoidPtr method_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
66 /* Finish up stream. Non-zero return indicates failure */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
67 typedef int (*Gif_close_func)(VoidPtr close_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
68 /* Error handling function */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
69 typedef void (*Gif_error_func)(const char *string, VoidPtr error_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
70
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
71 typedef struct GifFileType {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
72 int SWidth, SHeight, /* Screen dimensions. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
73 SColorResolution, /* How many colors can we generate? */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
74 SBackGroundColor; /* I hope you understand this one... */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
75 ColorMapObject *SColorMap; /* NULL if it doesn't exist. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
76 int ImageCount; /* Number of current image */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
77 GifImageDesc Image; /* Block describing current image */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
78 struct SavedImage *SavedImages; /* Use this to accumulate file state */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
79 VoidPtr Private; /* Don't mess with this! */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
80 VoidPtr GifIO; /* Contains all information for I/O */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
81 } GifFileType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
82
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
83 typedef enum {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
84 UNDEFINED_RECORD_TYPE,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
85 SCREEN_DESC_RECORD_TYPE,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
86 IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
87 EXTENSION_RECORD_TYPE, /* Begin with '!' */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
88 TERMINATE_RECORD_TYPE /* Begin with ';' */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
89 } GifRecordType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
90
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
91 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
92 * GIF89 extension function codes *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
93 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
94
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
95 #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
96 #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
97 #define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
98 #define APPLICATION_EXT_FUNC_CODE 0xff /* application block */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
99
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
100 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
101 * IO related routines. Defined in gif_io.c *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
102 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
103 GifFileType *GifSetup(void);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
104 void GifFree(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
105 void GifSetReadFunc (GifFileType *GifFile, Gif_rw_func func, VoidPtr data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
106 void GifSetWriteFunc(GifFileType *GifFile, Gif_rw_func func, VoidPtr data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
107 void GifSetCloseFunc(GifFileType *GifFile, Gif_close_func func, VoidPtr data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
108
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
109 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
110 * O.K., here are the routines one can access in order to decode GIF file: *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
111 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
112
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
113 void DGifOpenFileName(GifFileType *GifFile, const char *GifFileName);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
114 void DGifOpenFileHandle(GifFileType *GifFile, int GifFileHandle);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
115 void DGifInitRead(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
116 void DGifSlurp(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
117 void DGifGetScreenDesc(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
118 void DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
119 void DGifGetImageDesc(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
120 void DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
121 void DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
122 void DGifGetComment(GifFileType *GifFile, char *GifComment);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
123 void DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
124 GifByteType **GifExtension);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
125 void DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
126 void DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
127 GifByteType **GifCodeBlock);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
128 void DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
129 void DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
130 int DGifCloseFile(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
131
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
132 #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
133 #define D_GIF_ERR_READ_FAILED 102
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
134 #define D_GIF_ERR_NOT_GIF_FILE 103
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
135 #define D_GIF_ERR_NO_SCRN_DSCR 104
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
136 #define D_GIF_ERR_NO_IMAG_DSCR 105
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
137 #define D_GIF_ERR_NO_COLOR_MAP 106
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
138 #define D_GIF_ERR_WRONG_RECORD 107
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
139 #define D_GIF_ERR_DATA_TOO_BIG 108
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
140 #define GIF_ERR_NOT_ENOUGH_MEM 109
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
141 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
142 #define D_GIF_ERR_CLOSE_FAILED 110
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
143 #define D_GIF_ERR_NOT_READABLE 111
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
144 #define D_GIF_ERR_IMAGE_DEFECT 112
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
145 #define D_GIF_ERR_EOF_TOO_SOON 113
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
146
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
147 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
148 * O.K., here are the error routines *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
149 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
150 extern void GifSetErrorFunc(GifFileType *GifFile, Gif_error_func func, VoidPtr data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
151 extern void GifSetWarningFunc(GifFileType *GifFile, Gif_error_func func, VoidPtr data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
152 extern void GifInternError(GifFileType *GifFile, int errnum);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
153 extern void GifInternWarning(GifFileType *GifFile, int errnum);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
154 extern void GifError(GifFileType *GifFile, const char *err_str);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
155 extern void GifWarning(GifFileType *GifFile, const char *err_str);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
156
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
157 /*****************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
158 *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
159 * Everything below this point is new after version 1.2, supporting `slurp
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
160 * mode' for doing I/O in two big belts with all the image-bashing in core.
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
161 *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
162 *****************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
163
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
164 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
165 * Support for the in-core structures allocation (slurp mode). *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
166 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
167
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
168 /* This is the in-core version of an extension record */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
169 typedef struct {
321
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 308
diff changeset
170 int ByteCount;
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 308
diff changeset
171 GifByteType *Bytes; /* on malloc(3) heap */
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
172 } ExtensionBlock;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
173
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
174 /* This holds an image header, its unpacked raster bits, and extensions */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
175 typedef struct SavedImage {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
176 GifImageDesc ImageDesc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
177
321
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 308
diff changeset
178 GifPixelType *RasterBits; /* on malloc(3) heap */
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
179
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
180 int Function;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
181 int ExtensionBlockCount;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
182 ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
183 } SavedImage;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
184
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
185 extern void ApplyTranslation(SavedImage *Image, GifPixelType Translation[]);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
186
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
187 extern void MakeExtension(SavedImage *New, int Function);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
188 extern int AddExtensionBlock(SavedImage *New, int Length, GifByteType *data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
189 extern void FreeExtension(SavedImage *Image);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
190
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
191 extern SavedImage *MakeSavedImage(GifFileType *GifFile, SavedImage *CopyFrom);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
192 extern void FreeSavedImages(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
193
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
194 /* Common defines used by encode/decode functions */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
195
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
196 #define COMMENT_EXT_FUNC_CODE 0xfe /* Extension function code for comment. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
197 #define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
198 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
199 #define GIF_VERSION_POS 3 /* Version first character in stamp. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
200 #define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
201 #define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
202
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
203 #define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
204 #define LZ_BITS 12
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
205
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
206 #define FILE_STATE_READ 0x01
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
207 #define FILE_STATE_WRITE 0x01
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
208 #define FILE_STATE_SCREEN 0x02
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
209 #define FILE_STATE_IMAGE 0x04
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
210
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
211 #define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
212 #define FIRST_CODE 4097 /* Impossible code, to signal first. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
213 #define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
214
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
215 #define IS_READABLE(Private) (!(Private->FileState & FILE_STATE_READ))
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
216 #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
217
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
218 typedef struct GifFilePrivateType {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
219 int FileState,
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
220 BitsPerPixel, /* Bits per pixel (Codes uses at list this + 1). */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
221 ClearCode, /* The CLEAR LZ code. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
222 EOFCode, /* The EOF LZ code. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
223 RunningCode, /* The next code algorithm can generate. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
224 RunningBits,/* The number of bits required to represent RunningCode. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
225 MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
226 LastCode, /* The code before the current code. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
227 CrntCode, /* Current algorithm code. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
228 StackPtr, /* For character stack (see below). */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
229 CrntShiftState; /* Number of bits in CrntShiftDWord. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
230 unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
231 unsigned long PixelCount; /* Number of pixels in image. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
232 GifByteType Buf[256]; /* Compressed input is buffered here. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
233 GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
234 GifByteType Suffix[LZ_MAX_CODE+1]; /* So we can trace the codes. */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
235 unsigned int Prefix[LZ_MAX_CODE+1];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
236 } GifFilePrivateType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
237
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
238 typedef struct GifIODataType {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
239 Gif_rw_func ReadFunc, WriteFunc; /* Pointers to the functions that will do the I/O */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
240 Gif_close_func CloseFunc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
241 VoidPtr ReadFunc_data; /* data to be passed to the read function */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
242 VoidPtr WriteFunc_data; /* data to be passed to the write function */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
243 VoidPtr CloseFunc_data; /* data to be passed to the close function */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
244 Gif_error_func ErrorFunc; /* MUST NOT RETURN (use lng_jmp or exit)! */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
245 Gif_error_func WarningFunc; /* For warning messages (can be ignored) */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
246 VoidPtr ErrorFunc_data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
247 VoidPtr WarningFunc_data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
248 } GifIODataType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
249
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
250 typedef struct GifStdIODataType {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
251 FILE *File;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
252 int FileHandle;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
253 } GifStdIODataType;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
254
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
255 /* Install StdIO funcs on FILE into GifFile */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
256 void GifStdIOInit(GifFileType *GifFile, FILE *file, int filehandle);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
257
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
258 /* Error checking reads, writes and closes */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
259 void GifRead(GifByteType *buf, size_t size, GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
260 void GifWrite(GifByteType *buf, size_t size, GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
261 int GifClose(GifFileType *GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
262
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
263 /* The default Read and Write functions for files */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
264 size_t GifStdRead(GifByteType *buf, size_t size, VoidPtr method_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
265 size_t GifStdWrite(GifByteType *buf, size_t size, VoidPtr method_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
266 int GifStdFileClose(VoidPtr method_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
267
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
268 ColorMapObject *MakeMapObject(int ColorCount, GifColorType *ColorMap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
269 void FreeMapObject(ColorMapObject *Object);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
270
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
271
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
272 #endif /* GIF_LIB_H */