The color table is a collection of 24-bit RGB values. There are as many entries in the color table as there are colors in the bitmap. The color table isn't present for bitmaps with 24 color bits because each pixel is represented by 24-bit RGB values in the actual bitmap data area.
The color table for Windows 3.0 and Presentation Manager 1.2 DIBs consists of an array of RGBQUAD and RGBTRIPLE structures, respectively. These structures are defined as follows:
Windows 3.0 DIB | Presentation Manager 1.2 DIB |
typedef struct tagRGBQUAD { BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD; | typedef struct tagRGBTRIPLE { BYTE rgbtBlue; BYTE rgbtGreen; BYTE rgbtRed; } RGBTRIPLE; |
Because these structures are essentially alike, this section discusses them simultaneously. Each field name for the Windows RGBQUAD structure is followed by the corresponding field name for the Presentation Manager RGBTRIPLE structure, in parentheses.
The colors in the table should appear in order of importance. This can help a device driver render a bitmap on a device that cannot display as many colors as there are in the bitmap. If the DIB is in Windows 3.0 format, the driver can use the biClrImportant field of the BITMAPINFOHEADER structure to determine which colors are important.
The RGBQUAD (RGBTRIPLE) structure contains the following fields:
Windows (PM) Field | Description |
rgbBlue (rgbtBlue) | Specifies the blue intensity. |
rgbGreen (rgbtGreen) | Specifies the green intensity. |
rgbRed (rgbtRed) | Specifies the red intensity. |
rgbReserved (no PM equivalent) | Not used. Must be set to 0. |
An application can use the biSize (bcSize) field of the BITMAPINFOHEADER (BITMAPCOREHEADER) structure to locate the color table. Each of the following statements assigns the pColor variable the byte offset of the color table from the beginning of the file:
// Windows 3.0 DIB
pColor = (LPSTR)pBitmapInfo + (WORD)pBitmapInfo->biSize
// Presentation Manager 1.2 DIB
pColor = (LPSTR)pBitmapCoreInfo + (WORD)pBitmapCoreInfo->bcSize
The biBitCount (bcBitCount) field of the BITMAPINFOHEADER (BITMAPCOREHEADER) structure determines the number of bits which define each pixel and the maximum number of colors in the bitmap. Its value affects the interpretation of the color table.
The biBitCount (bcBitCount) field can have any of the following values:
Value | Meaning |
1 | The bitmap is monochrome, and the color table contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, the pixel is displayed with the color of the first entry in the color table. If the bit is set, the pixel has the color of the second entry in the table. |
4 | The bitmap has a maximum of 16 colors. Each pixel in the bitmap is represented by a four-bit index into the color table. |
For example, if the first byte in the bitmap is 0x1F, then the byte represents two pixels. The first pixel contains the color in the second table entry, and the second pixel contains the color in the 16th table entry. | |
8 | The bitmap has a maximum of 256 colors. Each pixel in the bitmap is represented by a byte-sized index into the color table. For example, if the first byte in the bitmap is 0x1F, then the first pixel has the color of the thirty-second table entry. |
24 | The bitmap has a maximum of 224 colors. The bmiColors (bmciColors) field is NULL, and each three bytes in the bitmap array represent the relative intensities of red, green, and blue, respectively, of a pixel. |
For Windows 3.0 DIBs, the biClrUsed field of the BITMAPINFOHEADER structure specifies the number of color indexes in the color table actually used by the bitmap. If the biClrUsed field is set to 0, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount field.