RGB Color Encoding

The red, green, and blue (RGB) components of a color are stored in either an RGB or RGB2 data structure, or as a long integer (32-bit) value. The color fields in the RGB2 structure and in the long integer follow the same rules.

If stored as a long integer, the RGB value has the first 8 bits reserved for a flag value and the remaining 24 bits reserved for color intensity. The flag byte must be set to 0. Each of the last three bytes specifies a color intensity, in the range 0 through 255, for a single primary color.

If a byte contains 0, the corresponding primary color is not present. As the value in the byte increases, the intensity of the primary color increases. For example, if the byte contains 128, the primary color is pale; if the byte contains 255, the primary color is as intense as the device permits.

The RGB value is determined by the following equation:

    RGB Value = (R * 65536) + (G * 256) + B

    Where:
        R is the red intensity
        G is the green intensity
        B is the blue intensity

If all three bytes are set to 0, the resulting color is black; if they all are set to 255, the resulting color is white. The RGB value associated with each of the standard eight colors is in the following table.

┌────────────────────┬────────────────────┐
│Color               │RGB value           │
├────────────────────┼────────────────────┤
│Black               │0x00000000          │
├────────────────────┼────────────────────┤
│Red                 │0x00FF0000          │
├────────────────────┼────────────────────┤
│Green               │0x0000FF00          │
├────────────────────┼────────────────────┤
│Blue                │0x000000FF          │
├────────────────────┼────────────────────┤
│Pink                │0x00FF00FF          │
├────────────────────┼────────────────────┤
│Cyan                │0x0000FFFF          │
├────────────────────┼────────────────────┤
│Yellow              │0x00FFFF00          │
├────────────────────┼────────────────────┤
│White               │0x00FFFFFF          │
└────────────────────┴────────────────────┘


[Back: Color Implementation]
[Next: Color Tables]