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 readScanLine(int, short[]) and writeScanLine(int, short[]) 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 ilcd package 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:
RRRR RGGG GGGB BBBB (most significant bit is leftmost)
The pseudo formula 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 noOfPixels 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 - Java:
short red = 0x00; //ranging from 0x00 to 0x1F
short green = 0x3F; //ranging from 0x00 to 0x3F
short blue = 0x00; //ranging from 0x00 to 0x1F
short color_16_bit = (short)((red << 11) + (green << 5) + blue);
Copyright © demmel products gmbh. All rights reserved.