[DEV] update test and color

This commit is contained in:
Edouard DUPIN 2014-09-11 21:47:21 +02:00
parent ce3243a5f4
commit 3db451068b
5 changed files with 149 additions and 44 deletions

View File

@ -90,7 +90,16 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%f%%,%f%%,%f%%,%f%%", &fred, &fgreen, &fblue, &falpha) == 4) {
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%f,%f,%f,%f", &fred, &fgreen, &fblue, &falpha) == 4) {
fred = std::avg(0.0f, fred, 1.0f);
fgreen = std::avg(0.0f, fgreen, 1.0f);
fblue = std::avg(0.0f, fblue, 1.0f);
@ -99,7 +108,7 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
outputValue.setG((uint8_t)(fgreen * 255.f));
outputValue.setB((uint8_t)(fblue * 255.f));
outputValue.setR((uint8_t)(falpha * 255.f));
} else if (sscanf(_input.c_str(), "%f%%,%f%%,%f%%", &fred, &fgreen, &fblue) == 3) {
} else if (sscanf(_input.c_str(), "%f,%f,%f", &fred, &fgreen, &fblue) == 3) {
fred = std::avg(0.0f, fred, 1.0f);
fgreen= std::avg(0.0f, fgreen, 1.0f);
fblue = std::avg(0.0f, fblue, 1.0f);
@ -113,18 +122,37 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBGen(const std::string& _input
}
etk::Color<double, 4> etk::parseStringStartWithRGB(const std::string& _input) {
TK_VERBOSE("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) {
int32_t red=0, green=0, blue=0, alpha=0;
if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR(fred);
outputValue.setG(fgreen);
outputValue.setB(fblue);
outputValue.setA(falpha);
} else if (sscanf(_input.c_str(), "%lf%%,%lf%%,%lf%%", &fred, &fgreen, &fblue) == 3) {
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR(fred);
outputValue.setG(fgreen);
outputValue.setB(fblue);
} else if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setA(std::min(0xFF, alpha)/255.0);
} else if (sscanf(_input.c_str(), "%u,%u,%u", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
outputValue.setA(std::min(0xFF, alpha)/255.0);
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red)/255.0);
outputValue.setG(std::min(0xFF, green)/255.0);
outputValue.setB(std::min(0xFF, blue)/255.0);
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
@ -133,6 +161,7 @@ etk::Color<double, 4> etk::parseStringStartWithRGB(const std::string& _input) {
etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string& _input) {
etk::Color<uint32_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red);
outputValue.setG(green);
@ -142,6 +171,24 @@ etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
outputValue.setA(alpha);
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(red);
outputValue.setG(green);
outputValue.setB(blue);
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR((uint32_t)(std::min(1.0, fred)*0xFFFFFFFF));
outputValue.setG((uint32_t)(std::min(1.0, fgreen)*0xFFFFFFFF));
outputValue.setB((uint32_t)(std::min(1.0, fblue)*0xFFFFFFFF));
outputValue.setA((uint32_t)(std::min(1.0, falpha)*0xFFFFFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR((uint32_t)(std::min(1.0, fred)*0xFFFFFFFF));
outputValue.setG((uint32_t)(std::min(1.0, fgreen)*0xFFFFFFFF));
outputValue.setB((uint32_t)(std::min(1.0, fblue)*0xFFFFFFFF));
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
@ -151,6 +198,7 @@ etk::Color<uint32_t, 4> etk::parseStringStartWithRGBUnsigned32(const std::string
etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string& _input) {
etk::Color<uint16_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
@ -160,6 +208,24 @@ etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
outputValue.setA(std::min(0xFFFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFFFF, red));
outputValue.setG(std::min(0xFFFF, green));
outputValue.setB(std::min(0xFFFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR((uint16_t)(std::min(1.0, fred)*0xFFFF));
outputValue.setG((uint16_t)(std::min(1.0, fgreen)*0xFFFF));
outputValue.setB((uint16_t)(std::min(1.0, fblue)*0xFFFF));
outputValue.setA((uint16_t)(std::min(1.0, falpha)*0xFFFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR((uint16_t)(std::min(1.0, fred)*0xFFFF));
outputValue.setG((uint16_t)(std::min(1.0, fgreen)*0xFFFF));
outputValue.setB((uint16_t)(std::min(1.0, fblue)*0xFFFF));
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}
@ -169,6 +235,7 @@ etk::Color<uint16_t, 4> etk::parseStringStartWithRGBUnsigned16(const std::string
etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const std::string& _input) {
etk::Color<uint8_t, 4> outputValue(0,0,0,0);
int32_t red=0, green=0, blue=0, alpha=0;
double fred=0, fgreen=0, fblue=0, falpha=0;
if (sscanf(_input.c_str(), "%u,%u,%u,%u", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
@ -178,6 +245,24 @@ etk::Color<uint8_t, 4> etk::parseStringStartWithRGBUnsigned8(const std::string&
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%X,%X,%X,%X", &red, &green, &blue, &alpha) == 4) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
outputValue.setA(std::min(0xFF, alpha));
} else if (sscanf(_input.c_str(), "%X,%X,%X", &red, &green, &blue) == 3) {
outputValue.setR(std::min(0xFF, red));
outputValue.setG(std::min(0xFF, green));
outputValue.setB(std::min(0xFF, blue));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf,%lf", &fred, &fgreen, &fblue, &falpha) == 4) {
outputValue.setR((uint8_t)(std::min(1.0, fred)*0xFF));
outputValue.setG((uint8_t)(std::min(1.0, fgreen)*0xFF));
outputValue.setB((uint8_t)(std::min(1.0, fblue)*0xFF));
outputValue.setA((uint8_t)(std::min(1.0, falpha)*0xFF));
} else if (sscanf(_input.c_str(), "%lf,%lf,%lf", &fred, &fgreen, &fblue) == 3) {
outputValue.setR((uint8_t)(std::min(1.0, fred)*0xFF));
outputValue.setG((uint8_t)(std::min(1.0, fgreen)*0xFF));
outputValue.setB((uint8_t)(std::min(1.0, fblue)*0xFF));
} else {
TK_ERROR(" pb in parsing the color : '" << _input << "' ==> unknown methode ...");
}

View File

@ -308,22 +308,40 @@ namespace etk {
Color<uint8_t, 4> value = etk::parseStringStartWithSharp(std::string(_input, 1));
*this = value;
} else if(etk::start_with(_input, "rgb(", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBGen(std::string(_input, 4, _input.size()-1));
Color<uint8_t, 4> value = etk::parseStringStartWithRGBGen(std::string(_input, 4, _input.size()-5));
*this = value;
} else if(etk::start_with(_input, "rgba(", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBGen(std::string(_input, 5, _input.size()-6));
*this = value;
} else if(etk::start_with(_input, "rgb[FLOAT](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 11, _input.size()-1));
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 11, _input.size()-12));
*this = value;
} else if(etk::start_with(_input, "rgba[FLOAT](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-13));
*this = value;
} else if(etk::start_with(_input, "rgb[DOUBLE](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-1));
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 12, _input.size()-13));
*this = value;
} else if(etk::start_with(_input, "rgba[DOUBLE](", false) == true) {
Color<double, 4> value = etk::parseStringStartWithRGB(std::string(_input, 13, _input.size()-14));
*this = value;
} else if(etk::start_with(_input, "rgb[U32](", false) == true) {
Color<uint32_t, 4> value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 9, _input.size()-1));
Color<uint32_t, 4> value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 9, _input.size()-10));
*this = value;
} else if(etk::start_with(_input, "rgba[U32](", false) == true) {
Color<uint32_t, 4> value = etk::parseStringStartWithRGBUnsigned32(std::string(_input, 10, _input.size()-11));
*this = value;
} else if(etk::start_with(_input, "rgb[U16](", false) == true) {
Color<uint16_t, 4> value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 9, _input.size()-1));
Color<uint16_t, 4> value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 9, _input.size()-10));
*this = value;
} else if(etk::start_with(_input, "rgba[U16](", false) == true) {
Color<uint16_t, 4> value = etk::parseStringStartWithRGBUnsigned16(std::string(_input, 10, _input.size()-11));
*this = value;
} else if(etk::start_with(_input, "rgb[U8](", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 8, _input.size()-1));
Color<uint8_t, 4> value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 8, _input.size()-9));
*this = value;
} else if(etk::start_with(_input, "rgba[U8](", false) == true) {
Color<uint8_t, 4> value = etk::parseStringStartWithRGBUnsigned8(std::string(_input, 9, _input.size()-10));
*this = value;
} else {
Color<uint8_t, 4> value = etk::parseStringColorNamed(_input);

View File

@ -1696,7 +1696,7 @@ bool etk::FSNode::filePuts(const std::string& _input) {
return false;
}
int64_t etk::FSNode::fileWrite(void * _data, int64_t _blockSize, int64_t _nbBlock) {
int64_t etk::FSNode::fileWrite(const void * _data, int64_t _blockSize, int64_t _nbBlock) {
#ifdef __TARGET_OS__Android
if( m_type == etk::FSN_TYPE_DATA
|| m_type == etk::FSN_TYPE_THEME_DATA) {
@ -1706,6 +1706,7 @@ int64_t etk::FSNode::fileWrite(void * _data, int64_t _blockSize, int64_t _nbBloc
#endif
return fwrite(_data, _blockSize, _nbBlock, m_PointerFile);
}
bool etk::FSNode::fileSeek(long int _offset, enum etk::seekNode _origin)
{
#ifdef __TARGET_OS__Android

View File

@ -452,7 +452,7 @@ namespace etk {
* @param[in] _nbBlock Number of block needed
* @return Number of element written (in block number)
*/
int64_t fileWrite(void* _data, int64_t _blockSize, int64_t _nbBlock);
int64_t fileWrite(const void* _data, int64_t _blockSize, int64_t _nbBlock);
/**
* @brief Get the position in the file.
* @return the requested position.
@ -470,6 +470,22 @@ namespace etk {
* @brief Flush the current file
*/
void fileFlush();
/**
* @brief Read all element in a file and set it in a generic vector
* @return the read vector
*/
template<typename T> std::vector<T> fileReadAll() {
std::vector<T> value;
value.resize(fileSize());
fileRead(&value[0], sizeof(T), fileSize()/sizeof(T));
return value;
}
/**
* @brief Write all the vector in a file
*/
template<typename T> void fileWriteAll(const std::vector<T>& _value) {
fileWrite(static_cast<const void*>(&(_value[0])), sizeof(T), _value.size()/sizeof(T));
}
private:
/**
* @brief Order the list of subnode the folder first and the alphabetical order

View File

@ -20,14 +20,6 @@
#undef __class__
#define __class__ "etktest"
void testVector() {
}
void testUChar() {
}
void testHash() {
TK_INFO("==> Start test of Hach table");
etk::Hash<std::string> testData;
@ -136,7 +128,6 @@ void testDimension() {
void testColor() {
TK_INFO("==> test of COLOR (START)");
/*
etk::Color<uint8_t, 4> colorRGBA8(0x52,0x0F, 0x65, 0x44);
etk::Color<uint16_t, 4> colorRGBA16(0x52,0x0F, 0x65, 0x44);
etk::Color<uint32_t, 4> colorRGBA32(0x52,0x0F, 0x65, 0x44);
@ -150,23 +141,22 @@ void testColor() {
etk::Color<uint32_t, 1> colorMono32(0x52);
etk::Color<float, 1> colorMonoF(5200.22);
etk::Color<double, 1> colorMonoD(520000.22);
*/
/*
etk::Color<uint8_t, 4> colorRGBA8__("#520F6544");
etk::Color<uint16_t, 4> colorRGBA16__("rgba(0x52, 0x0F, 0x65, 0x44)");
etk::Color<uint32_t, 4> colorRGBA32__("rgba(0x52,0x0F, 0x65, 0x44)");
etk::Color<float, 4> colorRGBAF__("rgba(0.1,0.2, 0.8, 1.0)");
etk::Color<uint8_t, 3> colorRGB8__("rgba(0x52,0x0F, 0x65)");
etk::Color<uint16_t, 3> colorRGB16__("rgba(0x52,0x0F, 0x65)");
etk::Color<uint32_t, 3> colorRGB32__("rgba(0x52,0x0F, 0x65)");
etk::Color<float, 3> colorRGBF__("rgba(0.1,0.2, 0.8)");
etk::Color<uint8_t, 1> colorMono8__("mono(0x52)");
etk::Color<uint16_t, 1> colorMono16__("mono(0x52)");
etk::Color<uint32_t, 1> colorMono32__("mono(0x52)");
etk::Color<float, 1> colorMonoF__("mono(5200.22)");
etk::Color<double, 1> colorMonoD__("mono(520000.22)");
*/
etk::Color<uint16_t, 4> colorRGBA16__("rgba[U16](0x52, 0x0F, 0x65, 0x44)");
etk::Color<uint32_t, 4> colorRGBA32__("rgba[U32](0x52,0x0F, 0x65, 0x44)");
etk::Color<float, 4> colorRGBAF__("rgba[FLOAT](0.1,0.2,0.8,1.0)");
etk::Color<uint8_t, 3> colorRGB8__("rgba[U8](0x52,0x0F, 0x65)");
etk::Color<uint16_t, 3> colorRGB16__("rgba[U16](0x52,0x0F, 0x65)");
etk::Color<uint32_t, 3> colorRGB32__("rgba[U32](0x52,0x0F, 0x65)");
etk::Color<float, 3> colorRGBF__("rgba[FLOAT](0.1,0.2, 0.8)");
/*
etk::Color<uint8_t, 1> colorMono8__("mono[U8](0x52)");
etk::Color<uint16_t, 1> colorMono16__("mono[U16](0x52)");
etk::Color<uint32_t, 1> colorMono32__("mono[U32](0x52)");
etk::Color<float, 1> colorMonoF__("mono[FLOAT](5200.22)");
etk::Color<double, 1> colorMonoD__("mono[DOUBLE](520000.22)");
*/
etk::Color<float, 4> colorRGBAf__(colorRGBA8);
etk::Color<uint32_t, 2> colorXX332__(colorRGBA8);
@ -185,9 +175,7 @@ void testColor() {
TK_INFO("Create a color : MONO 32 : " << colorMono32);
TK_INFO("Create a color : MONO float : " << colorMonoF);
TK_INFO("Create a color : MONO double : " << colorMonoD);
*/
TK_INFO("==> test of Color (STOP)");
exit(0);
}
void testRegExpSingle(const std::string& _expression, const std::string& _search) {
@ -283,14 +271,11 @@ int main(int argc, const char *argv[]) {
etk::setArgZero(argv[0]);
etk::initDefaultFolder("ewolApplNoName");
//testVector();
//testUChar();
//testUString();
//testHash();
testHash();
//testFSNode();
//testDimension();
//testArchive();
//testColor();
testColor();
testRegExp();
return 0;
}