HSV uses Premultiply and Unpremultiply functions

This commit is contained in:
Sasha Koshka 2024-09-10 17:42:45 -04:00
parent 2b1f5d5c65
commit 9655da5841

View File

@ -67,12 +67,7 @@ func (hsva HSVA) RGBA () (r, g, b, a uint32) {
S: hsva.S, S: hsva.S,
V: hsva.V, V: hsva.V,
}.RGBA() }.RGBA()
a = uint32(hsva.A) return Premultiply(r, g, b, uint32(hsva.A))
// alpha premultiplication
r = (r * a) / 0xFFFF
g = (g * a) / 0xFFFF
b = (b * a) / 0xFFFF
return
} }
// Canon returns the color but with the H, S, and V fields are constrained to // Canon returns the color but with the H, S, and V fields are constrained to
@ -104,11 +99,7 @@ func hsvModel (c color.Color) color.Color {
case HSV: return c case HSV: return c
case HSVA: return HSV { H: c.H, S: c.S, V: c.V } case HSVA: return HSV { H: c.H, S: c.S, V: c.V }
default: default:
r, g, b, a := c.RGBA() r, g, b, _ := Unpremultiply(c.RGBA())
// alpha unpremultiplication
r = (r / a) * 0xFFFF
g = (g / a) * 0xFFFF
b = (b / a) * 0xFFFF
return rgbToHSV(r, g, b) return rgbToHSV(r, g, b)
} }
} }