Colour table
The colour table is the palette of a BMP file. In an image of 8 bits per pixel or fewer, each pixel is a number that picks an entry from this table. It sits straight after the DIB header, or after the bit masks when those follow the header.
00000036 00 00 00 00 FF FF FF 00
When it is present
| Bit count | Colour table | Number of entries |
|---|---|---|
1, 4, 8 | Required | biClrUsed, or 2, 16 or 256 when biClrUsed is 0 |
16, 24, 32 | Optional | biClrUsed; none when it is 0 |
0 | None | The pixels are an embedded JPEG or PNG |
At 16 bits per pixel and above the pixels hold their colours directly. A colour table
there is only a hint for displays limited to a palette, and the pixels never refer to it.
biClrUsed can be smaller than the maximum for a palette image, which saves
space when an 8-bit image uses fewer than 256 colours. A
BITMAPCOREHEADER has no biClrUsed field, so its table always has
the full 2, 16 or 256 entries.
biClrImportant gives how many of the colours, counted from the start of the
table, are needed to show the image well; 0 means all of them. Most readers ignore it.
Entries
With every header except BITMAPCOREHEADER, each entry is an
RGBQUAD of 4 bytes, in the order blue, green, red:
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | rgbBlue | Blue, 0 to 255. |
| 1 | 1 | u8 | rgbGreen | Green, 0 to 255. |
| 2 | 1 | u8 | rgbRed | Red, 0 to 255. |
| 3 | 1 | u8 | rgbReserved | Reserved, zero. |
With a BITMAPCOREHEADER, each entry is an RGBTRIPLE of 3
bytes, with no reserved byte:
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 1 | u8 | rgbtBlue | Blue, 0 to 255. |
| 1 | 1 | u8 | rgbtGreen | Green, 0 to 255. |
| 2 | 1 | u8 | rgbtRed | Red, 0 to 255. |
The table is therefore 4 × entries bytes long, or 3 × entries with a core header. A full 256-colour table takes 1024 bytes.
Palette order
The table can hold any colours in any order. A 1-bit image is not always black and white, and index 0 is not always the darker colour. Always look colours up in the table rather than assuming them.
The pixels start at the offset given in the file header, which may leave a gap after the table.