GCC Code Coverage Report


Directory: ./
File: image/colormap.cpp
Date: 2026-09-27 03:10:11
Exec Total Coverage
Lines: 0 83 0.0%
Functions: 0 7 0.0%
Branches: 0 26 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #include <geogram/image/colormap.h>
41
42 namespace GEO {
43
44 //_________________________________________________________
45
46 ✗ Colormap::Colormap(index_t size_in) : size_(size_in) {
47 ✗ cells_ = new ColorCell[size_in] ;
48 ✗ }
49
50 ✗ Colormap::~Colormap() {
51 ✗ delete[] cells_ ;
52 ✗ }
53
54
55 ✗ void Colormap::color_ramp_component(
56 index_t component,
57 index_t index1, Numeric::uint8 alpha1,
58 index_t index2, Numeric::uint8 alpha2
59 ) {
60 ✗ if(index1 == index2) {
61 ✗ color_cell(index2)[component] = alpha2 ;
62 } else {
63 ✗ int n = std::abs(int(index2) - int(index1)) ;
64 ✗ float delta = (float(alpha2) - float(alpha1)) / float(n) ;
65 int sgn = geo_sgn(int(index2) - int(index1)) ;
66 float alpha = alpha1 ;
67 int index = int(index1) ;
68 ✗ for(int i=0 ; i<=n ; i++) {
69 ✗ color_cell(index_t(index))[component] =
70 ✗ Numeric::uint8(alpha) ;
71 ✗ index += sgn ;
72 ✗ alpha += delta ;
73 }
74 }
75 ✗ }
76
77
78 ✗ void Colormap::color_ramp_rgba(
79 index_t index1, const Color& c1,
80 index_t index2, const Color& c2
81 ) {
82 ✗ if(index1 == index2) {
83 Colormap::ColorCell c(
84 ✗ Numeric::uint8(c2.r() * 255.0),
85 ✗ Numeric::uint8(c2.g() * 255.0),
86 ✗ Numeric::uint8(c2.b() * 255.0),
87 ✗ Numeric::uint8(c2.a() * 255.0)
88 ) ;
89 ✗ color_cell(index2) = c ;
90 } else {
91
92 ✗ int n = std::abs(int(index2) - int(index1)) ;
93 int sgn = geo_sgn(int(index2) - int(index1)) ;
94
95 ✗ float r = float(c1.r()) ;
96 ✗ float g = float(c1.g()) ;
97 ✗ float b = float(c1.b()) ;
98 ✗ float a = float(c1.a()) ;
99 ✗ float dr = float(c2.r() - c1.r()) / float(n) ;
100 ✗ float dg = float(c2.g() - c1.g()) / float(n) ;
101 ✗ float db = float(c2.b() - c1.b()) / float(n) ;
102 ✗ float da = float(c2.a() - c1.a()) / float(n) ;
103 int index = int(index1) ;
104
105 ✗ for(int i=0 ; i<=n ; i++) {
106 ✗ set_color(index_t(index), r, g, b, a) ;
107 ✗ index += sgn ;
108 ✗ r += dr ;
109 ✗ g += dg ;
110 ✗ b += db ;
111 ✗ a += da ;
112 }
113 }
114 ✗ }
115
116
117 ✗ void Colormap::color_ramp_rgb(
118 index_t index1, const Color& c1,
119 index_t index2, const Color& c2
120 ) {
121 ✗ if(index1 == index2) {
122 Colormap::ColorCell c(
123 ✗ Numeric::uint8(c2.r() * 255.0),
124 ✗ Numeric::uint8(c2.g() * 255.0),
125 ✗ Numeric::uint8(c2.b() * 255.0),
126 ✗ color_cell(index2).a()
127 ) ;
128 ✗ color_cell(index2) = c ;
129 } else {
130
131 ✗ int n = std::abs(int(index2) - int(index1)) ;
132 int sgn = geo_sgn(int(index2) - int(index1)) ;
133
134 ✗ float r = float(c1.r()) ;
135 ✗ float g = float(c1.g()) ;
136 ✗ float b = float(c1.b()) ;
137
138 ✗ float dr = (float(c2.r()) - float(c1.r())) / float(n);
139 ✗ float dg = (float(c2.g()) - float(c1.g())) / float(n);
140 ✗ float db = (float(c2.b()) - float(c1.b())) / float(n);
141 int index = int(index1) ;
142
143 ✗ for(int i=0 ; i<=n ; i++) {
144 ✗ set_color(index_t(index), r, g, b) ;
145 ✗ index += sgn ;
146 ✗ r += dr ;
147 ✗ g += dg ;
148 ✗ b += db ;
149 }
150 }
151 ✗ }
152
153
154 ✗ void Colormap::set_color(index_t index, float r, float g, float b) {
155 ✗ r *= 255.0f ;
156 ✗ g *= 255.0f ;
157 ✗ b *= 255.0f ;
158 geo_clamp(r, float(0), float(255)) ;
159 geo_clamp(g, float(0), float(255)) ;
160 geo_clamp(b, float(0), float(255)) ;
161 Colormap::ColorCell c = Colormap::ColorCell(
162 ✗ Numeric::uint8(r),
163 ✗ Numeric::uint8(g),
164 ✗ Numeric::uint8(b),
165 ✗ color_cell(index).a()
166 ) ;
167 ✗ color_cell(index) = c ;
168 ✗ }
169
170 ✗ void Colormap::set_color(
171 index_t index, float r, float g, float b, float a
172 ) {
173 ✗ r *= 255.0f ;
174 ✗ g *= 255.0f ;
175 ✗ b *= 255.0f ;
176 ✗ a *= 255.0f ;
177 geo_clamp(r, float(0), float(255)) ;
178 geo_clamp(g, float(0), float(255)) ;
179 geo_clamp(b, float(0), float(255)) ;
180 geo_clamp(a, float(0), float(255)) ;
181 Colormap::ColorCell c = Colormap::ColorCell(
182 ✗ Numeric::uint8(r),
183 ✗ Numeric::uint8(g),
184 ✗ Numeric::uint8(b),
185 ✗ Numeric::uint8(a)
186 ) ;
187 ✗ color_cell(index) = c ;
188 ✗ }
189
190
191 //_________________________________________________________
192
193 }
194