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

@@ -144,7 +144,7 @@ static void generate_palettes(uint16_t palettes[/* 60 */][4]) {
* Expand a 5-bit color component to 8 bits with minimal bias
*/
static uint8_t _5to8(uint8_t five) {
return five << 3 | five >> 2;
return (five * 255 + 15) / 31;
}
// Can't mark as `const`, as the array type is otherwise not compatible (augh)