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