2
0

gif_lib.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /******************************************************************************
  2. * In order to make life a little bit easier when using the GIF file format,
  3. * this library was written, and which does all the dirty work...
  4. *
  5. * Written by Gershon Elber, Jun. 1989
  6. * Hacks by Eric S. Raymond, Sep. 1992
  7. ******************************************************************************
  8. * History:
  9. * 14 Jun 89 - Version 1.0 by Gershon Elber.
  10. * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names)
  11. * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp)
  12. * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support)
  13. * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code)
  14. *****************************************************************************/
  15. #ifndef _GIF_LIB_H_
  16. #define _GIF_LIB_H_ 1
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif /* __cplusplus */
  20. #define GIF_LIB_VERSION " Version 4.1, "
  21. #define GIF_ERROR 0
  22. #define GIF_OK 1
  23. #ifndef TRUE
  24. #define TRUE 1
  25. #endif /* TRUE */
  26. #ifndef FALSE
  27. #define FALSE 0
  28. #endif /* FALSE */
  29. #ifndef NULL
  30. #define NULL 0
  31. #endif /* NULL */
  32. #define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
  33. #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
  34. #define GIF_VERSION_POS 3 /* Version first character in stamp. */
  35. #define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */
  36. #define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */
  37. #define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */
  38. typedef int GifBooleanType;
  39. typedef unsigned char GifPixelType;
  40. typedef unsigned char *GifRowType;
  41. typedef unsigned char GifByteType;
  42. #ifdef _GBA_OPTMEM
  43. typedef unsigned short GifPrefixType;
  44. typedef short GifWord;
  45. #else
  46. typedef unsigned int GifPrefixType;
  47. typedef int GifWord;
  48. #endif
  49. #define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg)
  50. #define GIF_EXIT(Msg) { GIF_MESSAGE(Msg); exit(-3); }
  51. #ifdef SYSV
  52. #define VoidPtr char *
  53. #else
  54. #define VoidPtr void *
  55. #endif /* SYSV */
  56. typedef struct GifColorType {
  57. GifByteType Red, Green, Blue;
  58. } GifColorType;
  59. typedef struct ColorMapObject {
  60. int ColorCount;
  61. int BitsPerPixel;
  62. GifColorType *Colors; /* on malloc(3) heap */
  63. } ColorMapObject;
  64. typedef struct GifImageDesc {
  65. GifWord Left, Top, Width, Height, /* Current image dimensions. */
  66. Interlace; /* Sequential/Interlaced lines. */
  67. ColorMapObject *ColorMap; /* The local color map */
  68. } GifImageDesc;
  69. typedef struct GifFileType {
  70. GifWord SWidth, SHeight, /* Screen dimensions. */
  71. SColorResolution, /* How many colors can we generate? */
  72. SBackGroundColor; /* I hope you understand this one... */
  73. ColorMapObject *SColorMap; /* NULL if not exists. */
  74. int ImageCount; /* Number of current image */
  75. GifImageDesc Image; /* Block describing current image */
  76. struct SavedImage *SavedImages; /* Use this to accumulate file state */
  77. VoidPtr UserData; /* hook to attach user data (TVT) */
  78. VoidPtr Private; /* Don't mess with this! */
  79. } GifFileType;
  80. typedef enum {
  81. UNDEFINED_RECORD_TYPE,
  82. SCREEN_DESC_RECORD_TYPE,
  83. IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
  84. EXTENSION_RECORD_TYPE, /* Begin with '!' */
  85. TERMINATE_RECORD_TYPE /* Begin with ';' */
  86. } GifRecordType;
  87. /* DumpScreen2Gif routine constants identify type of window/screen to dump.
  88. * Note all values below 1000 are reserved for the IBMPC different display
  89. * devices (it has many!) and are compatible with the numbering TC2.0
  90. * (Turbo C 2.0 compiler for IBM PC) gives to these devices.
  91. */
  92. typedef enum {
  93. GIF_DUMP_SGI_WINDOW = 1000,
  94. GIF_DUMP_X_WINDOW = 1001
  95. } GifScreenDumpType;
  96. /* func type to read gif data from arbitrary sources (TVT) */
  97. typedef int (*InputFunc) (GifFileType *, GifByteType *, int);
  98. /* func type to write gif data ro arbitrary targets.
  99. * Returns count of bytes written. (MRB)
  100. */
  101. typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int);
  102. /******************************************************************************
  103. * GIF89 extension function codes
  104. ******************************************************************************/
  105. #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
  106. #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control */
  107. #define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
  108. #define APPLICATION_EXT_FUNC_CODE 0xff /* application block */
  109. /******************************************************************************
  110. * O.K., here are the routines one can access in order to encode GIF file:
  111. * (GIF_LIB file EGIF_LIB.C).
  112. ******************************************************************************/
  113. GifFileType *EGifOpenFileName(const char *GifFileName,
  114. int GifTestExistance);
  115. GifFileType *EGifOpenFileHandle(int GifFileHandle);
  116. GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc);
  117. int EGifSpew(GifFileType * GifFile);
  118. void EGifSetGifVersion(const char *Version);
  119. int EGifPutScreenDesc(GifFileType * GifFile,
  120. int GifWidth, int GifHeight, int GifColorRes,
  121. int GifBackGround,
  122. const ColorMapObject * GifColorMap);
  123. int EGifPutImageDesc(GifFileType * GifFile, int GifLeft, int GifTop,
  124. int Width, int GifHeight, int GifInterlace,
  125. const ColorMapObject * GifColorMap);
  126. int EGifPutLine(GifFileType * GifFile, GifPixelType * GifLine,
  127. int GifLineLen);
  128. int EGifPutPixel(GifFileType * GifFile, GifPixelType GifPixel);
  129. int EGifPutComment(GifFileType * GifFile, const char *GifComment);
  130. int EGifPutExtensionFirst(GifFileType * GifFile, int GifExtCode,
  131. int GifExtLen, const VoidPtr GifExtension);
  132. int EGifPutExtensionNext(GifFileType * GifFile, int GifExtCode,
  133. int GifExtLen, const VoidPtr GifExtension);
  134. int EGifPutExtensionLast(GifFileType * GifFile, int GifExtCode,
  135. int GifExtLen, const VoidPtr GifExtension);
  136. int EGifPutExtension(GifFileType * GifFile, int GifExtCode, int GifExtLen,
  137. const VoidPtr GifExtension);
  138. int EGifPutCode(GifFileType * GifFile, int GifCodeSize,
  139. const GifByteType * GifCodeBlock);
  140. int EGifPutCodeNext(GifFileType * GifFile,
  141. const GifByteType * GifCodeBlock);
  142. int EGifCloseFile(GifFileType * GifFile);
  143. #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
  144. #define E_GIF_ERR_WRITE_FAILED 2
  145. #define E_GIF_ERR_HAS_SCRN_DSCR 3
  146. #define E_GIF_ERR_HAS_IMAG_DSCR 4
  147. #define E_GIF_ERR_NO_COLOR_MAP 5
  148. #define E_GIF_ERR_DATA_TOO_BIG 6
  149. #define E_GIF_ERR_NOT_ENOUGH_MEM 7
  150. #define E_GIF_ERR_DISK_IS_FULL 8
  151. #define E_GIF_ERR_CLOSE_FAILED 9
  152. #define E_GIF_ERR_NOT_WRITEABLE 10
  153. /******************************************************************************
  154. * O.K., here are the routines one can access in order to decode GIF file:
  155. * (GIF_LIB file DGIF_LIB.C).
  156. *****************************************************************************/
  157. #ifndef _GBA_NO_FILEIO
  158. GifFileType *DGifOpenFileName(const char *GifFileName);
  159. GifFileType *DGifOpenFileHandle(int GifFileHandle);
  160. int DGifSlurp(GifFileType * GifFile);
  161. #endif /* _GBA_NO_FILEIO */
  162. GifFileType *DGifOpen(void *userPtr, InputFunc readFunc); /* new one
  163. * (TVT) */
  164. int DGifGetScreenDesc(GifFileType * GifFile);
  165. int DGifGetRecordType(GifFileType * GifFile, GifRecordType * GifType);
  166. int DGifGetImageDesc(GifFileType * GifFile);
  167. int DGifGetLine(GifFileType * GifFile, GifPixelType * GifLine, int GifLineLen);
  168. int DGifGetPixel(GifFileType * GifFile, GifPixelType GifPixel);
  169. int DGifGetComment(GifFileType * GifFile, char *GifComment);
  170. int DGifGetExtension(GifFileType * GifFile, int *GifExtCode,
  171. GifByteType ** GifExtension);
  172. int DGifGetExtensionNext(GifFileType * GifFile, GifByteType ** GifExtension);
  173. int DGifGetCode(GifFileType * GifFile, int *GifCodeSize,
  174. GifByteType ** GifCodeBlock);
  175. int DGifGetCodeNext(GifFileType * GifFile, GifByteType ** GifCodeBlock);
  176. int DGifGetLZCodes(GifFileType * GifFile, int *GifCode);
  177. int DGifCloseFile(GifFileType * GifFile);
  178. #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
  179. #define D_GIF_ERR_READ_FAILED 102
  180. #define D_GIF_ERR_NOT_GIF_FILE 103
  181. #define D_GIF_ERR_NO_SCRN_DSCR 104
  182. #define D_GIF_ERR_NO_IMAG_DSCR 105
  183. #define D_GIF_ERR_NO_COLOR_MAP 106
  184. #define D_GIF_ERR_WRONG_RECORD 107
  185. #define D_GIF_ERR_DATA_TOO_BIG 108
  186. #define D_GIF_ERR_NOT_ENOUGH_MEM 109
  187. #define D_GIF_ERR_CLOSE_FAILED 110
  188. #define D_GIF_ERR_NOT_READABLE 111
  189. #define D_GIF_ERR_IMAGE_DEFECT 112
  190. #define D_GIF_ERR_EOF_TOO_SOON 113
  191. /******************************************************************************
  192. * O.K., here are the routines from GIF_LIB file QUANTIZE.C.
  193. ******************************************************************************/
  194. int QuantizeBuffer(unsigned int Width, unsigned int Height,
  195. int *ColorMapSize, GifByteType * RedInput,
  196. GifByteType * GreenInput, GifByteType * BlueInput,
  197. GifByteType * OutputBuffer,
  198. GifColorType * OutputColorMap);
  199. /******************************************************************************
  200. * O.K., here are the routines from GIF_LIB file QPRINTF.C.
  201. ******************************************************************************/
  202. extern int GifQuietPrint;
  203. #ifdef HAVE_STDARG_H
  204. extern void GifQprintf(char *Format, ...);
  205. #elif defined (HAVE_VARARGS_H)
  206. extern void GifQprintf();
  207. #endif /* HAVE_STDARG_H */
  208. /******************************************************************************
  209. * O.K., here are the routines from GIF_LIB file GIF_ERR.C.
  210. ******************************************************************************/
  211. #ifndef _GBA_NO_FILEIO
  212. extern void PrintGifError(void);
  213. #endif /* _GBA_NO_FILEIO */
  214. extern int GifLastError(void);
  215. /******************************************************************************
  216. * O.K., here are the routines from GIF_LIB file DEV2GIF.C.
  217. ******************************************************************************/
  218. extern int DumpScreen2Gif(const char *FileName,
  219. int ReqGraphDriver,
  220. long ReqGraphMode1,
  221. long ReqGraphMode2,
  222. long ReqGraphMode3);
  223. /*****************************************************************************
  224. *
  225. * Everything below this point is new after version 1.2, supporting `slurp
  226. * mode' for doing I/O in two big belts with all the image-bashing in core.
  227. *
  228. *****************************************************************************/
  229. /******************************************************************************
  230. * Color Map handling from ALLOCGIF.C
  231. *****************************************************************************/
  232. extern ColorMapObject *MakeMapObject(int ColorCount,
  233. const GifColorType * ColorMap);
  234. extern void FreeMapObject(ColorMapObject * Object);
  235. extern ColorMapObject *UnionColorMap(const ColorMapObject * ColorIn1,
  236. const ColorMapObject * ColorIn2,
  237. GifPixelType ColorTransIn2[]);
  238. extern int BitSize(int n);
  239. /******************************************************************************
  240. * Support for the in-core structures allocation (slurp mode).
  241. *****************************************************************************/
  242. /* This is the in-core version of an extension record */
  243. typedef struct {
  244. int ByteCount;
  245. char *Bytes; /* on malloc(3) heap */
  246. int Function; /* Holds the type of the Extension block. */
  247. } ExtensionBlock;
  248. /* This holds an image header, its unpacked raster bits, and extensions */
  249. typedef struct SavedImage {
  250. GifImageDesc ImageDesc;
  251. unsigned char *RasterBits; /* on malloc(3) heap */
  252. int Function; /* DEPRECATED: Use ExtensionBlocks[x].Function instead */
  253. int ExtensionBlockCount;
  254. ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */
  255. } SavedImage;
  256. extern void ApplyTranslation(SavedImage * Image, GifPixelType Translation[]);
  257. extern void MakeExtension(SavedImage * New, int Function);
  258. extern int AddExtensionBlock(SavedImage * New, int Len,
  259. unsigned char ExtData[]);
  260. extern void FreeExtension(SavedImage * Image);
  261. extern SavedImage *MakeSavedImage(GifFileType * GifFile,
  262. const SavedImage * CopyFrom);
  263. extern void FreeSavedImages(GifFileType * GifFile);
  264. /******************************************************************************
  265. * The library's internal utility font
  266. *****************************************************************************/
  267. #define GIF_FONT_WIDTH 8
  268. #define GIF_FONT_HEIGHT 8
  269. extern unsigned char AsciiTable[][GIF_FONT_WIDTH];
  270. #ifdef _WIN32
  271. extern void DrawGifText(SavedImage * Image,
  272. #else
  273. extern void DrawText(SavedImage * Image,
  274. #endif
  275. const int x, const int y,
  276. const char *legend, const int color);
  277. extern void DrawBox(SavedImage * Image,
  278. const int x, const int y,
  279. const int w, const int d, const int color);
  280. void DrawRectangle(SavedImage * Image,
  281. const int x, const int y,
  282. const int w, const int d, const int color);
  283. extern void DrawBoxedText(SavedImage * Image,
  284. const int x, const int y,
  285. const char *legend,
  286. const int border, const int bg, const int fg);
  287. #ifdef __cplusplus
  288. }
  289. #endif /* __cplusplus */
  290. #endif /* _GIF_LIB_H */