m-gif - GIF87a and annimated GIF89a format (MedCon)
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'. The basic defines for the format: --------------------------------------------------------------------------- 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 --------------------------------------------------------------------------- What does the format support or not support: =========================================================================== 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 =========================================================================== 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. First some explanation on the GIF format and its different structures. ======================= The GIFHEADER structure ======================= This data structure is the very first information in a GIF file: sig[6] Holds the signature of the file "GIF87a" or "GIF89a". screenwidth, screenheight The required screen dimensions in pixels to display the images. background This represents the background color. It is in fact an index entry in the color palette. 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. flags This fields contains a number of bits of information. if (gh.flags & 0x0080) is true, a global color map will follow. The number of color bits: ((gh.flags & 0x0007) + 1) The number of colors : (1 << ((gh.flags & 0x0007) + 1) if (gh.flags > 0x0008) is true, the color palette is sorted with the most important colors first. This bit is low in GIF87a. Finally (1 << ((gh.flags >> 4) + 1) represents the number of color bits in the original image. This bit is low in GIF87a. 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 `block separators' : a comma, an exclamation mark and a semicolon. ',' => the next block will be an image '!' => the next block will be an extension ';' => the end of the GIF file 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. ======================== The IMAGEBLOCK extension ======================== left, top The upper left coordinate of the image relative to the screen. width, height The image dimensions. Width is the number of pixels in a line. Depth represents the number of rows. flags This field is similar to the global flags in the GIFHEADER structure. Number of colors in the image is ((iblk.flags & 0x0007) + 1). If (iblk.flags & 0x0040) is true, the image is interlaced. In this case the image is split into four passes instead of sequential lines: 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. If (iblk.flags & 0x0020) is true, the color map is sorted. The next byte, after the IMAGEBLOCK should be the initial image code size The compressed image consists of 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: FILE *fp; int i,n; do { n = fgetc(fp); /* get code size */ if (n != EOF) { for (i=0; i<n; i++) fgetc(fp); /* skip the block */ } }while( (n != 0) && (n != EOF)) /* read the next block, if any */ After reading this hole image block, the next byte should be again a `block separator'. If this separator is an exclamation mark, the following block is an extension. The GIF extension blocks allow additional features. ===================== The COMMENT extension ===================== This is a very simple extension. The byte 0xfe after a block separator, introduces a comment block. It contains text that does not make part of the image. The comment block is stored as subblocks, ending with a zero-length subblock (or endblock). ======================= The PLAINTEXT extension ======================= This is identified by the byte 0x01 after the block separator. The data structure follows this byte. left, top The items give the starting position of the displayed text. gridwidth, gridheight Two elements that specify the distance in pixels from one character to the next. cellwidth, cellheight These fields represent the actual dimensions in pixels of the characters to be displayed. forecolor, backcolor Color map indices for the foreground and background respectively. The next data after this structure is the text itself, stored in data subblocks just like the comment block is. ========================== The CONTROLBLOCK extension ========================== A GIF file with more then one picture also contains a CONTROLBLOCK extension. The byte 0xf9 after the block separator, represents this graphics control block. Following this byte is the data structure. blocksize This field always contains the value 0x04. flags if (cb.flags & 0x01) is true, cb.transparent_color will contain a valid transparent color index. if (cb.flags & 0x02) is true, the viewing program should wait for user input before displaying the next image. if (cb.delay) is greater than zero, the viewer should at least wait for the number of seconds specified in the delay data field. The value ((cb.flags >> 2) & 0x0007) tells the method to remove the present image from the screen: 0 = do nothing 1 = leave it 2 = restore with the background color 3 = restore with the previous graphic delay The delay in 1/100ths of a second to dispose the present graphic. transparant_color This fields represents the color index of the transparant color. terminator Any clues on this? ========================= The APPLICATION extension ========================= The final extension is the APPLICATION block. The application data structure is identified by the byte 0xff just after the block separator. blocksize This contains the value 0x0b. applstring An 8-byte string that specifies the creator software. authentication This field should contain 3 bytes based on the applstring field to check the integrity of the applstring field. The APPLICATION block extension can be followed by subblocks, ending with a zero-length subblock. A special kind of APPLICATION block extension is the 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: 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
For complete information on the GIF format, we liked reading this book: ``Supercharged Bitmapped Graphics'' written by Steve Rimmer published by Windcrest/McGraw-Hill ISBN: 0-8306-3788-5
/usr/local/xmedcon/source/m-gif.h The header file. /usr/local/xmedcon/source/m-gif.c The source file.
medcon(1), xmedcon(1), xmedcon-config(1) m-acr(4), m-anlz(4), m-inw(4), m-intf(4), m-ecat(4) medcon(3)
(X)MedCon project was originally written by Erik Nolf (eNlf) for the former PET-Centre at Ghent University (Belgium). e-mail: enlf-at-users.sourceforge.net www: http://xmedcon.sourceforge.net M-GIF(4)
Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.
Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.
Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.
Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.
The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.
Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.
Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.
Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.