lygia
/v1.1.6
/color
/space
/rgb2lms
)Convert rgb to LMS. LMS (long, medium, short), is a color space which represents the response of the three types of cones of the human eye, named for their responsivity (sensitivity) peaks at long, medium, and short wavelengths. Refs https://en.wikipedia.org/wiki/LMS_color_space https://arxiv.org/pdf/1711.10662
Use:
<vec3|vec4> rgb2lms(<vec3|vec4> rgb)
#ifndef FNC_RGB2LMS
#define FNC_RGB2LMS
vec3 rgb2lms(vec3 rgb) {
// mat3 rgb2lms_mat = mat3(
// 3.90405e-1, 5.49941e-1, 8.92632e-3,
// 7.08416e-2, 9.63172e-1, 1.35775e-3,
// 2.31082e-2, 1.28021e-1, 9.36245e-1
// );
mat3 rgb2lms_mat = mat3(
17.8824, 3.45565, 0.0299566,
43.5161, 27.1554, 0.184309,
4.11935, 0.184309, 1.46709
);
return rgb2lms_mat * rgb;
}
vec4 rgb2lms(vec4 rgb) { return vec4(rgb.rgb, rgb.a); }
#endif
Use:
<float3|float4> rgb2lms(<float3|float4> rgb)
#ifndef FNC_RGB2LMS
#define FNC_RGB2LMS
float3 rgb2lms(float3 rgb) {
// float3x3 rgb2lms_mat = float3x3(
// 3.90405e-1, 5.49941e-1, 8.92632e-3,
// 7.08416e-2, 9.63172e-1, 1.35775e-3,
// 2.31082e-2, 1.28021e-1, 9.36245e-1
// );
float3x3 rgb2lms_mat = float3x3(
17.8824, 3.45565, 0.0299566,
43.5161, 27.1554, 0.184309,
4.11935, 0.184309, 1.46709
);
return mul(rgb2lms_mat, rgb);
}
float4 rgb2lms(float4 rgb) { return float4( rgb2lms(rgb.rgb), rgb.a); }
#endif
fn rgb2lms(rgb: vec3<f32>) -> vec3<f32> {
// mat3 rgb2lms_mat = mat3(
// 3.90405e-1, 5.49941e-1, 8.92632e-3,
// 7.08416e-2, 9.63172e-1, 1.35775e-3,
// 2.31082e-2, 1.28021e-1, 9.36245e-1
// );
let rgb2lms_mat = mat3x3<f32>(
vec3<f32>(17.8824, 3.45565, 0.0299566),
vec3<f32>(43.5161, 27.1554, 0.184309),
vec3<f32>(4.11935, 0.184309, 1.46709)
);
return rgb2lms_mat * rgb;
}
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