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