The color table for a device-independent bitmap (DIB) consists of 16-bit indexes used as the colors for the bitmap. For the SetDIBitsToDevice function, they are physical indexes; for the DeviceBitmapBits function, they are logical indexes.
In the DeviceBitmapBits and SetDIBitsToDevice functions, the final parameter, lpTranslate, provides information that is useful only for palette-capable devices. However, all devices need to include this parameter.
When DeviceBitmapBits is retrieving bits on a 256-color device, lpTranslate is a pointer to a translation table with the following results.
Bitcount | Result |
1 | A palette-sized array of bytes, each one either 0x00H or 0xFFH. The array is used to determine if the index in the bitmap corresponds to a zero or a 1 in the DIB. |
4 | A palette-sized array of bytes, each one containing a value between 0x00H and 0xFFH. Each index in the bitmap will map to the corresponding 4-bit values in the DIB. |
8 | lpTranslate will equal an identity table that can be ignored. |
24 | A palette-sized array of 32-bit values, each one containing the RGB value (and unused high byte) corresponding to the index in the bitmap. |
On a palette-capable device when the source bitmap is a monochrome bitmap, DeviceBitmapBits passes in a translation table that has only two entries, instead of 256. Entry 0 has the color-table index for black and entry 1 has the color table index for white.
When DeviceBitmapBits sets bitmap bits, GDI passes a pointer only if the bitcount is 24. The parameter points to data maintained by GDI. For every RGB value in the DIB, the display driver calls the DeviceColorMatch function (GDI.449) to match an RGB value with an index. This function returns an index to represent that color in the device-dependent bitmap.