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:
parent
40cc74ad03
commit
67dc0ccf40
2 changed files with 18 additions and 3 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue