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
color.h File Reference

Unified Color helper for lcdgfx. More...

#include <stdint.h>
Include dependency graph for color.h:

Go to the source code of this file.

Classes

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

Detailed Description

Unified Color helper for lcdgfx.

Header-only, C++11-compatible. All operations are constexpr.

The helper is additive: existing RGB_COLOR8 / RGB_COLOR16 / RGB_COLOR4 / GRAY_COLOR4 macros remain the canonical fast-path for embedded targets and are not deprecated. The Color struct is intended for new code that wants:

  • One typed value that can be converted to whatever the active display expects, instead of reaching for a different macro per controller.
  • Round-trip conversions for testing / SDL emulation.
  • Compile-time evaluation of palette tables.

Conventions

  • Internal storage is 24-bit RGB888 in a uint32_t (0x00RRGGBB).
  • to_rgb565 produces the 5-6-5 layout that lcdgfx 16bpp drivers expect.
  • to_rgb332 produces the 3-3-2 layout that lcdgfx 8bpp drivers expect.
  • to_gray4 produces the 4-bit luminance value SSD1325 / SSD1327 use.
  • to_mono produces 0 or 1 using the same threshold as the legacy macros.
#include "canvas/color.h"
constexpr auto red = lcdgfx::Color::from_rgb(255, 0, 0);
constexpr auto red16 = red.to_rgb565(); // 0xF800
constexpr auto red8 = red.to_rgb332(); // 0xE0
display.setColor(red.to_rgb565());

Definition in file color.h.