16-Bit Color Values

The Color iLCD controller supports commands for setting colors such as background color or foreground color. Although the Color iLCD controller internally works with 16-bit color values, all commands except the read and write scan line commands use 24-bit color values (see at 24-Bit Color Values) to allow future expansions. The read and write scan line commands use the 16-bit color values only to minimize the amount of data to be read and written, as one 320x240 color pixel screen needs 320*240*2 = 153,600 bytes to be read/written even in 16-bit color format.

In the chapter Command Description, 16-bit color values are always described as type "color_16bit" in the corresponding parameter tables.

The bit assignment of the 16-bit color values is R5G6B5, which make up one 16-bit word as follows:

RRRRRGGGGGGBBBBB (most significant bit is leftmost)

The formula (C-notation) to get a 16-bit color value from the red/green/blue parts is as follows:

color_16_bit = (red << 11) + (green << 5) + blue

where red and blue has a range of 0…31 and green has a range of 0…63, the maximum value for red/green/blue refers to 100% color intensity. Shifting red left by 11, shifting green left by 5 and adding the shifted red and green value and blue together delivers the 16-bit color value.

Some color values shown in binary and hex representation explain the color values further:

Color Red (Dec. /%) Green (Dec. /%) Blue (Dec. /%) Binary Value Hex Value
Pure red 31 / 100% 0 / 0% 0 / 0% 1111100000000000 F800
Pure green 0 / 0% 63 / 100% 0 / 0% 0000011111100000 07E0
Pure blue 0 / 0% 0 / 0% 31 / 100% 0000000000011111 001F
Black 0 / 0% 0 / 0% 0 / 0% 0000000000000000 0000
White 31 / 100% 63 / 100% 31 / 100% 1111111111111111 FFFF
Yellow 31 / 100% 63 / 100% 0 / 0% 1111111111100000 FFE0
Magenta 31 / 100% 0 / 0% 31 / 100% 1111100000011111 F81F
Cyan 0 / 0% 63 / 100% 31 / 100% 0000011111111111 07FF

In the following description of these commands, the parameters of a 16-bit color value are always written as xxx_hb and xxx_lb where xxx describes the 16-bit color parameter.

This is the command for writing a (partial) scan line with no_of_pixels length made up of pixels p1, p2, etc. An example showing the hex parameters for setting a red, a green and a blue pixel starting from the current cursor position is as follows:

Syntax in iLCD Manager XE:

\iDNW\D3\XF8\XE007\X1F00
\iDNW\d0\d3\x0\xF8\xE0\x7\x1F\x0

All above notations represent the same value (set 3 pixels: red, green, blue). Note, that only for 16-bit color values, the 2 bytes are sent low byte first. Refer to Syntax used in iLCD Manager XE for further information about these introducters.

The actual bytes sent via the interface can be verified in the "Hex" part of any editor panel. The sequence for the above example would look like:

[AA][44][4E][57][00][03][00][F8][E0][07][1F][00]