Subversion Repositories wimsdev

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * whirlgif.h
  3.  *
  4.  * Copyright (c) 1997,1998,1999 by Hans Dinsen-Hansen
  5.  * Copyright (c) 1995,1996 by Kevin Kadow
  6.  * Copyright (c) 1990,1991,1992 by Mark Podlipec.
  7.  * All rights reserved.
  8.  *
  9.  * This software may be freely copied, modified and redistributed
  10.  * without fee provided that this copyright notice is preserved
  11.  * intact on all copies and modified copies.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software.
  14.  * It is provided solely "as is". The author(s) disclaim(s) all
  15.  * responsibility and liability with respect to this software's usage
  16.  * or its effect upon hardware or computer systems.
  17.  *
  18.  * The Graphics Interchange format (c) is the Copyright property of
  19.  * Compuserve Incorporated.  Gif(sm) is a Service Mark property of
  20.  * Compuserve Incorporated.
  21.  *
  22.  */
  23.  
  24. #define DA_REV  3.04
  25.  
  26. /* common includes */
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. #ifdef _USE_STRINGS_H
  31. #include <strings.h>
  32. #else
  33. #include <string.h>
  34. #endif
  35.  
  36. #ifdef _FOPEN_TXT_OR_BIN
  37. #define WRIBIN  "wb"
  38. #define REATXT  "rt"
  39. #define REABIN  "rb"
  40. #else
  41. /* Usually there is no need to distinguish between binary and txt */
  42. #define WRIBIN  "w"
  43. #define REATXT  "r"
  44. #define REABIN  "r"
  45. #endif
  46.  
  47. #ifndef TRUE
  48. #define TRUE 1
  49. #endif
  50. #ifndef FALSE
  51. #define FALSE 0
  52. #endif
  53.  
  54. /* define constants and defaults */
  55.     /* Default amount of inter-frame time */
  56. #define DEFAULT_TIME 10
  57.     /* If set to 1, Netscape 'loop' code will be added by default */
  58. #define DEFAULT_LOOP 0
  59.     /* If set to 1, use the colormaps from all images, not just the first */
  60. #define DEFAULT_USE_COLORMAP 0
  61.  
  62.     /* Used in calculating the transparent color */
  63. #define TRANS_NONE 1
  64. #define TRANS_RGB 2
  65. #define TRANS_MAP 3
  66.  
  67. #define DISP_NONE 0
  68. #define DISP_NOT  1
  69. #define DISP_BACK 2
  70. #define DISP_PREV 3
  71. #define DEFAULT_DISPOSAL DISP_NONE
  72.     /* set default disposal method here to any of the DISP_XXXX values */
  73.  
  74. #define BIGSTRING 256
  75. #define MAXVAL  4096        /* maxval of lzw coding size */
  76. #define MAXVALP 4096
  77. #define TERMIN 'T'
  78. #define LOOKUP 'L'
  79. #define SEARCH 'S'
  80. #define noOfArrays 20
  81. /* defines the amount of memory set aside in the encoding for the
  82.  * LOOKUP type nodes; for a 256 color GIF, the number of LOOKUP
  83.  * nodes will be <= noOfArrays, for a 128 color GIF the number of
  84.  * LOOKUP nodes will be <= 2 * noOfArrays, etc.  */
  85.  
  86. /* define shorthand for various types */
  87. #define LONG int
  88. #define ULONG unsigned int
  89. #define BYTE char
  90. #define UBYTE unsigned char
  91. #define SHORT short
  92. #define USHORT unsigned short
  93. #define WORD short int
  94. #define UWORD unsigned short int
  95.  
  96.  
  97. /* definition of various structures */
  98. typedef struct Transparency {
  99.   int type;
  100.   UBYTE valid;
  101.   UBYTE map;
  102.   UBYTE red;
  103.   UBYTE green;
  104.   UBYTE blue;
  105.   } Transparency;
  106.  
  107. typedef struct Global {
  108.   Transparency trans;
  109.   int left;
  110.   int top;
  111.   unsigned int time;
  112.   unsigned short disposal;
  113.   } Global;
  114.  
  115. typedef struct GifScreenHdr {
  116.   int width;
  117.   int height;
  118.   UBYTE m;
  119.   UBYTE cres;
  120.   UBYTE pixbits;
  121.   UBYTE bc;
  122.   UBYTE aspect;
  123.  } GifScreenHdr;
  124.  
  125. typedef union GifColor {
  126.   struct cmap {
  127.     UBYTE red;
  128.     UBYTE green;
  129.     UBYTE blue;
  130.     UBYTE pad;
  131.    } cmap;
  132.   ULONG pixel;
  133.  } GifColor;
  134.  
  135. typedef struct GifImageHdr {
  136.   int left;
  137.   int top;
  138.   int width;
  139.   int height;
  140.   UBYTE m;
  141.   UBYTE i;
  142.   UBYTE pixbits;
  143.   UBYTE reserved;
  144.  } GifImageHdr;
  145.  
  146. typedef struct GifTree {
  147.   char typ;             /* terminating, lookup, or search */
  148.   int code;             /* the code to be output */
  149.   UBYTE ix;             /* the color map index */
  150.   struct GifTree **node, *nxt, *alt;
  151. } GifTree;
  152.  
  153. /* define inline functions */
  154. #define GifPutShort(i, fout)    {fputc(i&0xff, fout); fputc(i>>8, fout);}
  155. #define GifGetShort(fin)        (Xgetc(fin) | Xgetc(fin)<<8)
  156.  
  157. /* forward declaration of the functions  */
  158. char *AddCodeToBuffer(int, short, char *);
  159. void CalcTrans(char *);
  160. void ClearTree(int, GifTree *);
  161. void GifClearTable();
  162. void GifComment(FILE *, char *);
  163. void GifDecode(FILE *, UBYTE *, GifImageHdr);
  164. void GifEncode(FILE *, UBYTE *, int, int);
  165. void GifLoop(FILE *, unsigned int);
  166. void GifReadFile(FILE *, char *, int);
  167. void GifScreenHeader(FILE *, FILE *, int);
  168. UBYTE *GifSendData(UBYTE *, int, UBYTE *);
  169. void ReadImageHeader(FILE *);
  170. void SetOffset(char *);
  171. long sq(UBYTE, UBYTE);
  172. void TheEnd();
  173. void TheEnd1(char *);
  174. void Usage();
  175. void WriteImageHeader(FILE *);
  176. UBYTE Xgetc(FILE *);
  177.