M-GIF(4)
π NAME π
m-gif β the GIF87a and annimated GIF89a format for (X)MedCon π
(yes bestie, this is a section 4 kernel interfaces manual page, and we're gonna read it together)
β¨ DESCRIPTION β¨
okay so. The Graphics Interchange Format from CompuServe π lets you have 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, you ask? π¦ here's the vibe check:
- Color Map β supported: max 256 RGB colors. Not supported:
- - File Endian β supported: little. Not supported: big
- Pixeltypes β supported:
Uint8. Not supported:- - 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)
- The number of color bits:
- 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.
- if
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.
- If
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 value0x04.flagsβ if(cb.flags & 0x01)is true,cb.transparent_colorwill 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 nothing1= leave it2= restore with the background color3= restore with the previous graphic
- if
delayβ The delay in 1/100ths of a second to dispose the present graphic.transparent_colorβ This fields represents the color index of the transparent 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 value0x0b.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:
- An application block
ap.blocksize = 0x0b;ap.applstring = "NETSCAPE";ap.authentication = "2.0";
- subblock of 3 bytes:
0x030x01,0xe8,0x03
- endblock of 0 bytes:
0x00
π NOTES π
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
π FILES π
/usr/local/xmedcon/source/m-gif.hβ The header file./usr/local/xmedcon/source/m-gif.cβ The source file.
π₯ SEE ALSO π₯
medcon(1), xmedcon(1), xmedcon-config(1)
m-acr(4), m-anlz(4), m-inw(4), m-intf(4), m-ecat(4)
πΈ AUTHOR πΈ
(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
and that's the whole thing bestie, no cap, every last bit of it π
this was the M-GIF(4) page, living under the Kernel Interfaces Manual umbrella like the icon it is β thanks for reading, mwah π«Άπ
π¦ where this page comes from
- debian trixie: libmdc-dev 0.25.1-gtk3+dfsg-1 Β· GPL-2.0-or-later
- ubuntu questing: libmdc-dev 0.25.1-gtk3+dfsg-1
- ubuntu resolute: libmdc-dev 0.25.1-gtk3+dfsg-1build1 Β· GPL-2.0-or-later
- ubuntu stonking: libmdc-dev 0.26.1-gtk3+dfsg-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms