PhoenixPNG  0.1.0
Set of tools to ease use of png file
Loading...
Searching...
No Matches
PColorMap.cpp File Reference
#include <stdlib.h>
#include "PColorMap.h"
+ Include dependency graph for PColorMap.cpp:

Go to the source code of this file.

Functions

PColorValue createColorValue (float value, color_t red, color_t green, color_t blue, color_t alpha)
 Create a PColorValue.
 
PColorValue createColorValue (float value, const PString &color)
 Create a PColorValue.
 
void getColorValue (color_t &red, color_t &green, color_t &blue, color_t &alpha, const PColorValue &color)
 Get the rgba values from PColorValue.
 
PColorValue phoenix_interpolateColor (const PColorValue &colorMin, const PColorValue &colorMax, float value)
 Interpolate a color with a value by respect to min an max color.
 
void phoenix_interpolateColor (PColorValue &output, const PColorValue &colorMin, const PColorValue &colorMax, float value)
 Interpolate a color with a value by respect to min an max color.
 

Function Documentation

◆ createColorValue() [1/2]

PColorValue createColorValue ( float value,
color_t red,
color_t green,
color_t blue,
color_t alpha )

Create a PColorValue.

Parameters
value: associated value with the given color
red: red proportion
green: green proportion
blue: blue proportion
alpha: transparent proportion
Returns
PColorValue

Definition at line 45 of file PColorMap.cpp.

45 {
46 PColorValue colorValue;
47 colorValue.value = value;
48 colorValue.r = red;
49 colorValue.g = green;
50 colorValue.b = blue;
51 colorValue.a = alpha;
52 return colorValue;
53}
Color related to a value.
Definition PColorMap.h:17
color_t r
Red channel.
Definition PColorMap.h:21
color_t g
Green channel.
Definition PColorMap.h:23
float value
Value of the color.
Definition PColorMap.h:19
color_t a
Alpha channel.
Definition PColorMap.h:27
color_t b
Blue channel.
Definition PColorMap.h:25

References PColorValue::a, PColorValue::b, PColorValue::g, PColorValue::r, and PColorValue::value.

◆ createColorValue() [2/2]

PColorValue createColorValue ( float value,
const PString & color )

Create a PColorValue.

Parameters
value: associated value with the given color
color: associated color
Returns
PColorValue

Definition at line 15 of file PColorMap.cpp.

15 {
16 size_t nbChannel(color.size());
17 color_t red(0), green(0), blue(0), alpha(0);
18 if(nbChannel >= 2lu){
19 PString redHex(color.substr(0lu, 2lu));
20 red = (color_t)strtol(redHex.c_str(), NULL, 16);
21 }
22 if(nbChannel >= 4lu){
23 PString greenHex(color.substr(2lu, 2lu));
24 green = (color_t)strtol(greenHex.c_str(), NULL, 16);
25 }
26 if(nbChannel >= 6lu){
27 PString blueHex(color.substr(4lu, 2lu));
28 blue = (color_t)strtol(blueHex.c_str(), NULL, 16);
29 }
30 if(nbChannel >= 8lu){
31 PString alphaHex(color.substr(6lu, 2lu));
32 alpha = (color_t)strtol(alphaHex.c_str(), NULL, 16);
33 }
34 return createColorValue(value, red, green, blue, alpha);
35}
PColorValue createColorValue(float value, const PString &color)
Create a PColorValue.
Definition PColorMap.cpp:15
unsigned char color_t
Type des of a color.
Definition PColorMap.h:14

References createColorValue().

Referenced by PColorMap::addColor(), PColorMap::addColor(), and createColorValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColorValue()

void getColorValue ( color_t & red,
color_t & green,
color_t & blue,
color_t & alpha,
const PColorValue & color )

Get the rgba values from PColorValue.

Parameters
[out]red: red proportion
[out]green: green proportion
[out]blue: blue proportion
[out]alpha: transparent proportion
color: given color

Definition at line 62 of file PColorMap.cpp.

62 {
63 red = color.r;
64 green = color.g;
65 blue = color.b;
66 alpha = color.a;
67}

References PColorValue::a, PColorValue::b, PColorValue::g, and PColorValue::r.

◆ phoenix_interpolateColor() [1/2]

PColorValue phoenix_interpolateColor ( const PColorValue & colorMin,
const PColorValue & colorMax,
float value )

Interpolate a color with a value by respect to min an max color.

Parameters
colorMin: color of the minimum value
colorMax: color of the maximum value
value: value between min and max
Returns
interpolated color

Definition at line 90 of file PColorMap.cpp.

90 {
91 PColorValue out;
92 phoenix_interpolateColor(out, colorMin, colorMax, value);
93 return out;
94}
void phoenix_interpolateColor(PColorValue &output, const PColorValue &colorMin, const PColorValue &colorMax, float value)
Interpolate a color with a value by respect to min an max color.
Definition PColorMap.cpp:75

References phoenix_interpolateColor().

+ Here is the call graph for this function:

◆ phoenix_interpolateColor() [2/2]

void phoenix_interpolateColor ( PColorValue & output,
const PColorValue & colorMin,
const PColorValue & colorMax,
float value )

Interpolate a color with a value by respect to min an max color.

Parameters
[out]output: interpolated color
colorMin: color of the minimum value
colorMax: color of the maximum value
value: value between min and max

Definition at line 75 of file PColorMap.cpp.

75 {
76 float ratio((value - colorMin.value)/(colorMax.value - colorMin.value));
77
78 output.r = colorMax.r*ratio + colorMin.r*(1.0f - ratio);
79 output.g = colorMax.g*ratio + colorMin.g*(1.0f - ratio);
80 output.b = colorMax.b*ratio + colorMin.b*(1.0f - ratio);
81 output.a = colorMax.a*ratio + colorMin.a*(1.0f - ratio);
82}

References PColorValue::a, PColorValue::b, PColorValue::g, PColorValue::r, and PColorValue::value.

Referenced by PColorMap::interpolate(), and phoenix_interpolateColor().

+ Here is the caller graph for this function: