mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +00:00
internal/f32color: add colorspace-correct function for alpha scaling
Package material's ad-hoc mulAlpha didn't take the sRGB color-space into account, which meant that alpha-scaled colors were subtly wrong. Introduce f32color.MulAlpha and convert all uses to it. Thanks to René Post for finding and debugging the issue. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -73,3 +73,15 @@ func sRGBToLinear(c float32) float32 {
|
||||
return float32(math.Pow(float64((c+0.055)/1.055), 2.4))
|
||||
}
|
||||
}
|
||||
|
||||
// MulAlpha scales all color components by alpha/255.
|
||||
func MulAlpha(c color.RGBA, alpha uint8) color.RGBA {
|
||||
// TODO: Optimize. This is pretty slow.
|
||||
a := float32(alpha) / 255.
|
||||
rgba := RGBAFromSRGB(c)
|
||||
rgba.A *= a
|
||||
rgba.R *= a
|
||||
rgba.G *= a
|
||||
rgba.B *= a
|
||||
return rgba.SRGB()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user