Gif.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * The Python Imaging Library.
  3. * $Id$
  4. *
  5. * Declarations for a fast, suspendable GIF decoder.
  6. *
  7. * Copyright (c) Fredrik Lundh 1995-96.
  8. */
  9. /* Max size for a LZW code word. */
  10. #define GIFBITS 12
  11. #define GIFTABLE (1<<GIFBITS)
  12. #define GIFBUFFER (1<<GIFBITS)
  13. typedef struct {
  14. /* CONFIGURATION */
  15. /* Initial number of bits. The caller should clear all fields in
  16. this structure and set this field before calling the decoder
  17. the first time. */
  18. int bits;
  19. /* If set, this is an interlaced image. Process it the following way:
  20. * 1st pass: start at top line, lines are 8 pixels high, step 8 pixels
  21. * 2nd pass: start at line 4, lines are 4 pixels high, step 8 pixels
  22. * 3rd pass: start at line 2, lines are 2 pixels high, step 4 pixels
  23. * 4th pass: start at line 1, lines are 1 pixels high, step 2 pixels
  24. */
  25. int interlace;
  26. /* PRIVATE CONTEXT (set by decoder) */
  27. /* Interlace parameters */
  28. int step, repeat;
  29. /* Input bit buffer */
  30. INT32 bitbuffer;
  31. int bitcount;
  32. int blocksize;
  33. /* Code buffer */
  34. int codesize;
  35. int codemask;
  36. /* Constant symbol codes */
  37. int clear, end;
  38. /* Symbol history */
  39. int lastcode;
  40. unsigned char lastdata;
  41. /* History buffer */
  42. int bufferindex;
  43. unsigned char buffer[GIFTABLE];
  44. /* Symbol table */
  45. UINT16 link[GIFTABLE];
  46. unsigned char data[GIFTABLE];
  47. int next;
  48. } GIFDECODERSTATE;
  49. typedef struct GIFENCODERBLOCK_T
  50. {
  51. struct GIFENCODERBLOCK_T *next;
  52. int size;
  53. UINT8 data[255];
  54. } GIFENCODERBLOCK;
  55. typedef struct {
  56. /* CONFIGURATION */
  57. /* Initial number of bits. The caller should clear all fields in
  58. this structure and set this field before calling the encoder
  59. the first time. */
  60. int bits;
  61. /* NOTE: the expanding encoder ignores this field */
  62. /* If set, write an interlaced image (see above) */
  63. int interlace;
  64. /* PRIVATE CONTEXT (set by encoder) */
  65. /* Interlace parameters */
  66. int step, repeat;
  67. /* Output bit buffer */
  68. INT32 bitbuffer;
  69. int bitcount;
  70. /* Output buffer list (linked list) */
  71. GIFENCODERBLOCK* block; /* current block */
  72. GIFENCODERBLOCK* flush; /* output queue */
  73. GIFENCODERBLOCK* free; /* if not null, use this */
  74. /* Fields used for run-length encoding */
  75. int first; /* true if we haven't read the first pixel */
  76. int last; /* last byte value seen */
  77. int count; /* how many bytes with that value we've seen */
  78. int lastcode;
  79. } GIFENCODERSTATE;