28 lines
1.2 KiB
Go
28 lines
1.2 KiB
Go
package helper
|
|
|
|
func LRGBtoXYZ(r, g, b float64) (_, _, _ float64) {
|
|
// https://en.wikipedia.org/wiki/SRGB#Correspondence_to_CIE_XYZ_stimulus
|
|
//
|
|
// Wikipedia lists this matrix for converting from linear sRGB to D65 CIE XYZ, so
|
|
// I'm considering it canonical:
|
|
//
|
|
// [+0.4124, +0.3576, +0.1805]
|
|
// [+0.2126, +0.7152, +0.0722]
|
|
// [+0.0193, +0.1192, +0.9505]
|
|
//
|
|
// The inverse:
|
|
// [+3.2406254773200531456132481428905, -1.5372079722103185962799221761846, -0.49862859869824785916021137156360 ]
|
|
// [-0.96893071472931930204316125127115, +1.8757560608852411526964057125165, +0.041517523842953942971183706902422]
|
|
// [+0.055710120445510610303218445022341, -0.20402105059848668752573283843409, +1.0569959422543882942447416955375 ]
|
|
|
|
return 0.4124*r + 0.3576*g + 0.1805*b,
|
|
0.2126*r + 0.7152*g + 0.0722*b,
|
|
0.0193*r + 0.1192*g + 0.9505*b
|
|
}
|
|
|
|
func XYZtoLRGB(x, y, z float64) (_, _, _ float64) {
|
|
return 3.2406254773200531456132481428905*x - 1.5372079722103185962799221761846*y - 0.49862859869824785916021137156360*z,
|
|
-0.96893071472931930204316125127115*x + 1.8757560608852411526964057125165*y + 0.041517523842953942971183706902422*z,
|
|
0.055710120445510610303218445022341*x - 0.20402105059848668752573283843409*y + 1.0569959422543882942447416955375*z
|
|
}
|