version 2.8
Colors

Detailed Description

Sub-Module for color handling.

Color system masks

For pixel formats we do some assignment of codes to enable format auto-calculation. (Undocumented). 0x2RGB TRUECOLOR RGB format, R = red bits, G = green bits, B = blue bits 0x3RGB TRUECOLOR BGR format, R = red bits, G = green bits, B = blue bits 0x40XX GRAYSCALE XX = bits 0x60XX PALLETTE XX = bits 0x8XXX CUSTOM format.

#define GDISP_COLORSYSTEM_MASK   0xF000
 
#define GDISP_COLORSYSTEM_RGB   0x2000
 
#define GDISP_COLORSYSTEM_BGR   0x3000
 

Color Type Constants

#define GDISP_COLORSYSTEM_TRUECOLOR   0x2000
 
#define GDISP_COLORSYSTEM_GRAYSCALE   0x4000
 
#define GDISP_COLORSYSTEM_PALETTE   0x6000
 

Pixel Format Constants

#define GDISP_PIXELFORMAT_MONO   (GDISP_COLORSYSTEM_GRAYSCALE|0x0001)
 
#define GDISP_PIXELFORMAT_GRAY4   (GDISP_COLORSYSTEM_GRAYSCALE|0x0002)
 
#define GDISP_PIXELFORMAT_GRAY16   (GDISP_COLORSYSTEM_GRAYSCALE|0x0004)
 
#define GDISP_PIXELFORMAT_GRAY256   (GDISP_COLORSYSTEM_GRAYSCALE|0x0008)
 
#define GDISP_PIXELFORMAT_RGB565   (GDISP_COLORSYSTEM_RGB|0x0565)
 
#define GDISP_PIXELFORMAT_BGR565   (GDISP_COLORSYSTEM_BGR|0x0565)
 
#define GDISP_PIXELFORMAT_RGB555   (GDISP_COLORSYSTEM_RGB|0x0555)
 
#define GDISP_PIXELFORMAT_BGR555   (GDISP_COLORSYSTEM_BGR|0x0555)
 
#define GDISP_PIXELFORMAT_RGB888   (GDISP_COLORSYSTEM_RGB|0x0888)
 
#define GDISP_PIXELFORMAT_BGR888   (GDISP_COLORSYSTEM_BGR|0x0888)
 
#define GDISP_PIXELFORMAT_RGB444   (GDISP_COLORSYSTEM_RGB|0x0444)
 
#define GDISP_PIXELFORMAT_BGR444   (GDISP_COLORSYSTEM_BGR|0x0444)
 
#define GDISP_PIXELFORMAT_RGB332   (GDISP_COLORSYSTEM_RGB|0x0332)
 
#define GDISP_PIXELFORMAT_BGR332   (GDISP_COLORSYSTEM_BGR|0x0233)
 
#define GDISP_PIXELFORMAT_RGB233   (GDISP_COLORSYSTEM_RGB|0x0233)
 
#define GDISP_PIXELFORMAT_BGR233   (GDISP_COLORSYSTEM_BGR|0x0332)
 
#define GDISP_PIXELFORMAT_RGB666   (GDISP_COLORSYSTEM_RGB|0x0666)
 
#define GDISP_PIXELFORMAT_BGR666   (GDISP_COLORSYSTEM_BGR|0x0666)
 
#define GDISP_PIXELFORMAT_ERROR   0x0000
 

Some basic colors

#define White   HTML2COLOR(0xFFFFFF)
 
#define Black   HTML2COLOR(0x000000)
 
#define Gray   HTML2COLOR(0x808080)
 
#define Grey   Gray
 
#define Blue   HTML2COLOR(0x0000FF)
 
#define Red   HTML2COLOR(0xFF0000)
 
#define Fuchsia   HTML2COLOR(0xFF00FF)
 
#define Magenta   Fuchsia
 
#define Green   HTML2COLOR(0x008000)
 
#define Yellow   HTML2COLOR(0xFFFF00)
 
#define Aqua   HTML2COLOR(0x00FFFF)
 
#define Cyan   Aqua
 
#define Lime   HTML2COLOR(0x00FF00)
 
#define Maroon   HTML2COLOR(0x800000)
 
#define Navy   HTML2COLOR(0x000080)
 
#define Olive   HTML2COLOR(0x808000)
 
#define Purple   HTML2COLOR(0x800080)
 
#define Silver   HTML2COLOR(0xC0C0C0)
 
#define Teal   HTML2COLOR(0x008080)
 
#define Orange   HTML2COLOR(0xFFA500)
 
#define Pink   HTML2COLOR(0xFFC0CB)
 
#define SkyBlue   HTML2COLOR(0x87CEEB)
 

Color bits

The number of bits for each of red, green and blue

#define COLOR_BITS_R   5
 
#define COLOR_BITS_G   6
 
#define COLOR_BITS_B   5
 

Color bit shifts

The number of bits to shift each of red, green and blue to put it in the correct place in the color

#define COLOR_SHIFT_R   11
 
#define COLOR_SHIFT_G   5
 
#define COLOR_SHIFT_B   0
 

Extraction macros (quick)

Extract the luma/red/green/blue component (0 to 255) of a color value.

