Skip to content

Commit 569fe6e

Browse files
committed
RGB565: Add html-style color constructor
1 parent 44bdc87 commit 569fe6e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

util/colors_rgb565.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ struct RGB565 {
1919
, b(std::clamp<uint16_t>(blue * 32.f, 0, 31)) {
2020
}
2121

22+
constexpr RGB565(uint32_t raw)
23+
: r((raw & 0xf80000) >> 19)
24+
, g((raw & 0x00fc00) >> 10)
25+
, b((raw & 0x0000f8) >> 3) {
26+
}
27+
2228
constexpr uint16_t raw() const {
2329
return (r << 11) | (g << 5) | b;
2430
}
@@ -70,3 +76,5 @@ static_assert(RGB565{(uint8_t)0xFF, 0xFF, 0x55}.blue() == (0x55 & 0xF8));
7076
static_assert(RGB565{(uint8_t)0xFF, 0xFF, 0xFF}.raw() == 0xFFFF);
7177
static_assert(RGB565{(uint8_t)0x80, 0x80, 0x80}.raw() == 0x8410);
7278
static_assert(RGB565{(uint8_t)0x00, 0x00, 0x00}.raw() == 0x0000);
79+
80+
static_assert(RGB565(0xFFAA22) == RGB565((uint8_t)0xFF, 0xAA, 0x22));

0 commit comments

Comments
 (0)