gif.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  *  Title:       GIF.H
00018  *  Purpose:     GIF Header file
00019  */
00020 #ifndef GIF_H_
00021 #define GIF_H_   1
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 #include "hdf5.h"
00028 
00029 #define MAX_PAL 768
00030 
00031 /* typedef H5T_NATIVE_UINT8  BYTE; */
00032 typedef unsigned char BYTE;
00033 
00034 /* typedef H5T_NATIVE_UINT16  WORD; */
00035 typedef unsigned long WORD;
00036 
00037 typedef char CHAR;
00038 typedef unsigned char boolean;
00039 
00040 #define false       0
00041 #define true        1
00042 
00043 /* Set the EndianOrder.
00044 ** The GIF Reader file should do this.
00045 ** Set EndianOrder = 0 if machine is little endian
00046 **     EndianOrder = 1 if machine is big endian.
00047 */
00048 extern int  EndianOrder;
00049 
00050 /*
00051 **  The GIF header format.
00052 **
00053 **  This structure actually contains the header, logical screen
00054 **  descriptor, and the global color table for the GIF image.
00055 */
00056 typedef struct _GifHeader { /* Offset   Description                         */
00057     BYTE PackedField;       /*  0Ah     Color Information                   */
00058     WORD TableSize;
00059     BYTE ImageCount;        /* Keep a count of the number of images         */
00060     BYTE CommentCount;
00061     BYTE ApplicationCount;
00062     BYTE PlainTextCount;
00063     BYTE HDFPalette[256][3];
00064     BYTE HeaderDump[6];     /* BYTE array to dump header contents           */
00065     BYTE LSDDump[7];        /* Logical Screen Descriptor dump               */
00066 } GIFHEAD;
00067 
00068 
00069 /*
00070 **  The GIF Image Descriptor.
00071 */
00072 typedef struct _GifImageDescriptor {
00073     WORD ImageWidth;            /* Width of the image in pixels             */
00074     WORD ImageHeight;           /* Height of the image in pixels            */
00075     BYTE PackedField;           /* Image and Color Table Data Information   */
00076     WORD TableSize;
00077     WORD CodeSize;              /* Minimum LZW CodeSize for image data      */
00078     BYTE HDFPalette[256][3];
00079     BYTE GIDDump[9];            /* GifImageDescriptor dump                  */
00080 
00081     BYTE *Image;                /* Decompressed Raster Image                */
00082     BYTE *GIFImage;
00083 } GIFIMAGEDESC;
00084 
00085 /*
00086 **  GIF 89a Graphic Control Extension Block
00087 */
00088 typedef struct _GifGraphicControlExtension {
00089     BYTE GCEDump[5];            /* Graphic Control Extension Dump           */
00090 } GIFGRAPHICCONTROL;
00091 
00092 /*
00093 **  GIF 89a Plain Text Extension Block
00094 */
00095 typedef struct _GifPlainTextExtension {
00096     BYTE PTEDump[15];           /* Plain Text Extension Dump                */
00097     BYTE *PlainTextData;        /* Plain Text data sub-blocks               */
00098     WORD DataSize;
00099 } GIFPLAINTEXT;
00100 
00101 
00102 /*
00103 **  GIF 89a Application Extension Block
00104 */
00105 typedef struct _GifApplicationExtension {
00106     BYTE AEDump[14];            /* Application Extension Dump               */
00107     BYTE *ApplicationData;      /* Application data sub-blocks              */
00108     WORD DataSize;
00109 } GIFAPPLICATION;
00110 
00111 /*
00112 **  GIF 89a Comment Extension Block
00113 */
00114 typedef struct _GifCommentExtension {
00115     BYTE CEDump[2];             /* Comment Extension Dump                   */
00116     BYTE *CommentData;          /* Comment data sub-blocks                  */
00117     WORD DataSize;
00118     BYTE Terminator;            /* Block Terminator (always 0)              */
00119 } GIFCOMMENT;
00120 
00121 /*
00122 ** GIF to HDF Memory Struct
00123 ** Purpose : The gif to hdf structure is used to pass all the
00124 **           gif data to the memory, which gets caught by the hdf driver
00125 **           Its the drivers job to put the data in the appropriate places
00126 **           in the HDF file.
00127 **           I have assumed that the ImageDescriptors and GraphicControls follow
00128 **           one another, ie. I have not associated them with each other. The driver
00129 **           must assume a 1-1 correspondance. The same discussion with plain text
00130 **           extension.
00131 */
00132 typedef struct _GifToMem {
00133         GIFHEAD            *GifHeader;
00134         GIFIMAGEDESC      **GifImageDesc;
00135         GIFGRAPHICCONTROL **GifGraphicControlExtension;
00136         GIFPLAINTEXT      **GifPlainTextExtension;
00137         GIFAPPLICATION    **GifApplicationExtension;
00138         GIFCOMMENT        **GifCommentExtension;
00139 } GIFTOMEM;
00140 
00141 /*
00142 **  Function Prototypes
00143 */
00144 
00145 /* GIF2MEM.C */
00146 GIFTOMEM Gif2Mem(BYTE *);
00147 
00148 /* GIFREAD.C */
00149 int ReadGifHeader(GIFHEAD *, BYTE **);
00150 int ReadGifImageDesc(GIFIMAGEDESC *, BYTE **);
00151 int ReadGifGraphicControl(GIFGRAPHICCONTROL *, BYTE **);
00152 int ReadGifPlainText(GIFPLAINTEXT *, BYTE **);
00153 int ReadGifApplication(GIFAPPLICATION *, BYTE **);
00154 int ReadGifComment(GIFCOMMENT *, BYTE **);
00155 
00156 /* HDFGIFWR.C */
00157 int hdfWriteGIF(FILE *fp, BYTE *pic, int ptype, int w, int h, BYTE *rmap,
00158                 BYTE *gmap, BYTE *bmap, BYTE *pc2ncmap, int numcols,
00159                 int colorstyle, int BitsPerPixel);
00160 
00161 /* WRITEHDF.C */
00162 int WriteHDF(GIFTOMEM , CHAR * , CHAR *);
00163 
00164 /* Function:    ReadHDF
00165 ** Return:      0 on completion without error, -1 on error
00166 ** Input:       CHAR *h5_file - HDF file name
00167 **              CHAR *dset_name - Name of the HDF Image dataset
00168 **              CHAR *pal_name - Name of the HDF palette
00169 ** Output:      BYTE* data - the HDF Image to be converted
00170 **              BYTE  palette[256][3] - the corresponding palette
00171 **              hsize_t* image_size - the size of each dimension of the image
00172 */
00173 int ReadHDF(BYTE** data, BYTE palette[256][3], hsize_t *image_size,
00174             CHAR *h5_file, CHAR *dset_name, CHAR *pal_name);
00175 
00176 BYTE *Decompress(GIFIMAGEDESC *, GIFHEAD *);
00177 BYTE GetByte(BYTE *);
00178 WORD GetWord(BYTE *);
00179 
00180 void cleanup(BYTE*);
00181 
00182 #endif  /* GIF_H_ */