Skip to content

Commit fb9ae3f

Browse files
committed
Support HSL in Colorizer
1 parent 42bc7b8 commit fb9ae3f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

image/color.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type Colorizer struct {
1414
G16 bool
1515
}
1616

17+
// HSLLerp controls if color.HSLLerp is used in place of color.RGBALerp in the [Colorizer].
18+
var HSLLerp = false
19+
1720
type cstop struct {
1821
s int
1922
c color.RGBA
@@ -77,7 +80,13 @@ func NewColorizer(img Image, c1, c2 color.Color, stops []int, colors []color.Col
7780
} else {
7881
ds := i - csl[ci].s
7982
t := float64(ds) / float64(ls)
80-
lut[i] = color.ColorRGBALerp(t, csl[ci].c, csl[ci+1].c)
83+
if HSLLerp {
84+
h := color.ColorHSLLerp(t, csl[ci].c, csl[ci+1].c)
85+
c, _ = color.RGBAModel.Convert(h).(color.RGBA)
86+
lut[i] = c
87+
} else {
88+
lut[i] = color.ColorRGBALerp(t, csl[ci].c, csl[ci+1].c)
89+
}
8190
}
8291
if i != 255 && i+1 == csl[ci+1].s {
8392
ci++

0 commit comments

Comments
 (0)