ipa: libipa: colour: Use Vector and Matrix for linear algebra
Replace the manual vector and matrix calculations with usage of the Vector and Matrix classes. This simplifies the code and improves readability. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
This commit is contained in:
parent
29892f1c56
commit
16c15c428d
1 changed files with 17 additions and 9 deletions
|
@ -31,7 +31,11 @@ namespace ipa {
|
||||||
*/
|
*/
|
||||||
double rec601LuminanceFromRGB(const RGB<double> &rgb)
|
double rec601LuminanceFromRGB(const RGB<double> &rgb)
|
||||||
{
|
{
|
||||||
return (rgb.r() * .299) + (rgb.g() * .587) + (rgb.b() * .114);
|
static const Vector<double, 3> rgb2y{{
|
||||||
|
0.299, 0.587, 0.114
|
||||||
|
}};
|
||||||
|
|
||||||
|
return rgb.dot(rgb2y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,17 +58,21 @@ double rec601LuminanceFromRGB(const RGB<double> &rgb)
|
||||||
*/
|
*/
|
||||||
uint32_t estimateCCT(const RGB<double> &rgb)
|
uint32_t estimateCCT(const RGB<double> &rgb)
|
||||||
{
|
{
|
||||||
/* Convert the RGB values to CIE tristimulus values (XYZ) */
|
/*
|
||||||
double X = (-0.14282) * rgb.r() + (1.54924) * rgb.g() + (-0.95641) * rgb.b();
|
* Convert the RGB values to CIE tristimulus values (XYZ) and divide by
|
||||||
double Y = (-0.32466) * rgb.r() + (1.57837) * rgb.g() + (-0.73191) * rgb.b();
|
* the sum of X, Y and Z to calculate the CIE xy chromaticity.
|
||||||
double Z = (-0.68202) * rgb.r() + (0.77073) * rgb.g() + (0.56332) * rgb.b();
|
*/
|
||||||
|
static const Matrix<double, 3, 3> rgb2xyz({
|
||||||
|
-0.14282, 1.54924, -0.95641,
|
||||||
|
-0.32466, 1.57837, -0.73191,
|
||||||
|
-0.68202, 0.77073, 0.56332
|
||||||
|
});
|
||||||
|
|
||||||
/* Calculate the normalized chromaticity values */
|
Vector<double, 3> xyz = rgb2xyz * rgb;
|
||||||
double x = X / (X + Y + Z);
|
xyz /= xyz.sum();
|
||||||
double y = Y / (X + Y + Z);
|
|
||||||
|
|
||||||
/* Calculate CCT */
|
/* Calculate CCT */
|
||||||
double n = (x - 0.3320) / (0.1858 - y);
|
double n = (xyz.x() - 0.3320) / (0.1858 - xyz.y());
|
||||||
return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33;
|
return 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue