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/. */
6 #ifndef mozilla_image_decoders_GIF2_H
7 #define mozilla_image_decoders_GIF2_H
9 #define MAX_LZW_BITS 12
10 #define MAX_BITS 4097 // 2^MAX_LZW_BITS+1
11 #define MAX_COLORS 256
12 #define MIN_HOLD_SIZE 256
14 enum { GIF_TRAILER
= 0x3B }; // ';'
15 enum { GIF_IMAGE_SEPARATOR
= 0x2C }; // ','
16 enum { GIF_EXTENSION_INTRODUCER
= 0x21 }; // '!'
17 enum { GIF_GRAPHIC_CONTROL_LABEL
= 0xF9 };
18 enum { GIF_COMMENT_LABEL
= 0xFE };
19 enum { GIF_PLAIN_TEXT_LABEL
= 0x01 };
20 enum { GIF_APPLICATION_EXTENSION_LABEL
= 0xFF };
23 // The interface for the GIF87/89a decoder.
25 // List of possible parsing states
32 gif_image_header_continue
,
38 gif_control_extension
,
43 gif_comment_extension
,
44 gif_application_extension
,
45 gif_netscape_extension_block
,
46 gif_consume_netscape_extension
,
50 // A GIF decoder's state
51 typedef struct gif_struct
{
52 // Parsing state machine
53 gstate state
; // Current decoder master state
54 uint32_t bytes_to_consume
; // Number of bytes to accumulate
55 uint32_t bytes_in_hold
; // bytes accumulated so far
57 // LZW decoder state machine
58 uint8_t* stackp
; // Current stack pointer
62 int avail
; // Index of next available slot in dictionary
65 int count
; // Remaining # bytes in sub-block
66 int bits
; // Number of unread bits in "datum"
67 int32_t datum
; // 32-bit input buffer
69 // Output state machine
70 int ipass
; // Interlace pass; Ranges 1-4 if interlaced.
71 unsigned rows_remaining
; // Rows remaining to be output
72 unsigned irow
; // Current output row, starting at zero
73 uint8_t* rowp
; // Current output pointer
75 // Parameters for image frame currently being decoded
76 unsigned x_offset
, y_offset
; // With respect to "screen" origin
77 unsigned height
, width
;
78 int tpixel
; // Index of transparent pixel
79 int32_t disposal_method
; // Restore to background, leave in place, etc.
80 uint32_t* local_colormap
; // Per-image colormap
81 int local_colormap_size
; // Size of local colormap array.
82 uint32_t delay_time
; // Display time, in milliseconds,
83 // for this image in a multi-image GIF
85 // Global (multi-image) state
86 int version
; // Either 89 for GIF89 or 87 for GIF87
87 unsigned screen_width
; // Logical screen width & height
88 unsigned screen_height
;
89 uint32_t global_colormap_depth
; // Depth of global colormap array
90 int images_decoded
; // Counts images for multi-part GIFs
91 int loop_count
; // Netscape specific extension block to control
92 // the number of animation loops a GIF
95 bool progressive_display
; // If TRUE, do Haeberli interlace hack
96 bool interlaced
; // TRUE, if scanlines arrive interlaced order
97 bool is_transparent
; // TRUE, if tpixel is valid
99 uint16_t prefix
[MAX_BITS
]; // LZW decoding tables
100 uint8_t* hold
; // Accumulation buffer
101 uint32_t global_colormap
[MAX_COLORS
]; // Default colormap if local not
103 uint8_t suffix
[MAX_BITS
]; // LZW decoding tables
104 uint8_t stack
[MAX_BITS
]; // Base of LZW decoder stack
108 #endif // mozilla_image_decoders_GIF2_H