[DEBUG] new color transform correction

This commit is contained in:
Edouard DUPIN 2014-07-10 21:17:47 +02:00
parent cf877f5047
commit 9c14cc6077
7 changed files with 72 additions and 68 deletions

View File

@ -24,7 +24,7 @@ static int32_t getColorSize();
static const colorList_ts* getColorList();
etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input) {
TK_INFO("parseStringStartWithSharp('" << _input << "'");
TK_VERBOSE("parseStringStartWithSharp('" << _input << "'");
size_t len = _input.size();
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
if(len == 3) {
@ -33,10 +33,11 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
outputValue.setR(red | red << 4);
outputValue.setG(green | green << 4);
outputValue.setB(blue | blue << 4);
outputValue.setA(0xFF);
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else if (len==5) {
} else if (len==4) {
int32_t red=0, green=0, blue=0, alpha=0;
if (sscanf(_input.c_str(), "%1x%1x%1x%1x", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red | red << 4);
@ -46,16 +47,17 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else if (len == 7) {
} else if (len == 6) {
int32_t red=0, green=0, blue=0;
if (sscanf(_input.c_str(), "%2x%2x%2x", &red, &green, &blue) == 3) {
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
outputValue.setA(0xFF);
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "'");
}
} else if (len == 9) {
} else if (len == 8) {
int32_t red=0, green=0, blue=0, alpha=0;
if (sscanf(_input.c_str(), "%2x%2x%2x%2x", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red);
@ -72,7 +74,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithSharp(const std::string& _input)
}
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input) {
TK_INFO("parseStringStartWithRGB('" << _input << "'");
TK_VERBOSE("parseStringStartWithRGB('" << _input << "'");
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
float fred=0, fgreen=0, fblue=0, falpha=0;
@ -108,7 +110,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
}
etk::Color<double, 4> etk::parseStringStartWithRGB(const std::string& _input) {
TK_INFO("parseStringStartWithRGB('" << _input << "'");
TK_VERBOSE("parseStringStartWithRGB('" << _input << "'");
etk::Color<double, 4> outputValue(0,0,0,0);
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%lf%%,%lf%%,%lf%%,%lf%%", &fred, &fgreen, &fblue, &falpha) == 4) {
@ -514,35 +516,3 @@ namespace etk {
#include "Color_float.cxx"
#include "Color_double.cxx"
};
/*
template<> Color<float,4>::Color(const etk::Color<uint8_t, 4>& _obj) {
if (MY_TYPE_SIZE >= 1) {
if (MY_TYPE_SIZE_2 >= 1) {
m_element[0] = (float)_obj.m_element[0] / 255.0f;
}
}
if (MY_TYPE_SIZE >= 2) {
if (MY_TYPE_SIZE_2 >= 2) {
m_element[1] = (float)_obj.m_element[1] / 255.0f;
} else {
m_element[1] = 0;
}
}
if (MY_TYPE_SIZE >= 3) {
if (MY_TYPE_SIZE_2 >= 3) {
m_element[2] = (float)_obj.m_element[2] / 255.0f;
} else {
m_element[2] = 0;
}
}
if (MY_TYPE_SIZE >= 4) {
if (MY_TYPE_SIZE_2 >= 4) {
m_element[3] = (float)_obj.m_element[3] / 255.0f;
} else {
m_element[3] = 0;
}
}
}
*/

View File

@ -32,6 +32,8 @@ namespace etk {
* @template-param MY_TYPE Type of the internal template value. The generic value is uint8_t and float
*/
template<typename MY_TYPE=uint8_t, int MY_TYPE_SIZE=4> class Color {
public:
static const Color<MY_TYPE, MY_TYPE_SIZE> emptyColor; // to auto fill with no data in all case
private:
MY_TYPE m_element[MY_TYPE_SIZE]; //!< all the color.
public:
@ -297,6 +299,7 @@ namespace etk {
}
template<typename MY_TYPE, int MY_TYPE_SIZE> Color<MY_TYPE, MY_TYPE_SIZE>::Color(const std::string& _input) {
TK_VERBOSE("convert color string : '" << _input << "'");
const char* inputData = _input.c_str();
size_t len = _input.size();
if( len >=1
@ -325,6 +328,7 @@ namespace etk {
Color<uint8_t, 4> value = etk::parseStringColorNamed(_input);
*this = value;
}
TK_VERBOSE(" ==> converted color string : '" << _input << "' ==> " << *this);
};

View File

@ -1,3 +1,9 @@
template<> const Color<uint16_t, 1> Color<uint16_t, 1>::emptyColor(0);
template<> const Color<uint16_t, 2> Color<uint16_t, 2>::emptyColor(0,0);
template<> const Color<uint16_t, 3> Color<uint16_t, 3>::emptyColor(0,0,0);
template<> const Color<uint16_t, 4> Color<uint16_t, 4>::emptyColor(0,0,0,0xFFFF);
// this work ...
template<> template<> Color<uint16_t,1>::Color(const Color<uint8_t, 1>& _obj) {
m_element[0] = (uint16_t)_obj.r() << 8;

View File

@ -1,3 +1,9 @@
template<> const Color<uint32_t, 1> Color<uint32_t, 1>::emptyColor(0);
template<> const Color<uint32_t, 2> Color<uint32_t, 2>::emptyColor(0,0);
template<> const Color<uint32_t, 3> Color<uint32_t, 3>::emptyColor(0,0,0);
template<> const Color<uint32_t, 4> Color<uint32_t, 4>::emptyColor(0,0,0,0xFFFFFFFF);
// this work ...
template<> template<> Color<uint32_t,1>::Color(const Color<uint8_t, 1>& _obj) {
m_element[0] = (uint32_t)_obj.r() << 24;

View File

@ -1,3 +1,9 @@
template<> const Color<uint8_t, 1> Color<uint8_t, 1>::emptyColor(0);
template<> const Color<uint8_t, 2> Color<uint8_t, 2>::emptyColor(0,0);
template<> const Color<uint8_t, 3> Color<uint8_t, 3>::emptyColor(0,0,0);
template<> const Color<uint8_t, 4> Color<uint8_t, 4>::emptyColor(0,0,0,0xFF);
// this work ...
template<> template<> Color<uint8_t,1>::Color(const Color<uint8_t, 1>& _obj) {
m_element[0] = _obj.r();
@ -225,76 +231,76 @@ template<> template<> Color<uint8_t,4>::Color(const Color<uint32_t, 4>& _obj) {
// ===========================================================================================================
template<> template<> Color<uint8_t,1>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = 0;
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = 0;
m_element[2] = 0;
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 1>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = 0;
m_element[2] = 0;
m_element[3] = 0;
}
template<> template<> Color<uint8_t,1>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
m_element[2] = 0;
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 2>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
m_element[2] = 0;
m_element[3] = 0;
}
template<> template<> Color<uint8_t,1>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[2] = (uint8_t)(_obj.b()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
m_element[2] = (uint8_t)(_obj.b()*255.0f);
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 3>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[2] = (uint8_t)(_obj.b()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
m_element[2] = (uint8_t)(_obj.b()*255.0f);
m_element[3] = 0;
}
template<> template<> Color<uint8_t,1>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
}
template<> template<> Color<uint8_t,2>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
}
template<> template<> Color<uint8_t,3>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[2] = (uint8_t)(_obj.b()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
m_element[2] = (uint8_t)(_obj.b()*255.0f);
}
template<> template<> Color<uint8_t,4>::Color(const Color<float, 4>& _obj) {
m_element[0] = (uint8_t)(_obj.r()*256.0f);
m_element[1] = (uint8_t)(_obj.g()*256.0f);
m_element[2] = (uint8_t)(_obj.b()*256.0f);
m_element[3] = (uint8_t)(_obj.a()*256.0f);
m_element[0] = (uint8_t)(_obj.r()*255.0f);
m_element[1] = (uint8_t)(_obj.g()*255.0f);
m_element[2] = (uint8_t)(_obj.b()*255.0f);
m_element[3] = (uint8_t)(_obj.a()*255.0f);
}
// ===========================================================================================================

View File

@ -1,3 +1,9 @@
template<> const Color<double, 1> Color<double, 1>::emptyColor(0.0);
template<> const Color<double, 2> Color<double, 2>::emptyColor(0.0,0.0);
template<> const Color<double, 3> Color<double, 3>::emptyColor(0.0,0.0,0.0);
template<> const Color<double, 4> Color<double, 4>::emptyColor(0.0,0.0,0.0,1.0);
// this work ...
template<> template<> Color<double,1>::Color(const Color<uint8_t, 1>& _obj) {
m_element[0] = (double)_obj.r() / 255.0;

View File

@ -1,3 +1,9 @@
template<> const Color<float, 1> Color<float, 1>::emptyColor(0.0f);
template<> const Color<float, 2> Color<float, 2>::emptyColor(0.0f,0.0f);
template<> const Color<float, 3> Color<float, 3>::emptyColor(0.0f,0.0f,0.0f);
template<> const Color<float, 4> Color<float, 4>::emptyColor(0.0f,0.0f,0.0f,1.0f);
// this work ...
template<> template<> Color<float,1>::Color(const Color<uint8_t, 1>& _obj) {
m_element[0] = (float)_obj.r() / 255.0f;