µGFX  2.9
version 2.9
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 GFX_WHITE   HTML2COLOR(0xFFFFFF)
 
#define GFX_BLACK   HTML2COLOR(0x000000)
 
#define GFX_GRAY   HTML2COLOR(0x808080)
 
#define GFX_GREY   GFX_GRAY
 
#define GFX_BLUE   HTML2COLOR(0x0000FF)
 
#define GFX_RED   HTML2COLOR(0xFF0000)
 
#define GFX_FUCHSIA   HTML2COLOR(0xFF00FF)
 
#define GFX_MAGENTA   GFX_FUCHSIA
 
#define GFX_GREEN   HTML2COLOR(0x008000)
 
#define GFX_YELLOW   HTML2COLOR(0xFFFF00)
 
#define GFX_AQUA   HTML2COLOR(0x00FFFF)
 
#define GFX_CYAN   GFX_AQUA
 
#define GFX_LIME   HTML2COLOR(0x00FF00)
 
#define GFX_MAROON   HTML2COLOR(0x800000)
 
#define GFX_NAVY   HTML2COLOR(0x000080)
 
#define GFX_OLIVE   HTML2COLOR(0x808000)
 
#define GFX_PURPLE   HTML2COLOR(0x800080)
 
#define GFX_SILVER   HTML2COLOR(0xC0C0C0)
 
#define GFX_TEAL   HTML2COLOR(0x008080)
 
#define GFX_ORANGE   HTML2COLOR(0xFFA500)
 
#define GFX_PINK   HTML2COLOR(0xFFC0CB)
 
#define GFX_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)+((gU16)GREEN_OF(c)<<1)+BLUE_OF(c))>>2)
 
#define RED_OF(c)   (((c) & 0xF800)>>8)
 
#define GREEN_OF(c)   (((c)&0x07E0)>>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)+((gU16)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   GFXOFF
 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   gU16
 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)   ((gColor)((((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)   ((gColor)((((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)   ((gColor)((((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 gColor
 The color type definition. More...
 

Macro Definition Documentation

◆ COLOR_BITS

#define COLOR_BITS   16

The number of bits in a color value.

Definition at line 141 of file gdisp_colors.h.

◆ COLOR_MASK

#define COLOR_MASK   0xFFFF

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

Definition at line 171 of file gdisp_colors.h.

◆ COLOR_NEEDS_MASK

#define COLOR_NEEDS_MASK   GFXOFF

Does the color need masking to remove invalid bits.

Definition at line 166 of file gdisp_colors.h.

◆ COLOR_SYSTEM

#define COLOR_SYSTEM   GDISP_COLORSYSTEM_TRUECOLOR

The color system (grayscale, palette or truecolor)

Definition at line 136 of file gdisp_colors.h.

◆ COLOR_TYPE

#define COLOR_TYPE   gU16

The color type.

Definition at line 176 of file gdisp_colors.h.

◆ COLOR_TYPE_BITS

#define COLOR_TYPE_BITS   16

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

Definition at line 181 of file gdisp_colors.h.

◆ HTML2COLOR

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

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

Definition at line 201 of file gdisp_colors.h.

◆ LUMA2COLOR

#define LUMA2COLOR (   l)    ((gColor)((((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 191 of file gdisp_colors.h.

◆ RGB2COLOR

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

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

Definition at line 196 of file gdisp_colors.h.

Typedef Documentation

◆ gColor

typedef COLOR_TYPE gColor

The color type definition.

Definition at line 437 of file gdisp_colors.h.