Commit a220c0e5 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Polish of RGB to LAB color conversion.

parent 1c6c1026
......@@ -60,19 +60,26 @@ void Color::setB(int b)
LAB Color::toLAB() const
{
LAB r;
Real fXX0 = 0;
Real fYY0 = 0;
Real fZZ0 = 0;
TMatrix<3,1> gMat({{Color::g(mR/255.0)}
,{Color::g(mG/255.0)}
,{Color::g(mG/255.0)}});
Real fXX0 = 0.;
Real fYY0 = 0.;
Real fZZ0 = 0.;
TMatrix<3,1> gMat({{Color::g(Real(mR)/255.)}
,{Color::g(Real(mG)/255.)}
,{Color::g(Real(mB)/255.)}});
TMatrix<3,1> XYZ = Color::bradford_srgb_matrix * gMat;
radix_line("XYZ={{" << XYZ.data()[0][0]
<< "},{" << XYZ.data()[1][0]
<< "},{" << XYZ.data()[2][0]
<< "}}");
tmatrix_value_t X0 = 0.964221;
tmatrix_value_t Y0 = 1.0;
tmatrix_value_t Z0 = 0.825213;
fXX0 = Color::f(XYZ.data()[0][0]/X0);
fYY0 = Color::f(XYZ.data()[1][0]/Y0);
fZZ0 = Color::f(XYZ.data()[2][0]/Z0);
radix_line("x0=" << fXX0
<< ", y0=" << fYY0
<< ", z0=" << fZZ0);
r.setL(116.0 * fYY0 - 16.0);
r.setA(500.0 * (fXX0 - fYY0));
r.setB(200.0 * (fYY0 - fZZ0));
......@@ -81,12 +88,12 @@ LAB Color::toLAB() const
Real Color::f(Real z)
{
if(z > 0.008856)
if(z > 0.008856452)
{
return std::pow(z, 1.0/3.0);
} else
{
return 7.787*z + 16.0/116.0;
return 7.787037037*z + 4./29.0;
}
}
Real Color::g(Real z)
......@@ -101,12 +108,12 @@ Real Color::g(Real z)
}
LAB::LAB()
: mL(0)
, mA(0)
, mB(0)
: mL(0.)
, mA(0.)
, mB(0.)
{
}
LAB::LAB(int l, int a, int b)
LAB::LAB(Real l, Real a, Real b)
: mL(l)
, mA(a)
, mB(b)
......
......@@ -12,13 +12,13 @@ class LAB
Real mL, mA, mB;
public:
LAB();
LAB(int l, int a, int b);
int l() const { return mL; }
void setL(int v) { mL = v; }
int a() const { return mA; }
void setA(int v) { mA = v; }
int b() const { return mB; }
void setB(int v) { mB = v; }
LAB(Real l, Real a, Real b);
Real l() const { return mL; }
void setL(Real v) { mL = v; }
Real a() const { return mA; }
void setA(Real v) { mA = v; }
Real b() const { return mB; }
void setB(Real v) { mB = v; }
};
/**
* @brief The Color(rgb) class
......
......@@ -3,20 +3,20 @@
#include "radixcolor/color.hh"
using namespace radix;
TEST(Radix, DISABLED_RGBtoLAB)
TEST(Radix, RGBtoLAB)
{
{
Color rgb(255, 255, 255);
LAB lab = rgb.toLAB();
EXPECT_EQ(100, lab.l());
EXPECT_EQ(0.00526049995830391, lab.a());
EXPECT_EQ(-0.010408184525267927, lab.b());
EXPECT_FLOAT_EQ(100, lab.l());
EXPECT_FLOAT_EQ(8.5893182e-05, lab.a());
EXPECT_FLOAT_EQ(0.00010726118, lab.b());
}
{
Color rgb(100, 255, 1);
LAB lab = rgb.toLAB();
EXPECT_EQ(89.0317899987809, lab.l());
EXPECT_EQ(-74.86753281894853, lab.a());
EXPECT_EQ(84.68384242989339, lab.b());
EXPECT_FLOAT_EQ(89.170418, lab.l());
EXPECT_FLOAT_EQ(-68.176277, lab.a());
EXPECT_FLOAT_EQ(82.658813, lab.b());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment