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.
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
Each entry is an RGBQUAD of 4 bytes, in the order blue, green, red, then a
reserved byte:
| 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. |
The table is therefore 4 × entries bytes long. A full 256-colour table takes 1024 bytes. A 2-bit image, a bit count that Windows CE allows, has up to 4 entries.
Under the CMYK compressions each entry is instead a CMYK colour of 4 bytes, in the order black, yellow, magenta, cyan.
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.