image/decoders/GIF2.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5 #ifndef _GIF_H_
michael@0 6 #define _GIF_H_
michael@0 7
michael@0 8 #define MAX_LZW_BITS 12
michael@0 9 #define MAX_BITS 4097 /* 2^MAX_LZW_BITS+1 */
michael@0 10 #define MAX_COLORS 256
michael@0 11 #define MIN_HOLD_SIZE 256
michael@0 12
michael@0 13 enum { GIF_TRAILER = 0x3B }; //';'
michael@0 14 enum { GIF_IMAGE_SEPARATOR = 0x2C }; //','
michael@0 15 enum { GIF_EXTENSION_INTRODUCER = 0x21 }; //'!'
michael@0 16 enum { GIF_GRAPHIC_CONTROL_LABEL = 0xF9 };
michael@0 17 enum { GIF_COMMENT_LABEL = 0xFE };
michael@0 18 enum { GIF_PLAIN_TEXT_LABEL = 0x01 };
michael@0 19 enum { GIF_APPLICATION_EXTENSION_LABEL = 0xFF };
michael@0 20
michael@0 21 /* gif2.h
michael@0 22 The interface for the GIF87/89a decoder.
michael@0 23 */
michael@0 24 // List of possible parsing states
michael@0 25 typedef enum {
michael@0 26 gif_type,
michael@0 27 gif_global_header,
michael@0 28 gif_global_colormap,
michael@0 29 gif_image_start,
michael@0 30 gif_image_header,
michael@0 31 gif_image_header_continue,
michael@0 32 gif_image_colormap,
michael@0 33 gif_image_body,
michael@0 34 gif_lzw_start,
michael@0 35 gif_lzw,
michael@0 36 gif_sub_block,
michael@0 37 gif_extension,
michael@0 38 gif_control_extension,
michael@0 39 gif_consume_block,
michael@0 40 gif_skip_block,
michael@0 41 gif_done,
michael@0 42 gif_error,
michael@0 43 gif_comment_extension,
michael@0 44 gif_application_extension,
michael@0 45 gif_netscape_extension_block,
michael@0 46 gif_consume_netscape_extension,
michael@0 47 gif_consume_comment
michael@0 48 } gstate;
michael@0 49
michael@0 50 /* A GIF decoder's state */
michael@0 51 typedef struct gif_struct {
michael@0 52 /* Parsing state machine */
michael@0 53 gstate state; /* Curent decoder master state */
michael@0 54 uint32_t bytes_to_consume; /* Number of bytes to accumulate */
michael@0 55 uint32_t bytes_in_hold; /* bytes accumulated so far*/
michael@0 56
michael@0 57 /* LZW decoder state machine */
michael@0 58 uint8_t *stackp; /* Current stack pointer */
michael@0 59 int datasize;
michael@0 60 int codesize;
michael@0 61 int codemask;
michael@0 62 int avail; /* Index of next available slot in dictionary */
michael@0 63 int oldcode;
michael@0 64 uint8_t firstchar;
michael@0 65 int count; /* Remaining # bytes in sub-block */
michael@0 66 int bits; /* Number of unread bits in "datum" */
michael@0 67 int32_t datum; /* 32-bit input buffer */
michael@0 68
michael@0 69 /* Output state machine */
michael@0 70 int ipass; /* Interlace pass; Ranges 1-4 if interlaced. */
michael@0 71 unsigned rows_remaining; /* Rows remaining to be output */
michael@0 72 unsigned irow; /* Current output row, starting at zero */
michael@0 73 uint8_t *rowp; /* Current output pointer */
michael@0 74
michael@0 75 /* Parameters for image frame currently being decoded*/
michael@0 76 unsigned x_offset, y_offset; /* With respect to "screen" origin */
michael@0 77 unsigned height, width;
michael@0 78 int tpixel; /* Index of transparent pixel */
michael@0 79 int32_t disposal_method; /* Restore to background, leave in place, etc.*/
michael@0 80 uint32_t *local_colormap; /* Per-image colormap */
michael@0 81 int local_colormap_size; /* Size of local colormap array. */
michael@0 82 uint32_t delay_time; /* Display time, in milliseconds,
michael@0 83 for this image in a multi-image GIF */
michael@0 84
michael@0 85 /* Global (multi-image) state */
michael@0 86 int version; /* Either 89 for GIF89 or 87 for GIF87 */
michael@0 87 unsigned screen_width; /* Logical screen width & height */
michael@0 88 unsigned screen_height;
michael@0 89 uint32_t global_colormap_depth; /* Depth of global colormap array. */
michael@0 90 int images_decoded; /* Counts images for multi-part GIFs */
michael@0 91 int loop_count; /* Netscape specific extension block to control
michael@0 92 the number of animation loops a GIF renders. */
michael@0 93
michael@0 94 bool progressive_display; /* If TRUE, do Haeberli interlace hack */
michael@0 95 bool interlaced; /* TRUE, if scanlines arrive interlaced order */
michael@0 96 bool is_transparent; /* TRUE, if tpixel is valid */
michael@0 97
michael@0 98 uint16_t prefix[MAX_BITS]; /* LZW decoding tables */
michael@0 99 uint8_t* hold; /* Accumulation buffer */
michael@0 100 uint32_t global_colormap[MAX_COLORS]; /* Default colormap if local not supplied */
michael@0 101 uint8_t suffix[MAX_BITS]; /* LZW decoding tables */
michael@0 102 uint8_t stack[MAX_BITS]; /* Base of LZW decoder stack */
michael@0 103
michael@0 104 } gif_struct;
michael@0 105
michael@0 106 #endif
michael@0 107

mercurial