image/decoders/GIF2.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/decoders/GIF2.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef _GIF_H_
     1.9 +#define _GIF_H_
    1.10 +
    1.11 +#define MAX_LZW_BITS          12
    1.12 +#define MAX_BITS            4097 /* 2^MAX_LZW_BITS+1 */
    1.13 +#define MAX_COLORS           256
    1.14 +#define MIN_HOLD_SIZE        256
    1.15 +
    1.16 +enum { GIF_TRAILER                     = 0x3B }; //';'
    1.17 +enum { GIF_IMAGE_SEPARATOR             = 0x2C }; //','
    1.18 +enum { GIF_EXTENSION_INTRODUCER        = 0x21 }; //'!'
    1.19 +enum { GIF_GRAPHIC_CONTROL_LABEL       = 0xF9 };
    1.20 +enum { GIF_COMMENT_LABEL               = 0xFE };
    1.21 +enum { GIF_PLAIN_TEXT_LABEL            = 0x01 };
    1.22 +enum { GIF_APPLICATION_EXTENSION_LABEL = 0xFF };
    1.23 +
    1.24 +/* gif2.h  
    1.25 +   The interface for the GIF87/89a decoder. 
    1.26 +*/
    1.27 +// List of possible parsing states
    1.28 +typedef enum {
    1.29 +    gif_type,
    1.30 +    gif_global_header,
    1.31 +    gif_global_colormap,
    1.32 +    gif_image_start,
    1.33 +    gif_image_header,
    1.34 +    gif_image_header_continue,
    1.35 +    gif_image_colormap,
    1.36 +    gif_image_body,
    1.37 +    gif_lzw_start,
    1.38 +    gif_lzw,
    1.39 +    gif_sub_block,
    1.40 +    gif_extension,
    1.41 +    gif_control_extension,
    1.42 +    gif_consume_block,
    1.43 +    gif_skip_block,
    1.44 +    gif_done,
    1.45 +    gif_error,
    1.46 +    gif_comment_extension,
    1.47 +    gif_application_extension,
    1.48 +    gif_netscape_extension_block,
    1.49 +    gif_consume_netscape_extension,
    1.50 +    gif_consume_comment
    1.51 +} gstate;
    1.52 +
    1.53 +/* A GIF decoder's state */
    1.54 +typedef struct gif_struct {
    1.55 +    /* Parsing state machine */
    1.56 +    gstate state;                   /* Curent decoder master state */
    1.57 +    uint32_t bytes_to_consume;      /* Number of bytes to accumulate */
    1.58 +    uint32_t bytes_in_hold;         /* bytes accumulated so far*/
    1.59 +
    1.60 +    /* LZW decoder state machine */
    1.61 +    uint8_t *stackp;              /* Current stack pointer */
    1.62 +    int datasize;
    1.63 +    int codesize;
    1.64 +    int codemask;
    1.65 +    int avail;                  /* Index of next available slot in dictionary */
    1.66 +    int oldcode;
    1.67 +    uint8_t firstchar;
    1.68 +    int count;                  /* Remaining # bytes in sub-block */
    1.69 +    int bits;                   /* Number of unread bits in "datum" */
    1.70 +    int32_t datum;              /* 32-bit input buffer */
    1.71 +
    1.72 +    /* Output state machine */
    1.73 +    int ipass;                  /* Interlace pass; Ranges 1-4 if interlaced. */
    1.74 +    unsigned rows_remaining;        /* Rows remaining to be output */
    1.75 +    unsigned irow;                  /* Current output row, starting at zero */
    1.76 +    uint8_t *rowp;                 /* Current output pointer */
    1.77 +
    1.78 +    /* Parameters for image frame currently being decoded*/
    1.79 +    unsigned x_offset, y_offset;    /* With respect to "screen" origin */
    1.80 +    unsigned height, width;
    1.81 +    int tpixel;                 /* Index of transparent pixel */
    1.82 +    int32_t disposal_method;    /* Restore to background, leave in place, etc.*/
    1.83 +    uint32_t *local_colormap;   /* Per-image colormap */
    1.84 +    int local_colormap_size;    /* Size of local colormap array. */
    1.85 +    uint32_t delay_time;        /* Display time, in milliseconds,
    1.86 +                                   for this image in a multi-image GIF */
    1.87 +
    1.88 +    /* Global (multi-image) state */
    1.89 +    int version;                /* Either 89 for GIF89 or 87 for GIF87 */
    1.90 +    unsigned screen_width;       /* Logical screen width & height */
    1.91 +    unsigned screen_height;
    1.92 +    uint32_t global_colormap_depth;  /* Depth of global colormap array. */
    1.93 +    int images_decoded;         /* Counts images for multi-part GIFs */
    1.94 +    int loop_count;             /* Netscape specific extension block to control
    1.95 +                                   the number of animation loops a GIF renders. */
    1.96 +
    1.97 +    bool progressive_display;    /* If TRUE, do Haeberli interlace hack */
    1.98 +    bool interlaced;             /* TRUE, if scanlines arrive interlaced order */
    1.99 +    bool is_transparent;         /* TRUE, if tpixel is valid */
   1.100 +
   1.101 +    uint16_t  prefix[MAX_BITS];          /* LZW decoding tables */
   1.102 +    uint8_t*  hold;                      /* Accumulation buffer */
   1.103 +    uint32_t  global_colormap[MAX_COLORS];   /* Default colormap if local not supplied */
   1.104 +    uint8_t   suffix[MAX_BITS];          /* LZW decoding tables */
   1.105 +    uint8_t   stack[MAX_BITS];           /* Base of LZW decoder stack */
   1.106 +
   1.107 +} gif_struct;
   1.108 +
   1.109 +#endif
   1.110 +

mercurial