bug 772897 - implement addon manager ui for click-to-play plugins r=unfocused
[gecko.git] / image / decoders / GIF2.h
blobe24784238db0283e3256f728bacb72f546af3aa3
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 _GIF_H_
6 #define _GIF_H_
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 };
21 /* gif2.h
22 The interface for the GIF87/89a decoder.
24 // List of possible parsing states
25 typedef enum {
26 gif_type,
27 gif_global_header,
28 gif_global_colormap,
29 gif_image_start,
30 gif_image_header,
31 gif_image_colormap,
32 gif_image_body,
33 gif_lzw_start,
34 gif_lzw,
35 gif_sub_block,
36 gif_extension,
37 gif_control_extension,
38 gif_consume_block,
39 gif_skip_block,
40 gif_done,
41 gif_error,
42 gif_comment_extension,
43 gif_application_extension,
44 gif_netscape_extension_block,
45 gif_consume_netscape_extension,
46 gif_consume_comment
47 } gstate;
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 */
58 int datasize;
59 int codesize;
60 int codemask;
61 int avail; /* Index of next available slot in dictionary */
62 int oldcode;
63 uint8_t firstchar;
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 */
103 } gif_struct;
105 #endif