Gitlab is now running v13.10.2 - More info -> here <-

Commit f10fcc84 authored by Pierre Aubert's avatar Pierre Aubert

Add test

parent 828c587a
Pipeline #99730 passed with stages
in 1 minute and 35 seconds
......@@ -50,7 +50,7 @@ bool testWriteColorMapPng2(){
PColorMap colorMap;
// 0,#000000,0.2,#00FF00,0.21,#FFFF00,0.4,#FF0000,0.6,#FFFFFF
colorMap.addColor(0.0, "00000000");
colorMap.addColor(0.0, 0, 0, 0, 0);
colorMap.addColor(5.0, "00FF00FF");
colorMap.addColor(10.0, "00FF0099");
colorMap.addColor(20.0, "FFFF0055");
......@@ -76,6 +76,36 @@ bool testWriteColorMapPng2(){
return b;
}
///Test the write of a png file
/** @return true on success, false otherwise
*/
bool testWriteColorMapPng3(){
std::string fileName("outputColorMap3.png");
bool b(true);
PColorValue minValue = createColorValue(0.0, "000000AA");
PColorValue maxValue = createColorValue(1.0, "FFFFFFFF");
size_t width(640lu), height(480lu);
PImagePng image;
b &= image.createImage(width, height, PImagePng::RGBA);
image.fill(18, 234, 142);
for(size_t j(0lu); j < height; ++j){
for(size_t i(0lu); i < width; ++i){
float value(((j*width + i)/1000lu)%42lu);
color_t red(0), green(0), blue(0), alpha(0);
PColorValue color(phoenix_interpolateColor(minValue, maxValue, value));
getColorValue(red, green, blue, alpha, color);
image.setColor(i, j, red, green, blue, alpha);
}
}
b &= image.write(fileName);
return b;
}
///The the basic functions of a color map
/** @return true on success, false otherwise
*/
......@@ -102,6 +132,7 @@ int main(int argc, char** argv){
bool b(true);
b &= testWriteColorMapPng();
b &= testWriteColorMapPng2();
b &= testWriteColorMapPng3();
b &= testBaseColorMap();
return b - 1;
}
......
......@@ -7,6 +7,64 @@
#include <stdlib.h>
#include "PColorMap.h"
///Create a PColorValue
/** @param value : associated value with the given color
* @param color : associated color
* @return PColorValue
*/
PColorValue createColorValue(float value, const std::string & color){
size_t nbChannel(color.size());
color_t red(0), green(0), blue(0), alpha(0);
if(nbChannel >= 2lu){
std::string redHex(color.substr(0lu, 2lu));
red = (color_t)strtol(redHex.c_str(), NULL, 16);
}
if(nbChannel >= 4lu){
std::string greenHex(color.substr(2lu, 2lu));
green = (color_t)strtol(greenHex.c_str(), NULL, 16);
}
if(nbChannel >= 6lu){
std::string blueHex(color.substr(4lu, 2lu));
blue = (color_t)strtol(blueHex.c_str(), NULL, 16);
}
if(nbChannel >= 8lu){
std::string alphaHex(color.substr(6lu, 2lu));
alpha = (color_t)strtol(alphaHex.c_str(), NULL, 16);
}
return createColorValue(value, red, green, blue, alpha);
}
///Create a PColorValue
/** @param value : associated value with the given color
* @param red : red proportion
* @param green : green proportion
* @param blue : blue proportion
* @param alpha : transparent proportion
* @return PColorValue
*/
PColorValue createColorValue(float value, color_t red, color_t green, color_t blue, color_t alpha){
PColorValue colorValue;
colorValue.value = value;
colorValue.r = red;
colorValue.g = green;
colorValue.b = blue;
colorValue.a = alpha;
return colorValue;
}
///Get the rgba values from PColorValue
/** @param[out] red : red proportion
* @param[out] green : green proportion
* @param[out] blue : blue proportion
* @param value : given value
*/
void getColorValue(color_t & red, color_t & green, color_t & blue, color_t & alpha, const PColorValue & color){
red = color.r;
green = color.g;
blue = color.b;
alpha = color.a;
}
///Interpolate a color with a value by respect to min an max color
/** @param[out] output : interpolated color
* @param colorMin : color of the minimum value
......@@ -65,25 +123,8 @@ PColorMap & PColorMap::operator = (const PColorMap & other){
* @param color : hexadecimal color associated to the given value (FF000000, 00FF0000, 0000FF00, 000000FF, etc)
*/
void PColorMap::addColor(float value, const std::string & color){
size_t nbChannel(color.size());
color_t red(0), green(0), blue(0), alpha(0);
if(nbChannel >= 2lu){
std::string redHex(color.substr(0lu, 2lu));
red = (color_t)strtol(redHex.c_str(), NULL, 16);
}
if(nbChannel >= 4lu){
std::string greenHex(color.substr(2lu, 2lu));
green = (color_t)strtol(greenHex.c_str(), NULL, 16);
}
if(nbChannel >= 6lu){
std::string blueHex(color.substr(4lu, 2lu));
blue = (color_t)strtol(blueHex.c_str(), NULL, 16);
}
if(nbChannel >= 8lu){
std::string alphaHex(color.substr(6lu, 2lu));
alpha = (color_t)strtol(alphaHex.c_str(), NULL, 16);
}
addColor(value, red, green, blue, alpha);
PColorValue colorValue = createColorValue(value, color);
p_mapColor[value] = colorValue;
}
///Add a color in the PColorMap
......@@ -94,13 +135,7 @@ void PColorMap::addColor(float value, const std::string & color){
* @param alpha : transparent proportion
*/
void PColorMap::addColor(float value, color_t red, color_t green, color_t blue, color_t alpha){
PColorValue colorValue;
colorValue.value = value;
colorValue.r = red;
colorValue.g = green;
colorValue.b = blue;
colorValue.a = alpha;
PColorValue colorValue = createColorValue(value, red, green, blue, alpha);
p_mapColor[value] = colorValue;
}
......
......@@ -30,6 +30,10 @@ struct PColorValue{
///Vector of a color value
typedef std::map<float, PColorValue> PMapColorValue;
PColorValue createColorValue(float value, const std::string & color);
PColorValue createColorValue(float value, color_t red, color_t green, color_t blue, color_t alpha = 255);
void getColorValue(color_t & red, color_t & green, color_t & blue, color_t & alpha, const PColorValue & color);
///@brief Describe a color map to adapt color with input value
class PColorMap{
public:
......
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