Improved LCH support

This commit is contained in:
Eduard Urbach 2024-03-06 19:23:49 +01:00
parent f623fa2154
commit a8ac7e8d54
Signed by: eduard
GPG key ID: 49226B848C78F6C8
5 changed files with 173 additions and 80 deletions

27
sRGB.go Normal file
View file

@ -0,0 +1,27 @@
package color
import "math"
// inSRGB indicates whether the given color can be mapped to the sRGB color space.
func inSRGB(l Value, a Value, b Value, chroma Value) bool {
r, g, b := oklabToLinearRGB(l, a*chroma, b*chroma)
return r >= 0 && g >= 0 && b >= 0 && r <= 1 && g <= 1 && b <= 1
}
// sRGB performs gamma correction to convert linear RGB to sRGB.
// Source: IEC 61966-2-2
func sRGB(x Value) Value {
if x < 0 {
return 0
}
if x < 0.0031308 {
return 12.92 * x
}
if x < 1.0 {
return 1.055*math.Pow(x, 1/2.4) - 0.055
}
return 1.0
}