CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches

The 16 colours the framebuffer's indices stand for, and a fade applied on top of them. More...

Functions

void gfx_setPalette (const uint16_t *rgb565, uint8_t count)
 Sets the first count palette entries.
 
void gfx_setPaletteEntry (uint8_t index, uint16_t rgb565)
 Sets one palette entry.
 
void gfx_setFade (uint8_t amount, uint16_t rgb565=0x0000)
 Fades every colour toward one colour (black by default).
 
uint8_t gfx_fade (void)
 The current fade amount.
 
uint16_t gfx_paletteOut (uint8_t index)
 The colour a palette index actually reaches the panel as, fade included.
 
static uint16_t gfx_rgb (uint8_t r, uint8_t g, uint8_t b)
 Packs an 8-bit-per-channel colour into RGB565.
 
uint8_t gfx_nearest (uint16_t rgb565)
 Nearest palette index for a full RGB565 colour.
 

Variables

uint16_t gfx_pal [16]
 The 16 palette colours as set, in RGB565.
 

Detailed Description

The 16 colours the framebuffer's indices stand for, and a fade applied on top of them.

Palette changes are STAGED: they take effect when the next flush starts, never part-way through one in flight, so these are safe to call at any time - including between gfx_flushAsync() and gfx_wait(). Every frame is re-sent through the palette, so animating it (cycling a slot, pulsing a highlight, a fade) costs a 256-entry table rebuild per frame and no drawing at all.

Function Documentation

◆ gfx_setPalette()

void gfx_setPalette ( const uint16_t *  rgb565,
uint8_t  count 
)

Sets the first count palette entries.

Parameters
rgb565The colours, in RGB565 (see gfx_rgb()). Passing gfx_pal itself just re-stages the palette.
countHow many entries to set, from index 0; at most 16 are used.

◆ gfx_setPaletteEntry()

void gfx_setPaletteEntry ( uint8_t  index,
uint16_t  rgb565 
)

Sets one palette entry.

Parameters
indexPalette index, 0..15 (only the low 4 bits are used).
rgb565The colour, in RGB565.

◆ gfx_setFade()

void gfx_setFade ( uint8_t  amount,
uint16_t  rgb565 = 0x0000 
)

Fades every colour toward one colour (black by default).

Applied while the expansion table is built, so gfx_pal[] keeps the true colours and gfx_nearest() still matches against them. Staged like the palette.

Parameters
amount0 = the palette as set, 255 = solid rgb565.
rgb565The colour faded toward, in RGB565 (default black).

◆ gfx_fade()

uint8_t gfx_fade ( void  )

The current fade amount.

Returns
0 (no fade) to 255 (every colour is the fade colour).

◆ gfx_paletteOut()

uint16_t gfx_paletteOut ( uint8_t  index)

The colour a palette index actually reaches the panel as, fade included.

Parameters
indexPalette index, 0..15.
Returns
The colour in RGB565.

◆ gfx_rgb()

static uint16_t gfx_rgb ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inlinestatic

Packs an 8-bit-per-channel colour into RGB565.

Parameters
rRed, 0..255 (the top 5 bits are kept).
gGreen, 0..255 (the top 6 bits are kept).
bBlue, 0..255 (the top 5 bits are kept).
Returns
The colour in RGB565, for gfx_setPalette() and the like.

◆ gfx_nearest()

uint8_t gfx_nearest ( uint16_t  rgb565)

Nearest palette index for a full RGB565 colour.

Linear search over 16 entries, by weighted distance, against the palette as set (not as faded) - fine at setup time to build named constants, far too slow to call per pixel.

Parameters
rgb565The colour, in RGB565.
Returns
The palette index, 0..15, closest to it.

Variable Documentation

◆ gfx_pal

uint16_t gfx_pal[16]
extern

The 16 palette colours as set, in RGB565.

Read it freely; change it with gfx_setPalette() or gfx_setPaletteEntry(), which stage the change for the next flush. The fade (gfx_setFade()) is not applied here: gfx_paletteOut() gives the colour the panel actually receives.