The device independent bitmap header follows the file header at offset 14. It gives the size of the image, the bits per pixel and the compression. It comes in several versions, and its first field, its own size in bytes, tells a reader which one it is.
00000000 42 4D 46 00 00 00 00 00 00 00 36 00 00 00 28 00
00000010 00 00 02 00 00 00 02 00 00 00 01 00 18 00 00 00
00000020 00 00 10 00 00 00 13 0B 00 00 13 0B 00 00 00 00
00000030 00 00 00 00 00 00
BITMAPINFOHEADER: 2 by 2 pixels, 24 bits, uncompressedVersions
Each version keeps the fields of the one before it and adds more at the end, apart from the oldest, whose width and height are 16-bit. Read the size, then read the fields that version has.
| Size | Name | From | Adds |
|---|---|---|---|
12 | BITMAPCOREHEADER | Windows 2.0, OS/2 1.x | 16-bit width and height, planes, bit count |
16 | OS22XBITMAPHEADER, short form | OS/2 2.x | 32-bit width and height; the remaining fields are taken as zero |
40 | BITMAPINFOHEADER | Windows 3.0 | compression, image size, resolution, colours used |
52 | BITMAPV2INFOHEADER | Adobe Photoshop | red, green and blue masks |
56 | BITMAPV3INFOHEADER | Adobe Photoshop | alpha mask |
64 | OS22XBITMAPHEADER | OS/2 2.x | units, halftoning, colour encoding |
108 | BITMAPV4HEADER | Windows 95, NT 4.0 | masks, colour space, endpoints, gamma |
124 | BITMAPV5HEADER | Windows 98, 2000 | rendering intent, ICC profile |
The V2 and V3 sizes are not in Microsoft’s documentation; Photoshop writes them and
most readers accept them. BITMAPINFOHEADER is by far the most common, and
BITMAPV5HEADER is used for images with alpha or a colour profile. Offsets in
the tables below are from the start of the DIB header; add 14 for the offset in the
file.
BITMAPCOREHEADER
The original header, 12 bytes long. Rows are always stored bottom row first, the only compression is none, and the colour table uses 3-byte entries.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | bcSize | The header size, 12. |
| 4 | 2 | u16 | bcWidth | The width in pixels. |
| 6 | 2 | u16 | bcHeight | The height in pixels. |
| 8 | 2 | u16 | bcPlanes | The number of planes, always 1. |
| 10 | 2 | u16 | bcBitCount | Bits per pixel: 1, 4, 8 or 24. |
BITMAPINFOHEADER
The 40-byte header introduced with Windows 3.0. Width and height become signed 32-bit numbers, and compression and colour counts are added. Every later Windows version starts with these same fields.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | biSize | The header size: 40, or more for a later version. |
| 4 | 4 | i32 | biWidth | The width in pixels. |
| 8 | 4 | i32 | biHeight | The height in pixels. Positive means the rows are stored bottom row first; negative means top row first. See row order. |
| 12 | 2 | u16 | biPlanes | The number of planes, always 1. |
| 14 | 2 | u16 | biBitCount | Bits per pixel: 1, 4, 8, 16, 24 or 32, or 0 when the pixels are an embedded JPEG or PNG. |
| 16 | 4 | u32 | biCompression | How the pixels are stored: BI_RGB (0) for uncompressed, or one of the values on the compression page. |
| 20 | 4 | u32 | biSizeImage | The size of the pixel data in bytes. May be 0 for uncompressed images. |
| 24 | 4 | i32 | biXPelsPerMeter | Horizontal resolution in pixels per metre; 2835 is about 72 dots per inch. |
| 28 | 4 | i32 | biYPelsPerMeter | Vertical resolution in pixels per metre. |
| 32 | 4 | u32 | biClrUsed | The number of entries in the colour table. 0 means the most the bit count allows. |
| 36 | 4 | u32 | biClrImportant | The number of colours needed to show the image. 0 means all of them. |
With BI_BITFIELDS or BI_ALPHABITFIELDS compression, three or
four bit masks follow this header.
BITMAPV2INFOHEADER and BITMAPV3INFOHEADER
These sizes move the bit masks inside the header. V2 adds the red, green and blue masks; V3 adds the alpha mask as well.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 40 | The fields of BITMAPINFOHEADER. | ||
| 40 | 4 | u32 | RedMask | The bits of each pixel that hold red. |
| 44 | 4 | u32 | GreenMask | The bits that hold green. |
| 48 | 4 | u32 | BlueMask | The bits that hold blue. V2 ends here, at 52 bytes. |
| 52 | 4 | u32 | AlphaMask | The bits that hold alpha. V3 ends here, at 56 bytes. |
BITMAPV4HEADER
The 108-byte header of Windows 95 and NT 4.0 keeps the four masks and adds colour
space information. The masks are used when the compression is
BI_BITFIELDS.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 40 | The fields of BITMAPINFOHEADER, named bV4Size, bV4Width and so on. | ||
| 40 | 4 | u32 | bV4RedMask | The bits that hold red. |
| 44 | 4 | u32 | bV4GreenMask | The bits that hold green. |
| 48 | 4 | u32 | bV4BlueMask | The bits that hold blue. |
| 52 | 4 | u32 | bV4AlphaMask | The bits that hold alpha. |
| 56 | 4 | u32 | bV4CSType | The colour space, such as LCS_sRGB. |
| 60 | 36 | CIEXYZTRIPLE | bV4Endpoints | The red, green and blue primaries, used for a calibrated colour space. |
| 96 | 4 | u32 | bV4GammaRed | Red gamma, as 16.16 fixed point. |
| 100 | 4 | u32 | bV4GammaGreen | Green gamma. |
| 104 | 4 | u32 | bV4GammaBlue | Blue gamma. |
BITMAPV5HEADER
The 124-byte header of Windows 98 and 2000 adds a rendering intent and a link to an ICC colour profile, either embedded in the file or named as a separate file.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 108 | The fields of BITMAPV4HEADER, named bV5Size and so on. | ||
| 108 | 4 | u32 | bV5Intent | The rendering intent. |
| 112 | 4 | u32 | bV5ProfileData | The offset of the profile, from the start of this header. |
| 116 | 4 | u32 | bV5ProfileSize | The size of the profile in bytes. |
| 120 | 4 | u32 | bV5Reserved | Reserved, zero. |
OS22XBITMAPHEADER
OS/2 2.x defined a 64-byte header. Its first 40 bytes line up with
BITMAPINFOHEADER, but two compression values differ: 3 means Huffman 1D and
4 means RLE24. A short form keeps only the first 16 bytes, and the missing fields are
taken as zero. OS/2 colour tables use 4-byte entries.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | cbFix | The header size, 64 or 16. |
| 4 | 4 | u32 | cx | The width in pixels. |
| 8 | 4 | u32 | cy | The height in pixels. |
| 12 | 2 | u16 | cPlanes | The number of planes, 1. |
| 14 | 2 | u16 | cBitCount | Bits per pixel. The short form ends here. |
| 16 | 4 | u32 | ulCompression | 0 none, 1 RLE8, 2 RLE4, 3 Huffman 1D, 4 RLE24. |
| 20 | 4 | u32 | cbImage | The size of the pixel data in bytes. |
| 24 | 4 | u32 | cxResolution | Horizontal resolution. |
| 28 | 4 | u32 | cyResolution | Vertical resolution. |
| 32 | 4 | u32 | cclrUsed | The number of colours used. |
| 36 | 4 | u32 | cclrImportant | The number of important colours. |
| 40 | 2 | u16 | usUnits | The resolution units; 0 is pixels per metre. |
| 42 | 2 | u16 | usReserved | Reserved. |
| 44 | 2 | u16 | usRecording | The row order; 0, bottom row first, is the only value defined. |
| 46 | 2 | u16 | usRendering | The halftoning method used, if any. |
| 48 | 4 | u32 | cSize1 | The first halftoning parameter. |
| 52 | 4 | u32 | cSize2 | The second halftoning parameter. |
| 56 | 4 | u32 | ulColorEncoding | The colour encoding; 0 is RGB. |
| 60 | 4 | u32 | ulIdentifier | Free for the application’s own use. |
Row order
A positive height means the first row in the file is the bottom row of the picture, a
bottom-up bitmap. A negative height means the first row is the top row, a top-down bitmap,
and the image is |biHeight| rows tall. Top-down bitmaps cannot be compressed:
their compression must be BI_RGB or BI_BITFIELDS. The width is
always positive.
The pixel data page shows how rows are laid out and padded.