jpayne@69
|
1 /******************************************************************************
|
jpayne@69
|
2
|
jpayne@69
|
3 gif_lib.h - service library for decoding and encoding GIF images
|
jpayne@69
|
4
|
jpayne@69
|
5 SPDX-License-Identifier: MIT
|
jpayne@69
|
6
|
jpayne@69
|
7 *****************************************************************************/
|
jpayne@69
|
8
|
jpayne@69
|
9 #ifndef _GIF_LIB_H_
|
jpayne@69
|
10 #define _GIF_LIB_H_ 1
|
jpayne@69
|
11
|
jpayne@69
|
12 #ifdef __cplusplus
|
jpayne@69
|
13 extern "C" {
|
jpayne@69
|
14 #endif /* __cplusplus */
|
jpayne@69
|
15
|
jpayne@69
|
16 #define GIFLIB_MAJOR 5
|
jpayne@69
|
17 #define GIFLIB_MINOR 2
|
jpayne@69
|
18 #define GIFLIB_RELEASE 2
|
jpayne@69
|
19
|
jpayne@69
|
20 #define GIF_ERROR 0
|
jpayne@69
|
21 #define GIF_OK 1
|
jpayne@69
|
22
|
jpayne@69
|
23 #include <stdbool.h>
|
jpayne@69
|
24 #include <stddef.h>
|
jpayne@69
|
25
|
jpayne@69
|
26 #define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
|
jpayne@69
|
27 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
|
jpayne@69
|
28 #define GIF_VERSION_POS 3 /* Version first character in stamp. */
|
jpayne@69
|
29 #define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */
|
jpayne@69
|
30 #define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */
|
jpayne@69
|
31
|
jpayne@69
|
32 typedef unsigned char GifPixelType;
|
jpayne@69
|
33 typedef unsigned char *GifRowType;
|
jpayne@69
|
34 typedef unsigned char GifByteType;
|
jpayne@69
|
35 typedef unsigned int GifPrefixType;
|
jpayne@69
|
36 typedef int GifWord;
|
jpayne@69
|
37
|
jpayne@69
|
38 typedef struct GifColorType {
|
jpayne@69
|
39 GifByteType Red, Green, Blue;
|
jpayne@69
|
40 } GifColorType;
|
jpayne@69
|
41
|
jpayne@69
|
42 typedef struct ColorMapObject {
|
jpayne@69
|
43 int ColorCount;
|
jpayne@69
|
44 int BitsPerPixel;
|
jpayne@69
|
45 bool SortFlag;
|
jpayne@69
|
46 GifColorType *Colors; /* on malloc(3) heap */
|
jpayne@69
|
47 } ColorMapObject;
|
jpayne@69
|
48
|
jpayne@69
|
49 typedef struct GifImageDesc {
|
jpayne@69
|
50 GifWord Left, Top, Width, Height; /* Current image dimensions. */
|
jpayne@69
|
51 bool Interlace; /* Sequential/Interlaced lines. */
|
jpayne@69
|
52 ColorMapObject *ColorMap; /* The local color map */
|
jpayne@69
|
53 } GifImageDesc;
|
jpayne@69
|
54
|
jpayne@69
|
55 typedef struct ExtensionBlock {
|
jpayne@69
|
56 int ByteCount;
|
jpayne@69
|
57 GifByteType *Bytes; /* on malloc(3) heap */
|
jpayne@69
|
58 int Function; /* The block function code */
|
jpayne@69
|
59 #define CONTINUE_EXT_FUNC_CODE 0x00 /* continuation subblock */
|
jpayne@69
|
60 #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
|
jpayne@69
|
61 #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */
|
jpayne@69
|
62 #define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
|
jpayne@69
|
63 #define APPLICATION_EXT_FUNC_CODE 0xff /* application block (GIF89) */
|
jpayne@69
|
64 } ExtensionBlock;
|
jpayne@69
|
65
|
jpayne@69
|
66 typedef struct SavedImage {
|
jpayne@69
|
67 GifImageDesc ImageDesc;
|
jpayne@69
|
68 GifByteType *RasterBits; /* on malloc(3) heap */
|
jpayne@69
|
69 int ExtensionBlockCount; /* Count of extensions before image */
|
jpayne@69
|
70 ExtensionBlock *ExtensionBlocks; /* Extensions before image */
|
jpayne@69
|
71 } SavedImage;
|
jpayne@69
|
72
|
jpayne@69
|
73 typedef struct GifFileType {
|
jpayne@69
|
74 GifWord SWidth, SHeight; /* Size of virtual canvas */
|
jpayne@69
|
75 GifWord SColorResolution; /* How many colors can we generate? */
|
jpayne@69
|
76 GifWord SBackGroundColor; /* Background color for virtual canvas */
|
jpayne@69
|
77 GifByteType AspectByte; /* Used to compute pixel aspect ratio */
|
jpayne@69
|
78 ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */
|
jpayne@69
|
79 int ImageCount; /* Number of current image (both APIs) */
|
jpayne@69
|
80 GifImageDesc Image; /* Current image (low-level API) */
|
jpayne@69
|
81 SavedImage *SavedImages; /* Image sequence (high-level API) */
|
jpayne@69
|
82 int ExtensionBlockCount; /* Count extensions past last image */
|
jpayne@69
|
83 ExtensionBlock *ExtensionBlocks; /* Extensions past last image */
|
jpayne@69
|
84 int Error; /* Last error condition reported */
|
jpayne@69
|
85 void *UserData; /* hook to attach user data (TVT) */
|
jpayne@69
|
86 void *Private; /* Don't mess with this! */
|
jpayne@69
|
87 } GifFileType;
|
jpayne@69
|
88
|
jpayne@69
|
89 #define GIF_ASPECT_RATIO(n) ((n) + 15.0 / 64.0)
|
jpayne@69
|
90
|
jpayne@69
|
91 typedef enum {
|
jpayne@69
|
92 UNDEFINED_RECORD_TYPE,
|
jpayne@69
|
93 SCREEN_DESC_RECORD_TYPE,
|
jpayne@69
|
94 IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
|
jpayne@69
|
95 EXTENSION_RECORD_TYPE, /* Begin with '!' */
|
jpayne@69
|
96 TERMINATE_RECORD_TYPE /* Begin with ';' */
|
jpayne@69
|
97 } GifRecordType;
|
jpayne@69
|
98
|
jpayne@69
|
99 /* func type to read gif data from arbitrary sources (TVT) */
|
jpayne@69
|
100 typedef int (*InputFunc)(GifFileType *, GifByteType *, int);
|
jpayne@69
|
101
|
jpayne@69
|
102 /* func type to write gif data to arbitrary targets.
|
jpayne@69
|
103 * Returns count of bytes written. (MRB)
|
jpayne@69
|
104 */
|
jpayne@69
|
105 typedef int (*OutputFunc)(GifFileType *, const GifByteType *, int);
|
jpayne@69
|
106
|
jpayne@69
|
107 /******************************************************************************
|
jpayne@69
|
108 GIF89 structures
|
jpayne@69
|
109 ******************************************************************************/
|
jpayne@69
|
110
|
jpayne@69
|
111 typedef struct GraphicsControlBlock {
|
jpayne@69
|
112 int DisposalMode;
|
jpayne@69
|
113 #define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */
|
jpayne@69
|
114 #define DISPOSE_DO_NOT 1 /* Leave image in place */
|
jpayne@69
|
115 #define DISPOSE_BACKGROUND 2 /* Set area too background color */
|
jpayne@69
|
116 #define DISPOSE_PREVIOUS 3 /* Restore to previous content */
|
jpayne@69
|
117 bool UserInputFlag; /* User confirmation required before disposal */
|
jpayne@69
|
118 int DelayTime; /* pre-display delay in 0.01sec units */
|
jpayne@69
|
119 int TransparentColor; /* Palette index for transparency, -1 if none */
|
jpayne@69
|
120 #define NO_TRANSPARENT_COLOR -1
|
jpayne@69
|
121 } GraphicsControlBlock;
|
jpayne@69
|
122
|
jpayne@69
|
123 /******************************************************************************
|
jpayne@69
|
124 GIF encoding routines
|
jpayne@69
|
125 ******************************************************************************/
|
jpayne@69
|
126
|
jpayne@69
|
127 /* Main entry points */
|
jpayne@69
|
128 GifFileType *EGifOpenFileName(const char *GifFileName,
|
jpayne@69
|
129 const bool GifTestExistence, int *Error);
|
jpayne@69
|
130 GifFileType *EGifOpenFileHandle(const int GifFileHandle, int *Error);
|
jpayne@69
|
131 GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *Error);
|
jpayne@69
|
132 int EGifSpew(GifFileType *GifFile);
|
jpayne@69
|
133 const char *EGifGetGifVersion(GifFileType *GifFile); /* new in 5.x */
|
jpayne@69
|
134 int EGifCloseFile(GifFileType *GifFile, int *ErrorCode);
|
jpayne@69
|
135
|
jpayne@69
|
136 #define E_GIF_SUCCEEDED 0
|
jpayne@69
|
137 #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
|
jpayne@69
|
138 #define E_GIF_ERR_WRITE_FAILED 2
|
jpayne@69
|
139 #define E_GIF_ERR_HAS_SCRN_DSCR 3
|
jpayne@69
|
140 #define E_GIF_ERR_HAS_IMAG_DSCR 4
|
jpayne@69
|
141 #define E_GIF_ERR_NO_COLOR_MAP 5
|
jpayne@69
|
142 #define E_GIF_ERR_DATA_TOO_BIG 6
|
jpayne@69
|
143 #define E_GIF_ERR_NOT_ENOUGH_MEM 7
|
jpayne@69
|
144 #define E_GIF_ERR_DISK_IS_FULL 8
|
jpayne@69
|
145 #define E_GIF_ERR_CLOSE_FAILED 9
|
jpayne@69
|
146 #define E_GIF_ERR_NOT_WRITEABLE 10
|
jpayne@69
|
147
|
jpayne@69
|
148 /* These are legacy. You probably do not want to call them directly */
|
jpayne@69
|
149 int EGifPutScreenDesc(GifFileType *GifFile, const int GifWidth,
|
jpayne@69
|
150 const int GifHeight, const int GifColorRes,
|
jpayne@69
|
151 const int GifBackGround,
|
jpayne@69
|
152 const ColorMapObject *GifColorMap);
|
jpayne@69
|
153 int EGifPutImageDesc(GifFileType *GifFile, const int GifLeft, const int GifTop,
|
jpayne@69
|
154 const int GifWidth, const int GifHeight,
|
jpayne@69
|
155 const bool GifInterlace,
|
jpayne@69
|
156 const ColorMapObject *GifColorMap);
|
jpayne@69
|
157 void EGifSetGifVersion(GifFileType *GifFile, const bool gif89);
|
jpayne@69
|
158 int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
|
jpayne@69
|
159 int EGifPutPixel(GifFileType *GifFile, const GifPixelType GifPixel);
|
jpayne@69
|
160 int EGifPutComment(GifFileType *GifFile, const char *GifComment);
|
jpayne@69
|
161 int EGifPutExtensionLeader(GifFileType *GifFile, const int GifExtCode);
|
jpayne@69
|
162 int EGifPutExtensionBlock(GifFileType *GifFile, const int GifExtLen,
|
jpayne@69
|
163 const void *GifExtension);
|
jpayne@69
|
164 int EGifPutExtensionTrailer(GifFileType *GifFile);
|
jpayne@69
|
165 int EGifPutExtension(GifFileType *GifFile, const int GifExtCode,
|
jpayne@69
|
166 const int GifExtLen, const void *GifExtension);
|
jpayne@69
|
167 int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
|
jpayne@69
|
168 const GifByteType *GifCodeBlock);
|
jpayne@69
|
169 int EGifPutCodeNext(GifFileType *GifFile, const GifByteType *GifCodeBlock);
|
jpayne@69
|
170
|
jpayne@69
|
171 /******************************************************************************
|
jpayne@69
|
172 GIF decoding routines
|
jpayne@69
|
173 ******************************************************************************/
|
jpayne@69
|
174
|
jpayne@69
|
175 /* Main entry points */
|
jpayne@69
|
176 GifFileType *DGifOpenFileName(const char *GifFileName, int *Error);
|
jpayne@69
|
177 GifFileType *DGifOpenFileHandle(int GifFileHandle, int *Error);
|
jpayne@69
|
178 int DGifSlurp(GifFileType *GifFile);
|
jpayne@69
|
179 GifFileType *DGifOpen(void *userPtr, InputFunc readFunc,
|
jpayne@69
|
180 int *Error); /* new one (TVT) */
|
jpayne@69
|
181 int DGifCloseFile(GifFileType *GifFile, int *ErrorCode);
|
jpayne@69
|
182
|
jpayne@69
|
183 #define D_GIF_SUCCEEDED 0
|
jpayne@69
|
184 #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
|
jpayne@69
|
185 #define D_GIF_ERR_READ_FAILED 102
|
jpayne@69
|
186 #define D_GIF_ERR_NOT_GIF_FILE 103
|
jpayne@69
|
187 #define D_GIF_ERR_NO_SCRN_DSCR 104
|
jpayne@69
|
188 #define D_GIF_ERR_NO_IMAG_DSCR 105
|
jpayne@69
|
189 #define D_GIF_ERR_NO_COLOR_MAP 106
|
jpayne@69
|
190 #define D_GIF_ERR_WRONG_RECORD 107
|
jpayne@69
|
191 #define D_GIF_ERR_DATA_TOO_BIG 108
|
jpayne@69
|
192 #define D_GIF_ERR_NOT_ENOUGH_MEM 109
|
jpayne@69
|
193 #define D_GIF_ERR_CLOSE_FAILED 110
|
jpayne@69
|
194 #define D_GIF_ERR_NOT_READABLE 111
|
jpayne@69
|
195 #define D_GIF_ERR_IMAGE_DEFECT 112
|
jpayne@69
|
196 #define D_GIF_ERR_EOF_TOO_SOON 113
|
jpayne@69
|
197
|
jpayne@69
|
198 /* These are legacy. You probably do not want to call them directly */
|
jpayne@69
|
199 int DGifGetScreenDesc(GifFileType *GifFile);
|
jpayne@69
|
200 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
|
jpayne@69
|
201 int DGifGetImageHeader(GifFileType *GifFile);
|
jpayne@69
|
202 int DGifGetImageDesc(GifFileType *GifFile);
|
jpayne@69
|
203 int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
|
jpayne@69
|
204 int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
|
jpayne@69
|
205 int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
|
jpayne@69
|
206 GifByteType **GifExtension);
|
jpayne@69
|
207 int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
|
jpayne@69
|
208 int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
|
jpayne@69
|
209 GifByteType **GifCodeBlock);
|
jpayne@69
|
210 int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
|
jpayne@69
|
211 int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
|
jpayne@69
|
212 const char *DGifGetGifVersion(GifFileType *GifFile);
|
jpayne@69
|
213
|
jpayne@69
|
214 /******************************************************************************
|
jpayne@69
|
215 Error handling and reporting.
|
jpayne@69
|
216 ******************************************************************************/
|
jpayne@69
|
217 extern const char *GifErrorString(int ErrorCode); /* new in 2012 - ESR */
|
jpayne@69
|
218
|
jpayne@69
|
219 /*****************************************************************************
|
jpayne@69
|
220 Everything below this point is new after version 1.2, supporting `slurp
|
jpayne@69
|
221 mode' for doing I/O in two big belts with all the image-bashing in core.
|
jpayne@69
|
222 ******************************************************************************/
|
jpayne@69
|
223
|
jpayne@69
|
224 /******************************************************************************
|
jpayne@69
|
225 Color map handling from gif_alloc.c
|
jpayne@69
|
226 ******************************************************************************/
|
jpayne@69
|
227
|
jpayne@69
|
228 extern ColorMapObject *GifMakeMapObject(int ColorCount,
|
jpayne@69
|
229 const GifColorType *ColorMap);
|
jpayne@69
|
230 extern void GifFreeMapObject(ColorMapObject *Object);
|
jpayne@69
|
231 extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,
|
jpayne@69
|
232 const ColorMapObject *ColorIn2,
|
jpayne@69
|
233 GifPixelType ColorTransIn2[]);
|
jpayne@69
|
234 extern int GifBitSize(int n);
|
jpayne@69
|
235
|
jpayne@69
|
236 /******************************************************************************
|
jpayne@69
|
237 Support for the in-core structures allocation (slurp mode).
|
jpayne@69
|
238 ******************************************************************************/
|
jpayne@69
|
239
|
jpayne@69
|
240 extern void GifApplyTranslation(SavedImage *Image,
|
jpayne@69
|
241 const GifPixelType Translation[]);
|
jpayne@69
|
242 extern int GifAddExtensionBlock(int *ExtensionBlock_Count,
|
jpayne@69
|
243 ExtensionBlock **ExtensionBlocks, int Function,
|
jpayne@69
|
244 unsigned int Len, unsigned char ExtData[]);
|
jpayne@69
|
245 extern void GifFreeExtensions(int *ExtensionBlock_Count,
|
jpayne@69
|
246 ExtensionBlock **ExtensionBlocks);
|
jpayne@69
|
247 extern SavedImage *GifMakeSavedImage(GifFileType *GifFile,
|
jpayne@69
|
248 const SavedImage *CopyFrom);
|
jpayne@69
|
249 extern void GifFreeSavedImages(GifFileType *GifFile);
|
jpayne@69
|
250
|
jpayne@69
|
251 /******************************************************************************
|
jpayne@69
|
252 5.x functions for GIF89 graphics control blocks
|
jpayne@69
|
253 ******************************************************************************/
|
jpayne@69
|
254
|
jpayne@69
|
255 int DGifExtensionToGCB(const size_t GifExtensionLength,
|
jpayne@69
|
256 const GifByteType *GifExtension,
|
jpayne@69
|
257 GraphicsControlBlock *GCB);
|
jpayne@69
|
258 size_t EGifGCBToExtension(const GraphicsControlBlock *GCB,
|
jpayne@69
|
259 GifByteType *GifExtension);
|
jpayne@69
|
260
|
jpayne@69
|
261 int DGifSavedExtensionToGCB(GifFileType *GifFile, int ImageIndex,
|
jpayne@69
|
262 GraphicsControlBlock *GCB);
|
jpayne@69
|
263 int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
|
jpayne@69
|
264 GifFileType *GifFile, int ImageIndex);
|
jpayne@69
|
265
|
jpayne@69
|
266 /******************************************************************************
|
jpayne@69
|
267 The library's internal utility font
|
jpayne@69
|
268 ******************************************************************************/
|
jpayne@69
|
269
|
jpayne@69
|
270 #define GIF_FONT_WIDTH 8
|
jpayne@69
|
271 #define GIF_FONT_HEIGHT 8
|
jpayne@69
|
272 extern const unsigned char GifAsciiTable8x8[][GIF_FONT_WIDTH];
|
jpayne@69
|
273
|
jpayne@69
|
274 extern void GifDrawText8x8(SavedImage *Image, const int x, const int y,
|
jpayne@69
|
275 const char *legend, const int color);
|
jpayne@69
|
276
|
jpayne@69
|
277 extern void GifDrawBox(SavedImage *Image, const int x, const int y, const int w,
|
jpayne@69
|
278 const int d, const int color);
|
jpayne@69
|
279
|
jpayne@69
|
280 extern void GifDrawRectangle(SavedImage *Image, const int x, const int y,
|
jpayne@69
|
281 const int w, const int d, const int color);
|
jpayne@69
|
282
|
jpayne@69
|
283 extern void GifDrawBoxedText8x8(SavedImage *Image, const int x, const int y,
|
jpayne@69
|
284 const char *legend, const int border,
|
jpayne@69
|
285 const int bg, const int fg);
|
jpayne@69
|
286
|
jpayne@69
|
287 #ifdef __cplusplus
|
jpayne@69
|
288 }
|
jpayne@69
|
289 #endif /* __cplusplus */
|
jpayne@69
|
290 #endif /* _GIF_LIB_H */
|
jpayne@69
|
291
|
jpayne@69
|
292 /* end */
|