LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
lcdgfx::Color Struct Reference

24-bit RGB colour with constexpr conversions to all native lcdgfx pixel formats. More...

#include <color.h>

Public Member Functions

constexpr uint8_t r () const
 Red channel (0..255). More...
 
constexpr uint8_t g () const
 Green channel (0..255). More...
 
constexpr uint8_t b () const
 Blue channel (0..255). More...
 
constexpr uint32_t to_rgb888 () const
 Pack as 24-bit RGB888 (0x00RRGGBB). More...
 
constexpr uint16_t to_rgb565 () const
 Pack as 5-6-5 RGB565 (matches RGB_COLOR16 macro for matching inputs). More...
 
constexpr uint8_t to_rgb332 () const
 Pack as 3-3-2 RGB332 (matches RGB_COLOR8 macro for matching inputs). More...
 
constexpr uint8_t to_gray4 () const
 Pack as 4-bit luminance using the standard 0.299R + 0.587G + 0.114B weighting, rounded to 4 bits. More...
 
constexpr uint8_t to_mono () const
 Reduce to 1 bit (0 or 1). More...
 
template<unsigned Bpp>
constexpr uint32_t to_native () const
 Compile-time-selectable convert: to_native<bpp>(). More...
 
constexpr bool operator== (const Color &other) const
 
constexpr bool operator!= (const Color &other) const
 
template<>
constexpr uint32_t to_native () const
 
template<>
constexpr uint32_t to_native () const
 
template<>
constexpr uint32_t to_native () const
 
template<>
constexpr uint32_t to_native () const
 
template<>
constexpr uint32_t to_native () const
 

Static Public Member Functions

static constexpr Color from_rgb (uint8_t r, uint8_t g, uint8_t b)
 Construct from 8-bit-per-channel RGB. More...
 
static constexpr Color from_rgb888 (uint32_t v)
 Construct from a 24-bit packed value (e.g. More...
 
static constexpr Color from_rgb565 (uint16_t v)
 Construct from a 5-6-5 packed 16-bit value, expanding back to RGB888. More...
 
static constexpr Color from_rgb332 (uint8_t v)
 Construct from a 3-3-2 packed 8-bit value, expanding back to RGB888. More...
 
static constexpr Color from_gray4 (uint8_t v)
 Construct from a 4-bit luminance (0..15) — broadcasts to all channels. More...
 
static constexpr Color from_mono (uint8_t v)
 Construct from a 1-bit value (0 = black, anything else = white). More...
 

Public Attributes

uint32_t rgb
 0x00RRGGBB (R in bits 23..16, G in bits 15..8, B in bits 7..0). More...
 

Detailed Description

24-bit RGB colour with constexpr conversions to all native lcdgfx pixel formats.

See file docstring for conventions.

Definition at line 68 of file color.h.

Member Function Documentation

◆ b()

constexpr uint8_t lcdgfx::Color::b ( ) const
inline

Blue channel (0..255).

Definition at line 124 of file color.h.

◆ from_gray4()

static constexpr Color lcdgfx::Color::from_gray4 ( uint8_t  v)
inlinestatic

Construct from a 4-bit luminance (0..15) — broadcasts to all channels.

Definition at line 105 of file color.h.

◆ from_mono()

static constexpr Color lcdgfx::Color::from_mono ( uint8_t  v)
inlinestatic

Construct from a 1-bit value (0 = black, anything else = white).

Definition at line 114 of file color.h.

◆ from_rgb()

static constexpr Color lcdgfx::Color::from_rgb ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inlinestatic

Construct from 8-bit-per-channel RGB.

Components are clamped via &0xFF.

Definition at line 74 of file color.h.

◆ from_rgb332()

static constexpr Color lcdgfx::Color::from_rgb332 ( uint8_t  v)
inlinestatic

Construct from a 3-3-2 packed 8-bit value, expanding back to RGB888.

Definition at line 96 of file color.h.

◆ from_rgb565()

static constexpr Color lcdgfx::Color::from_rgb565 ( uint16_t  v)
inlinestatic

Construct from a 5-6-5 packed 16-bit value, expanding back to RGB888.

Definition at line 86 of file color.h.

◆ from_rgb888()

static constexpr Color lcdgfx::Color::from_rgb888 ( uint32_t  v)
inlinestatic

Construct from a 24-bit packed value (e.g.

0xFF8800).

Definition at line 80 of file color.h.

◆ g()

constexpr uint8_t lcdgfx::Color::g ( ) const
inline

Green channel (0..255).

Definition at line 122 of file color.h.

◆ r()

constexpr uint8_t lcdgfx::Color::r ( ) const
inline

Red channel (0..255).

Definition at line 120 of file color.h.

◆ to_gray4()

constexpr uint8_t lcdgfx::Color::to_gray4 ( ) const
inline

Pack as 4-bit luminance using the standard 0.299R + 0.587G + 0.114B weighting, rounded to 4 bits.

Definition at line 147 of file color.h.

◆ to_mono()

constexpr uint8_t lcdgfx::Color::to_mono ( ) const
inline

Reduce to 1 bit (0 or 1).

Threshold = 128 on luminance.

Definition at line 158 of file color.h.

◆ to_native()

template<unsigned Bpp>
constexpr uint32_t lcdgfx::Color::to_native ( ) const

Compile-time-selectable convert: to_native<bpp>().

Falls back to RGB888 for unrecognised depths so user code does not silently miscompile. Supported depths: 1, 4 (luminance), 8 (RGB332), 16 (RGB565), 24 (RGB888).

◆ to_rgb332()

constexpr uint8_t lcdgfx::Color::to_rgb332 ( ) const
inline

Pack as 3-3-2 RGB332 (matches RGB_COLOR8 macro for matching inputs).

Definition at line 138 of file color.h.

◆ to_rgb565()

constexpr uint16_t lcdgfx::Color::to_rgb565 ( ) const
inline

Pack as 5-6-5 RGB565 (matches RGB_COLOR16 macro for matching inputs).

Definition at line 130 of file color.h.

◆ to_rgb888()

constexpr uint32_t lcdgfx::Color::to_rgb888 ( ) const
inline

Pack as 24-bit RGB888 (0x00RRGGBB).

Definition at line 127 of file color.h.

Member Data Documentation

◆ rgb

uint32_t lcdgfx::Color::rgb

0x00RRGGBB (R in bits 23..16, G in bits 15..8, B in bits 7..0).

Definition at line 71 of file color.h.


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