|
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_ |
|
7 |
|
8 #define MAX_LZW_BITS 12 |
|
9 #define MAX_BITS 4097 /* 2^MAX_LZW_BITS+1 */ |
|
10 #define MAX_COLORS 256 |
|
11 #define MIN_HOLD_SIZE 256 |
|
12 |
|
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 }; |
|
20 |
|
21 /* gif2.h |
|
22 The interface for the GIF87/89a decoder. |
|
23 */ |
|
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_header_continue, |
|
32 gif_image_colormap, |
|
33 gif_image_body, |
|
34 gif_lzw_start, |
|
35 gif_lzw, |
|
36 gif_sub_block, |
|
37 gif_extension, |
|
38 gif_control_extension, |
|
39 gif_consume_block, |
|
40 gif_skip_block, |
|
41 gif_done, |
|
42 gif_error, |
|
43 gif_comment_extension, |
|
44 gif_application_extension, |
|
45 gif_netscape_extension_block, |
|
46 gif_consume_netscape_extension, |
|
47 gif_consume_comment |
|
48 } gstate; |
|
49 |
|
50 /* A GIF decoder's state */ |
|
51 typedef struct gif_struct { |
|
52 /* Parsing state machine */ |
|
53 gstate state; /* Curent decoder master state */ |
|
54 uint32_t bytes_to_consume; /* Number of bytes to accumulate */ |
|
55 uint32_t bytes_in_hold; /* bytes accumulated so far*/ |
|
56 |
|
57 /* LZW decoder state machine */ |
|
58 uint8_t *stackp; /* Current stack pointer */ |
|
59 int datasize; |
|
60 int codesize; |
|
61 int codemask; |
|
62 int avail; /* Index of next available slot in dictionary */ |
|
63 int oldcode; |
|
64 uint8_t firstchar; |
|
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 */ |
|
68 |
|
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 */ |
|
74 |
|
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 */ |
|
84 |
|
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 renders. */ |
|
93 |
|
94 bool progressive_display; /* If TRUE, do Haeberli interlace hack */ |
|
95 bool interlaced; /* TRUE, if scanlines arrive interlaced order */ |
|
96 bool is_transparent; /* TRUE, if tpixel is valid */ |
|
97 |
|
98 uint16_t prefix[MAX_BITS]; /* LZW decoding tables */ |
|
99 uint8_t* hold; /* Accumulation buffer */ |
|
100 uint32_t global_colormap[MAX_COLORS]; /* Default colormap if local not supplied */ |
|
101 uint8_t suffix[MAX_BITS]; /* LZW decoding tables */ |
|
102 uint8_t stack[MAX_BITS]; /* Base of LZW decoder stack */ |
|
103 |
|
104 } gif_struct; |
|
105 |
|
106 #endif |
|
107 |