/*
 * MultiGIF  V1.0  28-Jun-96  Andy Wardley
 *
 * (C) 1996 Andy Wardley <abw@peritas.com>.  All rights reserved.
 *
 * gif.h
 *
 * Header file containing gif block structures.
 *
 */

#ifndef GIF_H
#define GIF_H



/*
 * type definitions 
 */
typedef unsigned char       BYTE;
typedef unsigned short int  WORD;



/*
 * GIF block identifiers
 */

#define GIF_EXTENSION     0x21   /* GIF extension block               */
#define GIF_IMAGE_DESC    0x2c   /* GIF image description block       */
#define GIF_TRAILER       0x3b   /* GIF trailer (end of data stream)  */
#define GIF_TEXT_EXT      0x01   /* GIF text extension block          */
#define GIF_COMMENT_EXT   0xFE   /* GIF comment block                 */
#define GIF_GRAPHIC_EXT   0xF9   /* GIF graphic control block         */
#define GIF_APP_EXT       0xFF   /* GIF application extension block   */
#define GIF_TRANSPARENT   0x01   /* image uses transparent colour     */
#define GIF_USERINPUT     0x02   /* wait for user input before frame  */
#define GIF_DISPOSAL      0x1C   /* image disposal method             */



/*
 * GIF bit flags (some are for local or global colour tables or both)
 */

#define GIF_COLTAB        0x80   /* GIF colour table exists           */
#define GIF_COLTABRES     0x70   /* GIF colour table resolution       */
#define GIF_INTERLACE     0x40   /* GIF image is interlaced           */
#define GIF_LCOLTABSORT   0x20   /* GIF local colour table is sorted  */
#define GIF_GCOLTABSORT   0x08   /* GIF global colour table is sorted */
#define GIF_COLTABSIZ     0x07   /* GIF colour table size             */



/*
 * GIF colour table entry
 */

typedef struct gif_colour_struct
{
	BYTE red;
	BYTE green;
	BYTE blue;
} gif_colour;



/*
 * GIF header 
 */

typedef struct gif_header_struct
{
	BYTE signature[3];     /* header signature - always "GIF"  */
	BYTE version[3];       /* version - "87a" or "89a"         */
	WORD screen_width;     /* width of logical screen          */
	WORD screen_height;    /* height of logical screen         */
	BYTE packed;           /* colour table information         */
	BYTE background;       /* background colour index          */
	BYTE aspect_ratio;     /* pixel aspect ratio               */
} gif_header;



/*
 *  GIF image descriptor.
 */

typedef struct gif_img_desc_struct
{
	BYTE seperator;        /* image descriptor identifier - 2Ch  */
	WORD left;             /* X position of image                */
	WORD top;              /* Y position of image                */
	WORD width;            /* width of image                     */
	WORD height;           /* height of image                    */
	BYTE packed;           /* image and colour table information */
} gif_img_desc;



/*
 *  GIF 89a graphic control extension 
 */

typedef struct gif_graphic_control_struct
{
	BYTE introducer;       /* extension introducer - 21h         */
	BYTE label;            /* extension label - F9h              */
	BYTE blocksize;        /* size of remaining fields - 04h     */
	BYTE packed;           /* transparency/input/disposal flags  */
	WORD delay;            /* delay before display (1/100 sec)   */
	BYTE transparent;      /* transparent colour index           */
	BYTE terminator;       /* block terminator - 0               */
} gif_graphic_control;



/*
 *  GIF 89a plain text extension
 */

typedef struct gif_plain_text_struct
{
	BYTE introducer;       /* extension introducer - 21h         */
	BYTE label;            /* extension label - 01h              */
	BYTE blocksize;        /* size of remaining fields - 0Ch     */
	WORD text_grid_left;   /* X position of text grid            */
	WORD text_grid_top;    /* Y position of text grid            */
	WORD text_grid_width;  /* width of text grid                 */
	WORD text_grid_height; /* height of text grid                */
	BYTE cell_width;       /* width of a grid cell               */
	BYTE cell_height;      /* height of a grid cell              */
	BYTE text_fg_colour;   /* foreground colour index            */
	BYTE text_bg_colour;   /* background colour index            */
	BYTE *plain_text_data; /* plain text data                    */
	BYTE terminator;       /* block terminator - 0               */
} gif_plain_text;



/*
 *  GIF 89a application extension
 */

typedef struct gif_app_ext_struct
{
	BYTE introducer;       /* extension introducer - 21h         */
	BYTE label;            /* extension label - FFh              */
	BYTE blocksize;        /* size of remaining fields - 0Bh     */
	BYTE identifier[8];    /* application identifier             */
	BYTE authcode[3];      /* application authentication code    */
	BYTE *app_data;        /* application data sub-blocks        */
	BYTE terminator;       /* block terminator - 0               */
} gif_app_ext;



/*
 *  GIF 89a comment extension
 */

typedef struct gif_comment_struct
{
	BYTE introducer;       /* extension introducer - 21h         */
	BYTE label;            /* extension label - FEh              */
	BYTE *comment_data;    /* comment data sub-blocks            */
	BYTE terminator;       /* block terminator - 0               */
} gif_comment;


#endif	/* GIF_H */
