Image File Header Formats
BMP, PCX, JPEG, FLI/FLC, and AVI files include headers that define the image size, number of colors, and other information needed to display the image. Fastgraph provides functions for reading the image headers and retrieving their more useful items. However, there may be times when you need additional information stored in the file header. This section provides full details about the structure of the image file headers. In the tables that follow, we'll assume all offsets start at zero, all field sizes are in bytes, and all numeric values are stored with the least significant byte first.
BMP (Windows) Header Format
Windows BMP files begin with a 54-byte header:
offset | size | description |
0 | 2 | signature, must be 4D42 hex |
2 | 4 | size of BMP file in bytes (unreliable) |
6 | 2 | reserved, must be zero |
8 | 2 | reserved, must be zero |
10 | 4 | offset to start of image data in bytes |
14 | 4 | size of BITMAPINFOHEADER structure, must be 40 |
18 | 4 | image width in pixels |
22 | 4 | image height in pixels |
26 | 2 | number of planes in the image, must be 1 |
28 | 2 | number of bits per pixel (1, 4, 8, or 24) |
30 | 4 | compression type (0=none, 1=RLE-8, 2=RLE-4) |
34 | 4 | size of image data in bytes (including padding) |
38 | 4 | horizontal resolution in pixels per meter (unreliable) |
42 | 4 | vertical resolution in pixels per meter (unreliable) |
46 | 4 | number of colors in image, or zero |
50 | 4 | number of important colors, or zero |
BMP (OS/2) Header Format
OS/2 BMP files begin with a 26-byte header:
offset | size | description |
0 | 2 | signature, must be 4D42 hex |
2 | 4 | size of BMP file in bytes (unreliable) |
6 | 2 | reserved, must be zero |
8 | 2 | reserved, must be zero |
10 | 4 | offset to start of image data in bytes |
14 | 4 | size of BITMAPCOREHEADER structure, must be 12 |
18 | 2 | image width in pixels |
20 | 2 | image height in pixels |
22 | 2 | number of planes in the image, must be 1 |
24 | 2 | number of bits per pixel (1, 4, 8, or 24) |
PCX Header Format
PCX files begin with a 128-byte header:
offset | size | description |
0 | 1 | manufacturer byte, must be 10 decimal |
1 | 1 | PCX version number |
0 = PC Paintbrush version 2.5 | ||
2 = PC Paintbrush 2.8 with palette information | ||
3 = PC Paintbrush 2.8 without palette information | ||
4 = PC Paintbrush for Windows | ||
5 = PC Paintbrush 3.0 or later, PC Paintbrush Plus | ||
2 | 1 | run length encoding byte, must be 1 |
3 | 1 | number of bits per pixel per bit plane |
4 | 8 | image limits in pixels: Xmin, Ymin, Xmax, Ymax |
12 | 2 | horizontal dots per inch when printed (unreliable) |
14 | 2 | vertical dots per inch when printed (unreliable) |
16 | 48 | 16-color palette (16 RGB triples between 0-255) |
64 | 1 | reserved, must be zero |
65 | 1 | number of bit planes |
66 | 2 | video memory bytes per image row |
68 | 2 | 16-color palette interpretation (unreliable) |
0 = color or b&w, 1 = grayscale | ||
70 | 2 | horizontal screen resolution - 1 (unreliable) |
72 | 2 | vertical screen resolution - 1 (unreliable) |
74 | 54 | reserved, must be zero |
JPEG Header Format
Strictly speaking, JPEG files do not have formal headers, but fg_jpeghead() and fgi_jpeghead() return relevant information from the file's start of frame segment. We call it a header for consistency with other image file formats.
offset | size | description |
0 | 2 | JPEG SOI marker (FFD8 hex) |
2 | 2 | image width in pixels |
4 | 2 | image height in pixels |
6 | 1 | number of components (1 = grayscale, 3 = RGB) |
7 | 1 | horizontal/vertical sampling factors for component 1 |
8 | 1 | sampling factors for component 2 (if RGB) |
9 | 1 | sampling factors for component 3 (if RGB) |
FLI/FLC Header Format
FLI and FLC files begin with a 128-byte header. The fields starting at offset 22 and above in the flic file header apply to FLC files only. For FLI files, they should all be zero.
offset | size | description |
0 | 4 | file size in bytes |
4 | 2 | signature, AF11 hex for FLI files, AF12 hex for FLC files |
6 | 2 | number of frames |
8 | 2 | image width in pixels |
10 | 2 | image height in pixels |
12 | 2 | bits per pixel, must be 8 |
14 | 2 | reserved, must be 3 |
16 | 4 | time delay between frames |
units are 1/70 second for FLI files | ||
units are milliseconds for FLC files | ||
20 | 2 | reserved, must be zero |
22 | 4 | file creation date/time (MS-DOS format) |
26 | 4 | creator serial number (unreliable) |
30 | 4 | file revision date/time (MS-DOS format) |
34 | 4 | updater serial number (unreliable) |
38 | 4 | horizontal aspect ratio of creating video mode |
40 | 2 | vertical aspect ratio of creating video mode |
42 | 38 | reserved, must be zero |
80 | 4 | byte offset to start of first frame |
84 | 4 | byte offset to start of second frame |
88 | 40 | reserved, must be zero |
AVI Header Format
AVI files contain a 56-byte header, starting at offset 32 within the file.
offset | size | description |
0 | 4 | time delay between frames in microseconds |
4 | 4 | data rate of AVI data |
8 | 4 | padding multiple size, typically 2048 |
12 | 4 | parameter flags |
16 | 4 | number of video frames |
20 | 4 | number of preview frames |
24 | 4 | number of data streams (1 or 2) |
28 | 4 | suggested playback buffer size in bytes |
32 | 4 | width of video image in pixels |
36 | 4 | height of video image in pixels |
40 | 4 | time scale, typically 30 |
44 | 4 | data rate (frame rate = data rate / time scale) |
48 | 4 | starting time, typically 0 |
52 | 4 | size of AVI data chunk in time scale units |