lygia
/v1.1.6
/color
/space
/xyz2srgb
)Converts a XYZ color to sRGB color space.
Dependencies:
Use:
xyz2rgb(<vec3|vec4> color)
#ifndef FNC_XYZ2SRGB
#define FNC_XYZ2SRGB
vec3 xyz2srgb(vec3 xyz) {
mat3 D65_XYZ_RGB;
D65_XYZ_RGB[0] = vec3( 3.24306333, -1.53837619, -0.49893282);
D65_XYZ_RGB[1] = vec3(-0.96896309, 1.87542451, 0.04154303);
D65_XYZ_RGB[2] = vec3( 0.05568392, -0.20417438, 1.05799454);
float r = dot(D65_XYZ_RGB[0], xyz);
float g = dot(D65_XYZ_RGB[1], xyz);
float b = dot(D65_XYZ_RGB[2], xyz);
return rgb2srgb(vec3(r, g, b));
}
vec4 xyz2srgb(in vec4 xyz) { return vec4(xyz2srgb(xyz.rgb), xyz.a); }
#endif
Dependencies:
Use:
xyz2rgb(<float3|float4> color)
#ifndef FNC_XYZ2SRGB
#define FNC_XYZ2SRGB
float3 xyz2srgb(float3 xyz) {
float3x3 D65_XYZ_RGB;
D65_XYZ_RGB[0] = float3( 3.24306333, -1.53837619, -0.49893282);
D65_XYZ_RGB[1] = float3(-0.96896309, 1.87542451, 0.04154303);
D65_XYZ_RGB[2] = float3( 0.05568392, -0.20417438, 1.05799454);
float r = dot(D65_XYZ_RGB[0], xyz);
float g = dot(D65_XYZ_RGB[1], xyz);
float b = dot(D65_XYZ_RGB[2], xyz);
return rgb2srgb(float3(r, g, b));
}
float4 xyz2srgb(in float4 xyz) { return float4(xyz2srgb(xyz.rgb), xyz.a); }
#endif
Dependencies:
fn xyz2srgb(xyz: vec3<f32> ) -> vec3<f32> {
let D65_XYZ_RGB_0 = vec3<f32>( 3.24306333, -1.53837619, -0.49893282);
let D65_XYZ_RGB_1 = vec3<f32>(-0.96896309, 1.87542451, 0.04154303);
let D65_XYZ_RGB_2 = vec3<f32>( 0.05568392, -0.20417438, 1.05799454);
return rgb2srgb(vec3<f32>( dot(D65_XYZ_RGB_0, xyz),
dot(D65_XYZ_RGB_1, xyz),
dot(D65_XYZ_RGB_2, xyz)));
}
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository