GIF2.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_image_decoders_GIF2_H
  6. #define mozilla_image_decoders_GIF2_H
  7. #define MAX_LZW_BITS 12
  8. #define MAX_BITS 4097 // 2^MAX_LZW_BITS+1
  9. #define MAX_COLORS 256
  10. #define MIN_HOLD_SIZE 256
  11. enum { GIF_TRAILER = 0x3B }; // ';'
  12. enum { GIF_IMAGE_SEPARATOR = 0x2C }; // ','
  13. enum { GIF_EXTENSION_INTRODUCER = 0x21 }; // '!'
  14. enum { GIF_GRAPHIC_CONTROL_LABEL = 0xF9 };
  15. enum { GIF_APPLICATION_EXTENSION_LABEL = 0xFF };
  16. // A GIF decoder's state
  17. typedef struct gif_struct {
  18. // LZW decoder state machine
  19. uint8_t* stackp; // Current stack pointer
  20. int datasize;
  21. int codesize;
  22. int codemask;
  23. int avail; // Index of next available slot in dictionary
  24. int oldcode;
  25. uint8_t firstchar;
  26. int bits; // Number of unread bits in "datum"
  27. int32_t datum; // 32-bit input buffer
  28. // Output state machine
  29. int64_t pixels_remaining; // Pixels remaining to be output.
  30. // Parameters for image frame currently being decoded
  31. int tpixel; // Index of transparent pixel
  32. int32_t disposal_method; // Restore to background, leave in place, etc.
  33. uint32_t* local_colormap; // Per-image colormap
  34. int local_colormap_size; // Size of local colormap array.
  35. uint32_t delay_time; // Display time, in milliseconds,
  36. // for this image in a multi-image GIF
  37. // Global (multi-image) state
  38. int version; // Either 89 for GIF89 or 87 for GIF87
  39. int32_t screen_width; // Logical screen width & height
  40. int32_t screen_height;
  41. uint8_t global_colormap_depth; // Depth of global colormap array
  42. uint16_t global_colormap_count; // Number of colors in global colormap
  43. int images_decoded; // Counts images for multi-part GIFs
  44. int loop_count; // Netscape specific extension block to control
  45. // the number of animation loops a GIF
  46. // renders.
  47. bool is_transparent; // TRUE, if tpixel is valid
  48. uint16_t prefix[MAX_BITS]; // LZW decoding tables
  49. uint32_t global_colormap[MAX_COLORS]; // Default colormap if local not
  50. // supplied
  51. uint8_t suffix[MAX_BITS]; // LZW decoding tables
  52. uint8_t stack[MAX_BITS]; // Base of LZW decoder stack
  53. } gif_struct;
  54. #endif // mozilla_image_decoders_GIF2_H