GCC Code Coverage Report


Directory: ./
File: lib/geogram/image/image.cpp
Date: 2026-09-07 02:28:19
Exec Total Coverage
Lines: 0 77 0.0%
Functions: 0 8 0.0%
Branches: 0 38 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/image.h>
41
42 namespace GEO {
43
44 //_________________________________________________________
45
46 size_t Image::nb_components(ColorEncoding color_rep) {
47 size_t result = 0;
48 switch(color_rep) {
49 case GRAY:
50 case INDEXED:
51 result = 1;
52 break;
53 case RGB:
54 case BGR:
55 case YUV:
56 result = 3;
57 break;
58 case RGBA:
59 result = 4;
60 break;
61 }
62 return result;
63 }
64
65 size_t Image::bytes_per_component(ComponentEncoding component_rep) {
66 size_t result = 0;
67 switch(component_rep) {
68 case BYTE:
69 result = 1;
70 break;
71 case INT16:
72 result = 2;
73 break;
74 case INT32:
75 case FLOAT32:
76 result = 4;
77 break;
78 case FLOAT64:
79 result = 8;
80 break;
81 }
82 return result;
83 }
84
85 Image::Image() {
86 bytes_per_pixel_ = 0 ;
87 dimension_ = 0 ;
88 size_[0] = 0 ;
89 size_[1] = 0 ;
90 size_[2] = 0 ;
91 factor_[0] = 0 ;
92 factor_[1] = 0 ;
93 factor_[2] = 0 ;
94 base_mem_ = nullptr ;
95 }
96
97 Image::~Image() {
98 delete[] base_mem_;
99 bytes_per_pixel_ = 0 ;
100 dimension_ = 0 ;
101 size_[0] = 0 ;
102 size_[1] = 0 ;
103 size_[2] = 0 ;
104 factor_[0] = 0 ;
105 factor_[1] = 0 ;
106 factor_[2] = 0 ;
107 base_mem_ = nullptr ;
108 }
109
110 void Image::initialize(
111 ColorEncoding color_rep, ComponentEncoding component_rep,
112 index_t size_x, index_t size_y, index_t size_z
113 ) {
114 color_encoding_ = color_rep;
115 component_encoding_ = component_rep;
116 bytes_per_pixel_ =
117 nb_components(color_rep) * bytes_per_component(component_rep);
118 size_[0] = size_x ;
119 size_[1] = size_y ;
120 size_[2] = size_z ;
121 dimension_ = 3;
122 if(size_z == 1) {
123 dimension_ = 2 ;
124 if(size_y == 1) {
125 dimension_ = 1 ;
126 }
127 }
128 factor_[0] = bytes_per_pixel_ ;
129 factor_[1] = factor_[0] * size_x ;
130 factor_[2] = factor_[1] * size_y ;
131 delete[] base_mem_;
132 base_mem_ = new Memory::byte[bytes()];
133 Memory::clear(base_mem_, bytes());
134 }
135
136 void Image::acquire() {
137 }
138
139 void Image::flip_vertically() {
140 index_t bpp=index_t(bytes_per_pixel());
141 index_t h = height() ;
142 index_t w = width() ;
143 index_t row_len = w * bpp ;
144 for(index_t j=0; j< h/2; j++) {
145 // get a pointer to the two lines we will swap
146 Memory::pointer row1 = base_mem() + j * row_len ;
147 Memory::pointer row2 = base_mem() + (h - 1 - j) * row_len ;
148 // for each point on line, swap all the channels
149 for(index_t i=0; i<w; i++) {
150 for (index_t k=0;k<bpp;k++) {
151 std::swap(row1[bpp*i+k], row2[bpp*i+k]);
152 }
153 }
154 }
155 }
156
157 void Image::swap_components(index_t channel1, index_t channel2) {
158 size_t nb_comp = nb_components(color_encoding());
159 size_t bytes_per_comp = bytes_per_component(component_encoding());
160 geo_assert(channel1 < nb_comp);
161 geo_assert(channel2 < nb_comp);
162 size_t bpp = bytes_per_pixel();
163 size_t nb_pix = nb_pixels();
164 Memory::pointer pixel_base = base_mem();
165 size_t channel1_offset = bytes_per_comp*channel1;
166 size_t channel2_offset = bytes_per_comp*channel2;
167 for(size_t i=0; i<nb_pix; ++i) {
168 Memory::pointer channel1_base = pixel_base + channel1_offset;
169 Memory::pointer channel2_base = pixel_base + channel2_offset;
170 for(index_t c=0; c<bytes_per_comp; ++c) {
171 std::swap(channel1_base[c], channel2_base[c]);
172 }
173 pixel_base += bpp;
174 }
175 }
176
177
178 //_________________________________________________________
179
180 }
181