1
0
Fork 0
mirror of https://github.com/imjasonh/dots synced 2026-07-07 00:22:55 +00:00

fix eee bug

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2025-11-14 16:25:47 -05:00
parent 40cc74ad03
commit 67dc0ccf40
2 changed files with 18 additions and 3 deletions

View file

@ -93,6 +93,18 @@ func TestParseHex(t *testing.T) {
wantANSI: 244, // Gray in ANSI 256 grayscale ramp
wantErr: false,
},
{
desc: "near-white (eee)",
hex: "eee",
wantANSI: 231, // Should map to white, not black
wantErr: false,
},
{
desc: "near-white (eeeeee)",
hex: "eeeeee",
wantANSI: 231, // Should map to white, not black
wantErr: false,
},
{
desc: "invalid length (too short)",
hex: "ff",

View file

@ -35,12 +35,15 @@ func quantizeGrayscale(r, g, b uint8) uint8 {
if avg < 8 {
return 16 // Black from RGB cube
}
if avg > 238 {
if avg >= 238 {
return 231 // White from RGB cube
}
// Map [8, 238] to [0, 23]
step := (avg - 8) * 24 / 230
// Map [8, 237] to [0, 23]
step := (avg - 8) * 24 / 229
if step > 23 {
step = 23
}
return 232 + uint8(step)
}