Back to index

lightning-sunbird  0.9+nobinonly
GIF2.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 #ifndef _GIF_H_
00038 #define _GIF_H_
00039 
00040 #define MAX_LZW_BITS          12
00041 #define MAX_BITS            4097 /* 2^MAX_LZW_BITS+1 */
00042 #define MINIMUM_DELAY_TIME   100
00043 #define MAX_COLORS           256
00044 
00045 /* gif2.h  
00046    The interface for the GIF87/89a decoder. 
00047 */
00048 // List of possible parsing states
00049 typedef enum {
00050     gif_gather,
00051     gif_init,                   //1
00052     gif_type,
00053     gif_version,
00054     gif_global_header,
00055     gif_global_colormap,
00056     gif_image_start,            //6
00057     gif_image_header,
00058     gif_image_colormap,
00059     gif_image_body,
00060     gif_lzw_start,
00061     gif_lzw,                    //11
00062     gif_sub_block,
00063     gif_extension,
00064     gif_control_extension,
00065     gif_consume_block,
00066     gif_skip_block,
00067     gif_done,                   //17
00068     gif_oom,
00069     gif_error,
00070     gif_comment_extension,
00071     gif_application_extension,
00072     gif_netscape_extension_block,
00073     gif_consume_netscape_extension,
00074     gif_consume_comment,
00075     gif_delay,
00076     gif_stop_animating   //added for animation stop 
00077 } gstate;
00078 
00079 /* "Disposal" method indicates how the image should be handled in the
00080    framebuffer before the subsequent image is displayed. */
00081 typedef enum 
00082 {
00083     DISPOSE_NOT_SPECIFIED      = 0,
00084     DISPOSE_KEEP               = 1, /* Leave it in the framebuffer */
00085     DISPOSE_OVERWRITE_BGCOLOR  = 2, /* Overwrite with background color */
00086     DISPOSE_OVERWRITE_PREVIOUS = 3  /* Save-under */
00087 } gdispose;
00088 
00089 /* A GIF decoder's state */
00090 typedef struct gif_struct {
00091     void* clientptr;
00092     /* Parsing state machine */
00093     gstate state;               /* Curent decoder master state */
00094     PRUint8 *hold;              /* Accumulation buffer */
00095     PRUint8 *gather_head;       /* Next byte to read in accumulation buffer */
00096     int32 gather_request_size;  /* Number of bytes to accumulate */
00097     int32 gathered;             /* bytes accumulated so far*/
00098     gstate post_gather_state;   /* State after requested bytes accumulated */
00099 
00100     /* LZW decoder state machine */
00101     PRUint8 *stackp;              /* Current stack pointer */
00102     int datasize;
00103     int codesize;
00104     int codemask;
00105     int clear_code;             /* Codeword used to trigger dictionary reset */
00106     int avail;                  /* Index of next available slot in dictionary */
00107     int oldcode;
00108     PRUint8 firstchar;
00109     int count;                  /* Remaining # bytes in sub-block */
00110     int bits;                   /* Number of unread bits in "datum" */
00111     int32 datum;                /* 32-bit input buffer */
00112 
00113     /* Output state machine */
00114     int ipass;                  /* Interlace pass; Ranges 1-4 if interlaced. */
00115     PRUintn rows_remaining;        /* Rows remaining to be output */
00116     PRUintn irow;                  /* Current output row, starting at zero */
00117     PRUint8 *rowbuf;              /* Single scanline temporary buffer */
00118     PRUint8 *rowend;              /* Pointer to end of rowbuf */
00119     PRUint8 *rowp;                /* Current output pointer */
00120 
00121     /* Parameters for image frame currently being decoded*/
00122     PRUintn x_offset, y_offset;    /* With respect to "screen" origin */
00123     PRUintn height, width;
00124     int tpixel;                 /* Index of transparent pixel */
00125     gdispose disposal_method;   /* Restore to background, leave in place, etc.*/
00126     PRUint8 *local_colormap;    /* Per-image colormap */
00127     int local_colormap_size;    /* Size of local colormap array. */
00128     PRUint32 delay_time;        /* Display time, in milliseconds,
00129                                    for this image in a multi-image GIF */
00130 
00131     /* Global (multi-image) state */
00132     int screen_bgcolor;         /* Logical screen background color */
00133     int version;                /* Either 89 for GIF89 or 87 for GIF87 */
00134     PRUintn screen_width;       /* Logical screen width & height */
00135     PRUintn screen_height;
00136     int global_colormap_size;   /* Size of global colormap array. */
00137     int images_decoded;         /* Counts images for multi-part GIFs */
00138     int loop_count;             /* Netscape specific extension block to control
00139                                    the number of animation loops a GIF renders. */
00140 
00141     PRPackedBool progressive_display;    /* If TRUE, do Haeberli interlace hack */
00142     PRPackedBool interlaced;             /* TRUE, if scanlines arrive interlaced order */
00143     PRPackedBool is_transparent;         /* TRUE, if tpixel is valid */
00144     PRPackedBool is_local_colormap_defined;
00145 
00146     PRUint16  prefix[MAX_BITS];          /* LZW decoding tables */
00147     PRUint8   global_colormap[3*MAX_COLORS];   /* Default colormap if local not supplied, 3 bytes for each color  */
00148     PRUint8   suffix[MAX_BITS];          /* LZW decoding tables */
00149     PRUint8   stack[MAX_BITS];           /* Base of LZW decoder stack */
00150 
00151 } gif_struct;
00152 
00153 
00154 /* These are the APIs that the client calls to intialize,
00155 push data to, and shut down the GIF decoder. */
00156 PRBool GIFInit(gif_struct* gs, void* aClientData);
00157 
00158 void gif_destroy(gif_struct* aGIFStruct);
00159 
00160 PRStatus gif_write(gif_struct* aGIFStruct, const PRUint8 * buf, PRUint32 numbytes);
00161 
00162 PRBool gif_write_ready(const gif_struct* aGIFStruct);
00163 
00164 #endif
00165