Path: blob/master/src/java.desktop/share/native/libsplashscreen/giflib/gif_lib.h
41153 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/******************************************************************************2526gif_lib.h - service library for decoding and encoding GIF images2728SPDX-License-Identifier: MIT2930*****************************************************************************/3132#ifndef _GIF_LIB_H_33#define _GIF_LIB_H_ 13435#ifdef __cplusplus36extern "C" {37#endif /* __cplusplus */3839#define GIFLIB_MAJOR 540#define GIFLIB_MINOR 241#define GIFLIB_RELEASE 14243#define GIF_ERROR 044#define GIF_OK 14546#include <stddef.h>47/** Begin JDK modifications to support building using old compilers**/48//#include <stdbool.h>49#ifdef bool50#undef bool51#endif52typedef int bool;53#define false 054#define true 155/** End JDK modifications to support building using old compilers**/5657#define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */58#define GIF_STAMP_LEN sizeof(GIF_STAMP) - 159#define GIF_VERSION_POS 3 /* Version first character in stamp. */60#define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */61#define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */6263typedef unsigned char GifPixelType;64typedef unsigned char *GifRowType;65typedef unsigned char GifByteType;66typedef unsigned int GifPrefixType;67typedef int GifWord;6869typedef struct GifColorType {70GifByteType Red, Green, Blue;71} GifColorType;7273typedef struct ColorMapObject {74int ColorCount;75int BitsPerPixel;76bool SortFlag;77GifColorType *Colors; /* on malloc(3) heap */78} ColorMapObject;7980typedef struct GifImageDesc {81GifWord Left, Top, Width, Height; /* Current image dimensions. */82bool Interlace; /* Sequential/Interlaced lines. */83ColorMapObject *ColorMap; /* The local color map */84} GifImageDesc;8586typedef struct ExtensionBlock {87int ByteCount;88GifByteType *Bytes; /* on malloc(3) heap */89int Function; /* The block function code */90#define CONTINUE_EXT_FUNC_CODE 0x00 /* continuation subblock */91#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */92#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */93#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */94#define APPLICATION_EXT_FUNC_CODE 0xff /* application block (GIF89) */95} ExtensionBlock;9697typedef struct SavedImage {98GifImageDesc ImageDesc;99GifByteType *RasterBits; /* on malloc(3) heap */100int ExtensionBlockCount; /* Count of extensions before image */101ExtensionBlock *ExtensionBlocks; /* Extensions before image */102} SavedImage;103104typedef struct GifFileType {105GifWord SWidth, SHeight; /* Size of virtual canvas */106GifWord SColorResolution; /* How many colors can we generate? */107GifWord SBackGroundColor; /* Background color for virtual canvas */108GifByteType AspectByte; /* Used to compute pixel aspect ratio */109ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */110int ImageCount; /* Number of current image (both APIs) */111GifImageDesc Image; /* Current image (low-level API) */112SavedImage *SavedImages; /* Image sequence (high-level API) */113int ExtensionBlockCount; /* Count extensions past last image */114ExtensionBlock *ExtensionBlocks; /* Extensions past last image */115int Error; /* Last error condition reported */116void *UserData; /* hook to attach user data (TVT) */117void *Private; /* Don't mess with this! */118} GifFileType;119120#define GIF_ASPECT_RATIO(n) ((n)+15.0/64.0)121122typedef enum {123UNDEFINED_RECORD_TYPE,124SCREEN_DESC_RECORD_TYPE,125IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */126EXTENSION_RECORD_TYPE, /* Begin with '!' */127TERMINATE_RECORD_TYPE /* Begin with ';' */128} GifRecordType;129130/* func type to read gif data from arbitrary sources (TVT) */131typedef int (*InputFunc) (GifFileType *, GifByteType *, int);132133/* func type to write gif data to arbitrary targets.134* Returns count of bytes written. (MRB)135*/136typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int);137138/******************************************************************************139GIF89 structures140******************************************************************************/141142typedef struct GraphicsControlBlock {143int DisposalMode;144#define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */145#define DISPOSE_DO_NOT 1 /* Leave image in place */146#define DISPOSE_BACKGROUND 2 /* Set area too background color */147#define DISPOSE_PREVIOUS 3 /* Restore to previous content */148bool UserInputFlag; /* User confirmation required before disposal */149int DelayTime; /* pre-display delay in 0.01sec units */150int TransparentColor; /* Palette index for transparency, -1 if none */151#define NO_TRANSPARENT_COLOR -1152} GraphicsControlBlock;153154/******************************************************************************155GIF encoding routines156******************************************************************************/157158/* Main entry points */159GifFileType *EGifOpenFileName(const char *GifFileName,160const bool GifTestExistence, int *Error);161GifFileType *EGifOpenFileHandle(const int GifFileHandle, int *Error);162GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *Error);163int EGifSpew(GifFileType * GifFile);164const char *EGifGetGifVersion(GifFileType *GifFile); /* new in 5.x */165int EGifCloseFile(GifFileType *GifFile, int *ErrorCode);166167#define E_GIF_SUCCEEDED 0168#define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */169#define E_GIF_ERR_WRITE_FAILED 2170#define E_GIF_ERR_HAS_SCRN_DSCR 3171#define E_GIF_ERR_HAS_IMAG_DSCR 4172#define E_GIF_ERR_NO_COLOR_MAP 5173#define E_GIF_ERR_DATA_TOO_BIG 6174#define E_GIF_ERR_NOT_ENOUGH_MEM 7175#define E_GIF_ERR_DISK_IS_FULL 8176#define E_GIF_ERR_CLOSE_FAILED 9177#define E_GIF_ERR_NOT_WRITEABLE 10178179/* These are legacy. You probably do not want to call them directly */180int EGifPutScreenDesc(GifFileType *GifFile,181const int GifWidth, const int GifHeight,182const int GifColorRes,183const int GifBackGround,184const ColorMapObject *GifColorMap);185int EGifPutImageDesc(GifFileType *GifFile,186const int GifLeft, const int GifTop,187const int GifWidth, const int GifHeight,188const bool GifInterlace,189const ColorMapObject *GifColorMap);190void EGifSetGifVersion(GifFileType *GifFile, const bool gif89);191int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine,192int GifLineLen);193int EGifPutPixel(GifFileType *GifFile, const GifPixelType GifPixel);194int EGifPutComment(GifFileType *GifFile, const char *GifComment);195int EGifPutExtensionLeader(GifFileType *GifFile, const int GifExtCode);196int EGifPutExtensionBlock(GifFileType *GifFile,197const int GifExtLen, const void *GifExtension);198int EGifPutExtensionTrailer(GifFileType *GifFile);199int EGifPutExtension(GifFileType *GifFile, const int GifExtCode,200const int GifExtLen,201const void *GifExtension);202int EGifPutCode(GifFileType *GifFile, int GifCodeSize,203const GifByteType *GifCodeBlock);204int EGifPutCodeNext(GifFileType *GifFile,205const GifByteType *GifCodeBlock);206207/******************************************************************************208GIF decoding routines209******************************************************************************/210211/* Main entry points */212GifFileType *DGifOpenFileName(const char *GifFileName, int *Error);213GifFileType *DGifOpenFileHandle(int GifFileHandle, int *Error);214int DGifSlurp(GifFileType * GifFile);215GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *Error); /* new one (TVT) */216int DGifCloseFile(GifFileType * GifFile, int *ErrorCode);217218#define D_GIF_SUCCEEDED 0219#define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */220#define D_GIF_ERR_READ_FAILED 102221#define D_GIF_ERR_NOT_GIF_FILE 103222#define D_GIF_ERR_NO_SCRN_DSCR 104223#define D_GIF_ERR_NO_IMAG_DSCR 105224#define D_GIF_ERR_NO_COLOR_MAP 106225#define D_GIF_ERR_WRONG_RECORD 107226#define D_GIF_ERR_DATA_TOO_BIG 108227#define D_GIF_ERR_NOT_ENOUGH_MEM 109228#define D_GIF_ERR_CLOSE_FAILED 110229#define D_GIF_ERR_NOT_READABLE 111230#define D_GIF_ERR_IMAGE_DEFECT 112231#define D_GIF_ERR_EOF_TOO_SOON 113232233/* These are legacy. You probably do not want to call them directly */234int DGifGetScreenDesc(GifFileType *GifFile);235int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);236int DGifGetImageHeader(GifFileType *GifFile);237int DGifGetImageDesc(GifFileType *GifFile);238int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);239int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);240int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,241GifByteType **GifExtension);242int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);243int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,244GifByteType **GifCodeBlock);245int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);246int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);247const char *DGifGetGifVersion(GifFileType *GifFile);248249250/******************************************************************************251Error handling and reporting.252******************************************************************************/253extern const char *GifErrorString(int ErrorCode); /* new in 2012 - ESR */254255/*****************************************************************************256Everything below this point is new after version 1.2, supporting `slurp257mode' for doing I/O in two big belts with all the image-bashing in core.258******************************************************************************/259260/******************************************************************************261Color map handling from gif_alloc.c262******************************************************************************/263264extern ColorMapObject *GifMakeMapObject(int ColorCount,265const GifColorType *ColorMap);266extern void GifFreeMapObject(ColorMapObject *Object);267extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,268const ColorMapObject *ColorIn2,269GifPixelType ColorTransIn2[]);270extern int GifBitSize(int n);271272/******************************************************************************273Support for the in-core structures allocation (slurp mode).274******************************************************************************/275276extern void GifApplyTranslation(SavedImage *Image, GifPixelType Translation[]);277extern int GifAddExtensionBlock(int *ExtensionBlock_Count,278ExtensionBlock **ExtensionBlocks,279int Function,280unsigned int Len, unsigned char ExtData[]);281extern void GifFreeExtensions(int *ExtensionBlock_Count,282ExtensionBlock **ExtensionBlocks);283extern SavedImage *GifMakeSavedImage(GifFileType *GifFile,284const SavedImage *CopyFrom);285extern void GifFreeSavedImages(GifFileType *GifFile);286287/******************************************************************************2885.x functions for GIF89 graphics control blocks289******************************************************************************/290291int DGifExtensionToGCB(const size_t GifExtensionLength,292const GifByteType *GifExtension,293GraphicsControlBlock *GCB);294size_t EGifGCBToExtension(const GraphicsControlBlock *GCB,295GifByteType *GifExtension);296297int DGifSavedExtensionToGCB(GifFileType *GifFile,298int ImageIndex,299GraphicsControlBlock *GCB);300int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,301GifFileType *GifFile,302int ImageIndex);303304/******************************************************************************305The library's internal utility font306******************************************************************************/307308#define GIF_FONT_WIDTH 8309#define GIF_FONT_HEIGHT 8310extern const unsigned char GifAsciiTable8x8[][GIF_FONT_WIDTH];311312extern void GifDrawText8x8(SavedImage *Image,313const int x, const int y,314const char *legend, const int color);315316extern void GifDrawBox(SavedImage *Image,317const int x, const int y,318const int w, const int d, const int color);319320extern void GifDrawRectangle(SavedImage *Image,321const int x, const int y,322const int w, const int d, const int color);323324extern void GifDrawBoxedText8x8(SavedImage *Image,325const int x, const int y,326const char *legend,327const int border, const int bg, const int fg);328329#ifdef __cplusplus330}331#endif /* __cplusplus */332#endif /* _GIF_LIB_H */333334/* end */335336337