Skip to content

Commit

Permalink
Use Luv colorspace for color profile conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jun 24, 2021
1 parent cb996cd commit 615a2b5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func ansi256ToANSIColor(c ANSI256Color) ANSIColor {
h, _ := colorful.Hex(ansiHex[c])
for i := 0; i <= 15; i++ {
hb, _ := colorful.Hex(ansiHex[i])
d := h.DistanceLab(hb)
d := h.DistanceLuv(hb)

if d < md {
md = d
Expand Down Expand Up @@ -235,8 +235,8 @@ func hexToANSI256Color(c colorful.Color) ANSI256Color {
// Return the one which is nearer to the original input rgb value
c2 := colorful.Color{R: float64(cr) / 255.0, G: float64(cg) / 255.0, B: float64(cb) / 255.0}
g2 := colorful.Color{R: float64(gv) / 255.0, G: float64(gv) / 255.0, B: float64(gv) / 255.0}
colorDist := c.DistanceLab(c2)
grayDist := c.DistanceLab(g2)
colorDist := c.DistanceLuv(c2)
grayDist := c.DistanceLuv(g2)

if colorDist <= grayDist {
return ANSI256Color(16 + ci)
Expand Down

0 comments on commit 615a2b5

Please sign in to comment.