TinyGPU
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
RGB565 Class Reference

RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout. More...

#include <RGB565.h>

Public Member Functions

 RGB565 ()=default
 Creates a black RGB565 color.
 
 RGB565 (uint8_t r, uint8_t g, uint8_t b)
 Creates a color from 8-bit red, green, and blue components.
 
 RGB565 (uint16_t packed)
 
void setValue (uint8_t r, uint8_t g, uint8_t b)
 Sets the color from 8-bit red, green, and blue components.
 
void setValue (uint16_t packed)
 
uint8_t getRed () const
 Returns the red component expanded to 8 bits.
 
uint8_t getGreen () const
 Returns the green component expanded to 8 bits.
 
uint8_t getBlue () const
 Returns the blue component expanded to 8 bits.
 
uint16_t getValue () const
 
uint16_t getValueSwapped () const
 

Static Public Member Functions

static RGB565 fromRGB (uint8_t r, uint8_t g, uint8_t b)
 
static uint16_t swapBytes (uint16_t v)
 
static uint8_t size ()
 Returns size in bits.
 

Protected Attributes

uint16_t value = 0
 

Detailed Description

RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.

The class provides conversion between 8-bit per channel RGB values and the packed 16-bit representation commonly used by embedded displays.

Storage note: value holds the two bytes of the conventional RGB565 packing (R:5 G:6 B:5, red in the high bits) swapped - i.e. exactly the byte order every SPI/QSPI panel driver in this codebase (DisplayDriverSPI, DisplayDriverQSPI) needs on the wire. That's the overwhelmingly common consumer, so getValue()/writeData() need no per-pixel swap. Anything that instead needs the conventional (native) bit layout - LVGL's own pixel buffer, SDL's SDL_PIXELFORMAT_RGB565 texture upload, or a file format like AVI/BMP that declares standard RGB565 bitmasks - must go through getValueSwapped() (or construct via the swapped packed value) to undo it.

Constructor & Destructor Documentation

◆ RGB565() [1/3]

RGB565 ( )
default

Creates a black RGB565 color.

◆ RGB565() [2/3]

RGB565 ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inline

Creates a color from 8-bit red, green, and blue components.

◆ RGB565() [3/3]

RGB565 ( uint16_t  packed)
inlineexplicit

Creates a color from a packed value already in this class's stored (byte-swapped) order - i.e. one that round-trips through getValue(). To decode a packed value in the conventional (native) bit layout instead - e.g. a raw pixel from LVGL's own buffer - byte-swap it first: RGB565(swapBytes(nativePacked)).

Member Function Documentation

◆ fromRGB()

static RGB565 fromRGB ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inlinestatic

Creates a color from semantic red/green/blue intensities, regardless of this class's own constructor argument order. Prefer this in generic code that converts between pixel formats.

◆ getBlue()

uint8_t getBlue ( ) const
inline

Returns the blue component expanded to 8 bits.

◆ getGreen()

uint8_t getGreen ( ) const
inline

Returns the green component expanded to 8 bits.

◆ getRed()

uint8_t getRed ( ) const
inline

Returns the red component expanded to 8 bits.

◆ getValue()

uint16_t getValue ( ) const
inline

Returns the packed value in this class's stored (byte-swapped) order - i.e. wire-ready for DisplayDriverSPI/DisplayDriverQSPI with no further swap needed.

◆ getValueSwapped()

uint16_t getValueSwapped ( ) const
inline

Returns the packed value in the conventional (native) RGB565 bit layout (R:5 G:6 B:5, red in the high bits) - the order LVGL, SDL, and standard RGB565 file-format bitmasks (e.g. AVI/BMP) expect.

◆ setValue() [1/2]

void setValue ( uint16_t  packed)
inline

Sets the color from a packed value already in this class's stored (byte-swapped) order - see the constructor note above.

◆ setValue() [2/2]

void setValue ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inline

Sets the color from 8-bit red, green, and blue components.

◆ size()

static uint8_t size ( )
inlinestatic

Returns size in bits.

◆ swapBytes()

static uint16_t swapBytes ( uint16_t  v)
inlinestatic

Byte-swaps a 16-bit value; used to convert between this class's stored (wire) order and the conventional (native) RGB565 bit layout.

Member Data Documentation

◆ value

uint16_t value = 0
protected

The documentation for this class was generated from the following file: