Separate HSVA color into HSV, HSVA, fix alpha premultiplication

This commit is contained in:
Sasha Koshka 2024-08-15 16:41:22 -04:00
parent b3e7178176
commit 2546c338ad

View File

@ -1,13 +1,31 @@
package internal package internal
import "image/color"
// HSV represents a color with hue, saturation, and value components. Each
// component C is in range 0 <= C <= 1.
type HSV struct {
H float64
S float64
V float64
}
// HSVA is an HSV color with an added 8-bit alpha component. The alpha component
// ranges from 0x0000 (fully transparent) to 0xFFFF (opaque), and has no bearing
// on the other components.
type HSVA struct { type HSVA struct {
H float64 H float64
S float64 S float64
V float64 V float64
A uint8 A uint16
} }
func (hsva HSVA) RGBA () (r, g, b, a uint32) { var (
HSVModel color.Model = color.ModelFunc(hsvModel)
HSVAModel color.Model = color.ModelFunc(hsvaModel)
)
func (hsv HSV) RGBA () (r, g, b, a uint32) {
// Adapted from: // Adapted from:
// https://www.cs.rit.edu/~ncs/color/t_convert.html // https://www.cs.rit.edu/~ncs/color/t_convert.html