Note
This uses quick and dirty bit shifting. If you want more exact colors use EXACT_RED_OF() etc which uses multiplies and divides. For constant colors using EXACT_RED_OF() is no more expensive because the compiler evaluates the arithmetic.
LUMA_OF() returns a roughly weighted luminance (0.25R + 0.5G + 0.25B). Note this is different to LUMA2COLOR() which uses a linear conversion (0.33R + 0.33G + 0.33B) and color tv luminance of (0.26126R + 0.7152G + 0.0722B) and digital tv luminance of (0.299R + 0.587G + 0.114B).
A 5 bit color component maximum value (0x1F) converts to 0xF8 (slightly off-color)
#define LUMA_OF(c)   ((RED_OF(c)+((uint16_t)GREEN_OF(c)<<1)+BLUE_OF(c))>>2)
 
#define RED_OF(c)   (((c) & 0xF800)>>8)
 
#define GREEN_OF(c)   (((c)&0x007E)>>3)
 
#define BLUE_OF(c)   (((c)&0x001F)<<3)
 

Extraction macros (precise)

Extract the exact luma/red/green/blue component (0 to 255) of a color value.

Note
This uses multiplies and divides rather than bit shifting. This gives exact equivalent colors at the expense of more cpu intensive operations. Note for constants this is no more expensive than REF_OF() because the compiler evaluates the arithmetic.
EXACT_LUMA_OF() returns a roughly weighted luminance (0.25R + 0.5G + 0.25B). Note this is different to LUMA2COLOR() which uses a linear conversion (0.33R + 0.33G + 0.33B) and color tv luminance of (0.26126R + 0.7152G + 0.0722B) and digital tv luminance of (0.299R + 0.587G + 0.114B).
A 5 bit color component maximum value (0x1F) converts to 0xFF (the true equivalent color)
#define EXACT_LUMA_OF(c)   ((EXACT_RED_OF(c)+((uint16_t)EXACT_GREEN_OF(c)<<1)+EXACT_BLUE_OF(c))>>2)
 
#define EXACT_RED_OF(c)   (((((c)>>11)&0x1F)*255)/31)
 
#define EXACT_GREEN_OF(c)   (((((c)>>5)&0x3F)*255)/63)
 
#define EXACT_BLUE_OF(c)   (((((c)>>0)&0x1F)*255)/31)
 

Macros

#define COLOR_SYSTEM   GDISP_COLORSYSTEM_TRUECOLOR
 The color system (grayscale, palette or truecolor) More...
 
#define COLOR_BITS   16
 The number of bits in a color value. More...
 
#define COLOR_NEEDS_MASK   FALSE
 Does the color need masking to remove invalid bits. More...
 
#define COLOR_MASK   0xFFFF
 If the color needs masking to remove invalid bits, this is the mask. More...
 
#define COLOR_TYPE   uint16_t
 The color type. More...
 
#define COLOR_TYPE_BITS   16
 The number of bits in the color type (not necessarily the same as COLOR_BITS). More...
 
#define LUMA2COLOR(l)   ((color_t)((((l) & 0xF8)<<8) | (((l) & 0xFC)<<3) | (((l) & 0xF8)>>3)))
 Convert a luminance (0 to 255) into a color value. More...
 
#define RGB2COLOR(r, g, b)   ((color_t)((((r) & 0xF8)<<8) | (((g) & 0xFC)<<3) | (((b) & 0xF8)>>3)))
 Convert red, green, blue (each 0 to 255) into a color value. More...
 
#define HTML2COLOR(h)   ((color_t)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))
 Convert a 6 digit HTML code (hex) into a color value. More...
 

Typedefs

typedef COLOR_TYPE color_t
 The color type definition. More...
 

Macro Definition Documentation

#define COLOR_BITS   16

The number of bits in a color value.

Definition at line 116 of file gdisp_colors.h.

#define COLOR_MASK   0xFFFF

If the color needs masking to remove invalid bits, this is the mask.

Definition at line 146 of file gdisp_colors.h.

#define COLOR_NEEDS_MASK   FALSE

Does the color need masking to remove invalid bits.

Definition at line 141 of file gdisp_colors.h.

#define COLOR_SYSTEM   GDISP_COLORSYSTEM_TRUECOLOR

The color system (grayscale, palette or truecolor)

Definition at line 111 of file gdisp_colors.h.

#define COLOR_TYPE   uint16_t

The color type.

Definition at line 151 of file gdisp_colors.h.

#define COLOR_TYPE_BITS   16

The number of bits in the color type (not necessarily the same as COLOR_BITS).

Definition at line 156 of file gdisp_colors.h.

#define HTML2COLOR (   h)    ((color_t)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))

Convert a 6 digit HTML code (hex) into a color value.

Definition at line 176 of file gdisp_colors.h.

#define LUMA2COLOR (   l)    ((color_t)((((l) & 0xF8)<<8) | (((l) & 0xFC)<<3) | (((l) & 0xF8)>>3)))

Convert a luminance (0 to 255) into a color value.

Note
The word "Luma" is used instead of grey or gray due to the spelling ambiguities of the word grey
This is not a weighted luminance conversion in the color tv style.
LUMA2COLOR() uses a linear conversion (0.33R + 0.33G + 0.33B). Note this is different to color tv luminance (0.26126R + 0.7152G + 0.0722B), digital tv luminance of (0.299R + 0.587G + 0.114B), or LUMA_OF() which uses (0.25R + 0.5G + 0.25B).

Definition at line 166 of file gdisp_colors.h.

#define RGB2COLOR (   r,
  g,
 
)    ((color_t)((((r) & 0xF8)<<8) | (((g) & 0xFC)<<3) | (((b) & 0xF8)>>3)))

Convert red, green, blue (each 0 to 255) into a color value.

Definition at line 171 of file gdisp_colors.h.

Typedef Documentation

The color type definition.

Definition at line 412 of file gdisp_colors.h.