28 lines
554 B
Go
28 lines
554 B
Go
|
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
|
||
|
}
|