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

Commit 53f5acd1 authored by Pierre Aubert's avatar Pierre Aubert

Add template function to colorize image with table of values and a PColorMap

parent f10fcc84
Pipeline #99731 passed with stages
in 1 minute and 57 seconds
......@@ -106,6 +106,44 @@ bool testWriteColorMapPng3(){
return b;
}
///Test the write of a png file
/** @return true on success, false otherwise
*/
bool testWriteColorMapPng4(){
std::string fileName("outputColorMap4.png");
bool b(true);
PColorMap colorMap;
// 0,#000000,0.2,#00FF00,0.21,#FFFF00,0.4,#FF0000,0.6,#FFFFFF
colorMap.addColor(0.0, 0, 0, 0, 0);
colorMap.addColor(5.0, "00FF00FF");
colorMap.addColor(10.0, "00FF0099");
colorMap.addColor(20.0, "FFFF0055");
colorMap.addColor(30.0, "FF0000AA");
colorMap.addColor(40.0, "FFFFFFFF");
size_t width(640lu), height(480lu);
PImagePng image;
b &= image.createImage(width, height, PImagePng::RGBA);
float * matValue = new float[width*height];
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);
matValue[j*width + i] = value;
}
}
image.setColor(matValue, height, width, colorMap);
b &= image.write(fileName);
delete [] matValue;
return b;
}
///The the basic functions of a color map
/** @return true on success, false otherwise
*/
......@@ -133,6 +171,7 @@ int main(int argc, char** argv){
b &= testWriteColorMapPng();
b &= testWriteColorMapPng2();
b &= testWriteColorMapPng3();
b &= testWriteColorMapPng4();
b &= testBaseColorMap();
return b - 1;
}
......
......@@ -41,10 +41,14 @@ class PImagePng{
void setColor(size_t idxWidth, size_t idxHeight, color_t red, color_t green, color_t blue);
void setColor(size_t idxWidth, size_t idxHeight, color_t red, color_t green, color_t blue, color_t alpha);
template<typename T>
void setColor(const T * matValue, size_t nbRow, size_t nbCol, const PColorMap & colorMap);
void getColor(size_t idxWidth, size_t idxHeight, color_t & red, color_t & green, color_t & blue);
void getColor(size_t idxWidth, size_t idxHeight, color_t & red, color_t & green, color_t & blue, color_t & alpha);
unsigned int getWidth() const;
unsigned int getHeight() const;
NbColorByte getNbBytePerPixel() const;
......@@ -66,7 +70,7 @@ class PImagePng{
NbColorByte p_nbBytePerPixel;
};
#include "PImagePng_impl.h"
#endif
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#ifndef __PIMAGEPNG_IMPL_H__
#define __PIMAGEPNG_IMPL_H__
#include <algorithm>
#include "PImagePng.h"
///Set the color of the image by respect to a given matrix of values and the colorMap
/** @param matValue : matrix of value to be used to colorize the PImagePng
* @param nbRow : number of rows of the matrix
* @param nbCol : number of columns of the matrix
* @param colorMap : PColorMap to be used to convert values in color
*/
template<typename T>
void PImagePng::setColor(const T * matValue, size_t nbRow, size_t nbCol, const PColorMap & colorMap){
size_t nbValueRow(std::min(nbRow, (size_t)p_image.height));
size_t nbValueCol(std::min(nbCol, (size_t)p_image.width));
for(size_t i(0lu); i < nbValueRow; ++i){
for(size_t j(0lu); j < nbValueCol; ++j){
float value(matValue[i*nbCol + j]);
color_t red(0), green(0), blue(0), alpha(0);
colorMap.interpolate(red, green, blue, alpha, value);
setColor(j, i, red, green, blue, alpha);
}
}
}
#endif
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