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