'\" t .TH M-GIF 4 .SH NAME m-gif - GIF87a and annimated GIF89a format (MedCon) .SH DESCRIPTION .PP .in 0.2i The Graphics Interchange Format from CompuServe allows between 1 and 8 bits of color information with an RGB color palette. The image arrays are compressed with an LZW coding. The extension of the file is `.gif'. .PP .in 0.2i The basic defines for the format: .PP .in 0.2i .nf --------------------------------------------------------------------------- typedef struct { char sig[6]; /* GIF87a or GIF89a */ Uint16 screenwidth,screenheight; /* screen dimensions */ Uint8 flags,background,aspect; /* background color, ratio */ } MDC_GIFHEADER; #define MDC_GIF_GH_SIZE 13 typedef struct { Uint16 left,top,width,height; /* image dimensions */ Uint8 flags; } MDC_GIFIMAGEBLOCK; #define MDC_GIF_IBLK_SIZE 9 typedef struct { /* display information */ Uint8 blocksize; Uint8 flags; Uint16 delay; Uint8 transparent_colour; Uint8 terminator; } MDC_GIFCONTROLBLOCK; #define MDC_GIF_CBLK_SIZE 6 typedef struct { /* plain text block */ Uint8 blocksize; Uint16 left,top; Uint16 gridwidth,gridheight; Uint8 cellwidth,cellheight; Uint8 forecolour,backcolour; } MDC_GIFPLAINTEXT; #define MDC_GIF_TBLK_SIZE 13 typedef struct { /* application block */ Uint8 blocksize; char applstring[8]; char authentication[3]; } MDC_GIFAPPLICATION; #define MDC_GIF_ABLK_SIZE 12 --------------------------------------------------------------------------- .fi .PP .in 0.2i What does the format support or not support: .PP .in 0.2i .nf =========================================================================== Item Supported Not Supported =========================================================================== Color Map : max 256 RGB colors - File Endian : little big Pixeltypes : Uint8 - =========================================================================== Scaling factors : quantify & calibrate factors/image are NOT supported --------------------------------------------------------------------------- Dimensions/Image : different dimensions for each image are supported --------------------------------------------------------------------------- Pixeltypes/Image : different pixeltypes for each image are NOT supported =========================================================================== .fi .PP .in 0.2i Because of the flexible nature of the GIF format it could be possible to include scaling factors per image with the GIF extension blocks, but more about this later. The image is stored from left to right and from top to bottom, unless the images are interlaced. .PP .in 0.2i First some explanation on the GIF format and its different structures. .PP .in 0.2i ======================= .br The .B GIFHEADER structure .br ======================= .PP .in 0.2i This data structure is the very first information in a GIF file: .PP .in 0.2i .TP .B sig[6] Holds the signature of the file "GIF87a" or "GIF89a". .TP .B screenwidth, screenheight The required screen dimensions in pixels to display the images. .TP .B background This represents the background color. It is in fact an index entry in the color palette. .TP .B aspect The aspect ratio of the pixels in the image. If this field is not 0 the aspect ratio is: ((gh.aspect + 15) / 64). This entry is always 0 for the GIF87a format. .TP .B flags This fields contains a number of bits of information. .br if (gh.flags & 0x0080) is true, a global color map will follow. .nf The number of color bits: ((gh.flags & 0x0007) + 1) The number of colors : (1 << ((gh.flags & 0x0007) + 1) .fi if (gh.flags > 0x0008) is true, the color palette is sorted with the most important colors first. This bit is low in GIF87a. .br Finally (1 << ((gh.flags >> 4) + 1) represents the number of color bits in the original image. This bit is low in GIF87a. .PP .in 0.2i After reading the GIFHEADER and any global colormap, there should be a `block separator' which introduce the following block of GIF information. There are three kind of .B `block separators' : a comma, an exclamation mark and a semicolon. .br .nf ',' => the next block will be an image '!' => the next block will be an extension ';' => the end of the GIF file .fi .PP .in 0.2i The image block after a comma consists of the IMAGEBLOCK structure and the compressed image. The IMAGEBLOCK structure defines the nature of the image and supersedes the global definitions. .PP .in 0.2i ======================== .br The .B IMAGEBLOCK extension .br ======================== .PP .in 0.2i .TP .B left, top The upper left coordinate of the image relative to the screen. .TP .B width, height The image dimensions. Width is the number of pixels in a line. Depth represents the number of rows. .TP .B flags This field is similar to the global flags in the GIFHEADER structure. Number of colors in the image is ((iblk.flags & 0x0007) + 1). .br If (iblk.flags & 0x0040) is true, the image is .B interlaced. In this case the image is split into four passes instead of sequential lines: .br .ce 4 1st pass: lines 0 8 16 24 ... (+8) 2nd pass: lines 4 12 20 28 ... (+8) 3rd pass: lines 2 6 10 14 ... (+4) 4th pass: lines 1 3 5 7 ... (+2) If (iblk.flags & 0x0080) is true, there is a local color map. .br If (iblk.flags & 0x0020) is true, the color map is sorted. .br .PP .in 0.2i The next byte, after the IMAGEBLOCK should be the .B initial image code size . The compressed image consists of .B subblocks of code, of which the first byte gives the amount of code bytes that follow. The last block is a zero-length block. This is how you could skip an image: .PP .in 0.2i .nf FILE *fp; int i,n; do { n = fgetc(fp); /* get code size */ if (n != EOF) { for (i=0; i> 2) & 0x0007) tells the method to remove the present image from the screen: .PP .in 0.2i .nf 0 = do nothing 1 = leave it 2 = restore with the background color 3 = restore with the previous graphic .fi .TP .B delay The delay in 1/100ths of a second to dispose the present graphic. .TP .B transparant_color This fields represents the color index of the transparant color. .TP .B terminator Any clues on this? .PP .in 0.2i ========================= .br The .B APPLICATION extension .br ========================= .PP .in 0.2i The final extension is the APPLICATION block. The application data structure is identified by the byte .B 0xff just after the block separator. .TP .B blocksize This contains the value 0x0b. .TP .B applstring An 8-byte string that specifies the creator software. .TP .B authentication This field should contain 3 bytes based on the applstring field to check the integrity of the applstring field. .PP .in 0.2i The APPLICATION block extension can be followed by subblocks, ending with a zero-length subblock. .PP .in 0.2i A special kind of APPLICATION block extension is the .B LOOPBLOCK extension used for annimated GIF files in concern to Netscape Navigator. This block comes between the GIFHEADER and IMAGEBLOCK data structures. It contains the following items: .br .nf 1. An application block ap.blocksize = 0x0b; ap.applstring = "NETSCAPE"; ap.authentication = "2.0"; 2. subblock of 3 bytes: 0x03 0x01,0xe8,0x03 3. endblock of 0 bytes: 0x00 .fi .PP .in 0.2i .SH NOTES For complete information on the GIF format, we liked reading this book: .br .PP .in 0.2i .B ``Supercharged Bitmapped Graphics'' .br written by Steve Rimmer .br published by Windcrest/McGraw-Hill .br ISBN: 0-8306-3788-5 .PP .in 0.2i .SH FILES .PP .in 0.2i .nf /usr/local/xmedcon/source/m-gif.h The header file. /usr/local/xmedcon/source/m-gif.c The source file. .fi .PP .in 0.2i .SH SEE ALSO .PP .in 0.2i medcon(1), xmedcon(1), xmedcon-config(1) .PP .in 0.2i m-acr(4), m-anlz(4), m-inw(4), m-intf(4), m-ecat(4) .PP .in 0.2i medcon(3) .PP .in 0.2i .SH AUTHOR .PP .in 0.2i .I (X)MedCon project was originally written by Erik Nolf (eNlf) for the former PET-Centre at Ghent University (Belgium). .PP .in 0.2i .TS tab(=); lB l lB l. e-mail:=enlf-at-users.sourceforge.net=www:=http://xmedcon.sourceforge.net .TE