GCC Code Coverage Report


Directory: ./
File: src/PColorMap.cpp
Date: 2025-09-08 17:09:06
Exec Total Coverage
Lines: 98 98 100.0%
Functions: 16 17 94.1%
Branches: 38 42 90.5%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include <stdlib.h>
8 #include "PColorMap.h"
9
10 ///Create a PColorValue
11 /** @param value : associated value with the given color
12 * @param color : associated color
13 * @return PColorValue
14 */
15 25 PColorValue createColorValue(float value, const PString & color){
16 25 size_t nbChannel(color.size());
17 25 color_t red(0), green(0), blue(0), alpha(0);
18
1/2
✓ Branch 0 (3→4) taken 25 times.
✗ Branch 1 (3→11) not taken.
25 if(nbChannel >= 2lu){
19
2/2
✓ Branch 0 (4→5) taken 25 times.
✓ Branch 2 (5→6) taken 25 times.
25 PString redHex(color.substr(0lu, 2lu));
20 25 red = (color_t)strtol(redHex.c_str(), NULL, 16);
21 25 }
22
1/2
✓ Branch 0 (11→12) taken 25 times.
✗ Branch 1 (11→19) not taken.
25 if(nbChannel >= 4lu){
23
2/2
✓ Branch 0 (12→13) taken 25 times.
✓ Branch 2 (13→14) taken 25 times.
25 PString greenHex(color.substr(2lu, 2lu));
24 25 green = (color_t)strtol(greenHex.c_str(), NULL, 16);
25 25 }
26
1/2
✓ Branch 0 (19→20) taken 25 times.
✗ Branch 1 (19→27) not taken.
25 if(nbChannel >= 6lu){
27
2/2
✓ Branch 0 (20→21) taken 25 times.
✓ Branch 2 (21→22) taken 25 times.
25 PString blueHex(color.substr(4lu, 2lu));
28 25 blue = (color_t)strtol(blueHex.c_str(), NULL, 16);
29 25 }
30
2/2
✓ Branch 0 (27→28) taken 20 times.
✓ Branch 1 (27→35) taken 5 times.
25 if(nbChannel >= 8lu){
31
2/2
✓ Branch 0 (28→29) taken 20 times.
✓ Branch 2 (29→30) taken 20 times.
20 PString alphaHex(color.substr(6lu, 2lu));
32 20 alpha = (color_t)strtol(alphaHex.c_str(), NULL, 16);
33 20 }
34 25 return createColorValue(value, red, green, blue, alpha);
35 }
36
37 ///Create a PColorValue
38 /** @param value : associated value with the given color
39 * @param red : red proportion
40 * @param green : green proportion
41 * @param blue : blue proportion
42 * @param alpha : transparent proportion
43 * @return PColorValue
44 */
45 27 PColorValue createColorValue(float value, color_t red, color_t green, color_t blue, color_t alpha){
46 PColorValue colorValue;
47 27 colorValue.value = value;
48 27 colorValue.r = red;
49 27 colorValue.g = green;
50 27 colorValue.b = blue;
51 27 colorValue.a = alpha;
52 27 return colorValue;
53 }
54
55 ///Get the rgba values from PColorValue
56 /** @param[out] red : red proportion
57 * @param[out] green : green proportion
58 * @param[out] blue : blue proportion
59 * @param[out] alpha : transparent proportion
60 * @param color : given color
61 */
62 307200 void getColorValue(color_t & red, color_t & green, color_t & blue, color_t & alpha, const PColorValue & color){
63 307200 red = color.r;
64 307200 green = color.g;
65 307200 blue = color.b;
66 307200 alpha = color.a;
67 307200 }
68
69 ///Interpolate a color with a value by respect to min an max color
70 /** @param[out] output : interpolated color
71 * @param colorMin : color of the minimum value
72 * @param colorMax : color of the maximum value
73 * @param value : value between min and max
74 */
75 1072800 void phoenix_interpolateColor(PColorValue & output, const PColorValue & colorMin, const PColorValue & colorMax, float value){
76 1072800 float ratio((value - colorMin.value)/(colorMax.value - colorMin.value));
77
78 1072800 output.r = colorMax.r*ratio + colorMin.r*(1.0f - ratio);
79 1072800 output.g = colorMax.g*ratio + colorMin.g*(1.0f - ratio);
80 1072800 output.b = colorMax.b*ratio + colorMin.b*(1.0f - ratio);
81 1072800 output.a = colorMax.a*ratio + colorMin.a*(1.0f - ratio);
82 1072800 }
83
84 ///Interpolate a color with a value by respect to min an max color
85 /** @param colorMin : color of the minimum value
86 * @param colorMax : color of the maximum value
87 * @param value : value between min and max
88 * @return interpolated color
89 */
90 307200 PColorValue phoenix_interpolateColor(const PColorValue & colorMin, const PColorValue & colorMax, float value){
91 PColorValue out;
92
1/1
✓ Branch 0 (2→3) taken 307200 times.
307200 phoenix_interpolateColor(out, colorMin, colorMax, value);
93 307200 return out;
94 }
95
96 ///Default constructor of PColorMap
97 5 PColorMap::PColorMap(){
98
1/1
✓ Branch 0 (3→4) taken 5 times.
5 initialisationPColorMap();
99 5 }
100
101 ///Copy constructor of PColorMap
102 /** @param other : class to copy
103 */
104 1 PColorMap::PColorMap(const PColorMap & other){
105
1/1
✓ Branch 0 (3→4) taken 1 times.
1 copyPColorMap(other);
106 1 }
107
108 ///Destructor of PColorMap
109 6 PColorMap::~PColorMap(){
110
111 6 }
112
113 ///Definition of equal operator of PColorMap
114 /** @param other : class to copy
115 * @return copied class
116 */
117 1 PColorMap & PColorMap::operator = (const PColorMap & other){
118 1 copyPColorMap(other);
119 1 return *this;
120 }
121
122 ///Add a color in the PColorMap
123 /** @param value : associated value with the given color
124 * @param color : hexadecimal color associated to the given value (FF000000, 00FF0000, 0000FF00, 000000FF, etc)
125 */
126 23 void PColorMap::addColor(float value, const PString & color){
127
1/1
✓ Branch 0 (2→3) taken 23 times.
23 PColorValue colorValue = createColorValue(value, color);
128
1/1
✓ Branch 0 (3→4) taken 23 times.
23 p_mapColor[value] = colorValue;
129 23 }
130
131 ///Add a color in the PColorMap
132 /** @param value : associated value with the given color
133 * @param red : red proportion
134 * @param green : green proportion
135 * @param blue : blue proportion
136 * @param alpha : transparent proportion
137 */
138 2 void PColorMap::addColor(float value, color_t red, color_t green, color_t blue, color_t alpha){
139
1/1
✓ Branch 0 (2→3) taken 2 times.
2 PColorValue colorValue = createColorValue(value, red, green, blue, alpha);
140
1/1
✓ Branch 0 (3→4) taken 2 times.
2 p_mapColor[value] = colorValue;
141 2 }
142
143 ///Interpolate color by respect to the given value
144 /** @param[out] red : red proportion
145 * @param[out] green : green proportion
146 * @param[out] blue : blue proportion
147 * @param value : given value
148 */
149 307200 void PColorMap::interpolate(color_t & red, color_t & green, color_t & blue, float value) const{
150 PColorValue out;
151
1/1
✓ Branch 0 (2→3) taken 307200 times.
307200 interpolate(out, value);
152 307200 red = out.r;
153 307200 green = out.g;
154 307200 blue = out.b;
155 307200 }
156
157 ///Interpolate color by respect to the given value
158 /** @param[out] red : red proportion
159 * @param[out] green : green proportion
160 * @param[out] blue : blue proportion
161 * @param[out] alpha : transparent proportion
162 * @param value : given value
163 */
164 614400 void PColorMap::interpolate(color_t & red, color_t & green, color_t & blue, color_t & alpha, float value) const{
165 PColorValue out;
166
1/1
✓ Branch 0 (2→3) taken 614400 times.
614400 interpolate(out, value);
167 614400 red = out.r;
168 614400 green = out.g;
169 614400 blue = out.b;
170 614400 alpha = out.a;
171 614400 }
172
173 ///Interpolate color by respect to the given value
174 /** @param[out] output : output color
175 * @param value : given value
176 */
177 921600 void PColorMap::interpolate(PColorValue & output, float value) const{
178
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 921600 times.
987600 if(p_mapColor.size() == 0lu){return;} //No color
179 921600 PMapColorValue::const_iterator itMin(p_mapColor.begin());
180
2/2
✓ Branch 0 (7→8) taken 24000 times.
✓ Branch 1 (7→10) taken 897600 times.
921600 if(value <= itMin->second.value){ //If the value is smaller than the first colored one
181 24000 output = itMin->second; //We copy this value
182 24000 return;
183 }
184 897600 PMapColorValue::const_reverse_iterator rit(p_mapColor.rbegin());
185
3/3
✓ Branch 0 (11→12) taken 897600 times.
✓ Branch 2 (12→13) taken 42000 times.
✓ Branch 3 (12→15) taken 855600 times.
897600 if(value >= rit->second.value){ //If the value is greater than the last colored one
186
1/1
✓ Branch 0 (13→14) taken 42000 times.
42000 output = rit->second; //We copy this value
187 42000 return;
188 }
189 855600 PMapColorValue::const_iterator itMax(itMin);
190 855600 ++itMax;
191
2/2
✓ Branch 0 (32→17) taken 3025800 times.
✓ Branch 1 (32→33) taken 90000 times.
3115800 while(itMax != p_mapColor.end()){
192
6/6
✓ Branch 0 (18→19) taken 2794800 times.
✓ Branch 1 (18→22) taken 231000 times.
✓ Branch 2 (20→21) taken 765600 times.
✓ Branch 3 (20→22) taken 2029200 times.
✓ Branch 4 (23→24) taken 765600 times.
✓ Branch 5 (23→28) taken 2260200 times.
3025800 if(value > itMin->second.value && value < itMax->second.value){
193
1/1
✓ Branch 0 (26→27) taken 765600 times.
765600 phoenix_interpolateColor(output, itMin->second, itMax->second, value);
194 765600 break;
195 }
196 2260200 ++itMax;
197 2260200 ++itMin;
198 }
199 }
200
201 ///Copy function of PColorMap
202 /** @param other : class to copy
203 */
204 2 void PColorMap::copyPColorMap(const PColorMap & other){
205 2 p_mapColor = other.p_mapColor;
206 2 }
207
208 ///Initialisation function of the class PColorMap
209 5 void PColorMap::initialisationPColorMap(){
210
211 5 }
212
213
214
215
216
217