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

@@ -50,9 +50,10 @@ uint16_t Rgba::cgbColor() const {
g = reverse_curve[g];
b = reverse_curve[b];
} else {
r >>= 3;
g >>= 3;
b >>= 3;
constexpr auto _8to5 = [](uint8_t c) -> uint8_t { return (c * 31 + 127) / 255; };
r = _8to5(r);
g = _8to5(g);
b = _8to5(b);
}
return r | g << 5 | b << 10;
}