More accurate 8-bit <=> 5-bit RGB color conversion (#1827)

This commit is contained in:
Rangi
2025-09-08 15:13:25 -04:00
committed by GitHub
parent 65d408eb5d
commit 223b3d1921
20 changed files with 31 additions and 15 deletions

View File

@@ -18,10 +18,7 @@ struct Rgba {
: red(rgba >> 24), green(rgba >> 16), blue(rgba >> 8), alpha(rgba) {}
static constexpr Rgba fromCGBColor(uint16_t color) {
constexpr auto _5to8 = [](uint8_t channel) -> uint8_t {
channel &= 0b11111; // For caller's convenience
return channel << 3 | channel >> 2;
};
constexpr auto _5to8 = [](uint8_t c) -> uint8_t { return ((c & 0b11111) * 255 + 15) / 31; };
return {
_5to8(color),
_5to8(color >> 5),