michael@0: /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef _GIF_H_ michael@0: #define _GIF_H_ michael@0: michael@0: #define MAX_LZW_BITS 12 michael@0: #define MAX_BITS 4097 /* 2^MAX_LZW_BITS+1 */ michael@0: #define MAX_COLORS 256 michael@0: #define MIN_HOLD_SIZE 256 michael@0: michael@0: enum { GIF_TRAILER = 0x3B }; //';' michael@0: enum { GIF_IMAGE_SEPARATOR = 0x2C }; //',' michael@0: enum { GIF_EXTENSION_INTRODUCER = 0x21 }; //'!' michael@0: enum { GIF_GRAPHIC_CONTROL_LABEL = 0xF9 }; michael@0: enum { GIF_COMMENT_LABEL = 0xFE }; michael@0: enum { GIF_PLAIN_TEXT_LABEL = 0x01 }; michael@0: enum { GIF_APPLICATION_EXTENSION_LABEL = 0xFF }; michael@0: michael@0: /* gif2.h michael@0: The interface for the GIF87/89a decoder. michael@0: */ michael@0: // List of possible parsing states michael@0: typedef enum { michael@0: gif_type, michael@0: gif_global_header, michael@0: gif_global_colormap, michael@0: gif_image_start, michael@0: gif_image_header, michael@0: gif_image_header_continue, michael@0: gif_image_colormap, michael@0: gif_image_body, michael@0: gif_lzw_start, michael@0: gif_lzw, michael@0: gif_sub_block, michael@0: gif_extension, michael@0: gif_control_extension, michael@0: gif_consume_block, michael@0: gif_skip_block, michael@0: gif_done, michael@0: gif_error, michael@0: gif_comment_extension, michael@0: gif_application_extension, michael@0: gif_netscape_extension_block, michael@0: gif_consume_netscape_extension, michael@0: gif_consume_comment michael@0: } gstate; michael@0: michael@0: /* A GIF decoder's state */ michael@0: typedef struct gif_struct { michael@0: /* Parsing state machine */ michael@0: gstate state; /* Curent decoder master state */ michael@0: uint32_t bytes_to_consume; /* Number of bytes to accumulate */ michael@0: uint32_t bytes_in_hold; /* bytes accumulated so far*/ michael@0: michael@0: /* LZW decoder state machine */ michael@0: uint8_t *stackp; /* Current stack pointer */ michael@0: int datasize; michael@0: int codesize; michael@0: int codemask; michael@0: int avail; /* Index of next available slot in dictionary */ michael@0: int oldcode; michael@0: uint8_t firstchar; michael@0: int count; /* Remaining # bytes in sub-block */ michael@0: int bits; /* Number of unread bits in "datum" */ michael@0: int32_t datum; /* 32-bit input buffer */ michael@0: michael@0: /* Output state machine */ michael@0: int ipass; /* Interlace pass; Ranges 1-4 if interlaced. */ michael@0: unsigned rows_remaining; /* Rows remaining to be output */ michael@0: unsigned irow; /* Current output row, starting at zero */ michael@0: uint8_t *rowp; /* Current output pointer */ michael@0: michael@0: /* Parameters for image frame currently being decoded*/ michael@0: unsigned x_offset, y_offset; /* With respect to "screen" origin */ michael@0: unsigned height, width; michael@0: int tpixel; /* Index of transparent pixel */ michael@0: int32_t disposal_method; /* Restore to background, leave in place, etc.*/ michael@0: uint32_t *local_colormap; /* Per-image colormap */ michael@0: int local_colormap_size; /* Size of local colormap array. */ michael@0: uint32_t delay_time; /* Display time, in milliseconds, michael@0: for this image in a multi-image GIF */ michael@0: michael@0: /* Global (multi-image) state */ michael@0: int version; /* Either 89 for GIF89 or 87 for GIF87 */ michael@0: unsigned screen_width; /* Logical screen width & height */ michael@0: unsigned screen_height; michael@0: uint32_t global_colormap_depth; /* Depth of global colormap array. */ michael@0: int images_decoded; /* Counts images for multi-part GIFs */ michael@0: int loop_count; /* Netscape specific extension block to control michael@0: the number of animation loops a GIF renders. */ michael@0: michael@0: bool progressive_display; /* If TRUE, do Haeberli interlace hack */ michael@0: bool interlaced; /* TRUE, if scanlines arrive interlaced order */ michael@0: bool is_transparent; /* TRUE, if tpixel is valid */ michael@0: michael@0: uint16_t prefix[MAX_BITS]; /* LZW decoding tables */ michael@0: uint8_t* hold; /* Accumulation buffer */ michael@0: uint32_t global_colormap[MAX_COLORS]; /* Default colormap if local not supplied */ michael@0: uint8_t suffix[MAX_BITS]; /* LZW decoding tables */ michael@0: uint8_t stack[MAX_BITS]; /* Base of LZW decoder stack */ michael@0: michael@0: } gif_struct; michael@0: michael@0: #endif michael@0: