GCC Code Coverage Report


Directory: src/gate/
File: src/gate/graphics/cxx_colors.cpp
Date: 2026-06-21 00:38:37
Exec Total Coverage
Lines: 97 129 75.2%
Functions: 34 41 82.9%
Branches: 8 28 28.6%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/graphics/colors.hpp"
30 #include "gate/exceptions.hpp"
31 #include "gate/results.hpp"
32
33 namespace gate
34 {
35 namespace graph
36 {
37
38 11 Color::Color(uint32_t rgba)
39 {
40 11 this->value.bits = rgba;
41
42 11 }
43 53 Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
44 {
45 53 this->value.r = r;
46 53 this->value.g = g;
47 53 this->value.b = b;
48 53 this->value.a = a;
49 53 }
50 1 Color::Color(gate_color_t const& col)
51 1 : value(col)
52 {
53 1 }
54
55 3 Color::Color(gate_color_rgb_t const& src)
56 {
57 3 this->value.r = src.r;
58 3 this->value.g = src.g;
59 3 this->value.b = src.b;
60 3 this->value.a = 255;
61 3 }
62
63 1 Color& Color::operator=(gate_color_t const& src)
64 {
65 1 this->value = src;
66 1 return *this;
67 }
68 Color& Color::operator=(gate_color_rgb_t const& src)
69 {
70 this->value.r = src.r;
71 this->value.g = src.g;
72 this->value.b = src.b;
73 this->value.a = 255;
74 return *this;
75 }
76
77
78 1 gate_color_t* Color::c_impl()
79 {
80 1 return &this->value;
81 }
82 22 gate_color_t const* Color::c_impl() const
83 {
84 22 return &this->value;
85 }
86
87 gate_color_t* Color::operator->()
88 {
89 return &this->value;
90 }
91 6 gate_color_t const* Color::operator->() const
92 {
93 6 return &this->value;
94 }
95
96
97
98 1 void Color::setOpaque(Color const& color)
99 {
100 1 gate_color_set_opaque(&this->value, &color.value);
101 1 }
102 1 void Color::setOpaque(gate_color_t const& color)
103 {
104 1 gate_color_set_opaque(&this->value, &color);
105
106 1 }
107
108 1 void Color::setTransparent(Color const& color)
109 {
110 1 gate_color_set_transparent(&this->value, &color.value);
111 1 }
112 1 void Color::setTransparent(gate_color_t const& color)
113 {
114 1 gate_color_set_transparent(&this->value, &color);
115 1 }
116
117 5 bool_t Color::operator==(Color const& src) const
118 {
119 5 return this->value.bits == src.value.bits;
120 }
121 1 bool_t Color::operator!=(Color const& src) const
122 {
123 1 return this->value.bits != src.value.bits;
124 }
125 3 bool_t Color::operator< (Color const& src) const
126 {
127 3 return this->value.bits < src.value.bits;
128 }
129 5 bool_t Color::operator<=(Color const& src) const
130 {
131 5 return this->value.bits <= src.value.bits;
132 }
133 2 bool_t Color::operator> (Color const& src) const
134 {
135 2 return src < *this;
136 }
137 3 bool_t Color::operator>=(Color const& src) const
138 {
139 3 return src <= *this;
140 }
141
142
143 4 Color Color::parseHex(String const& text)
144 {
145 4 Color ret;
146
2/4
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
4 if (0 == gate_color_parse_hex(text.c_str(), text.length(), &ret.value))
147 {
148 GATEXX_RAISE_EXCEPTION(results::InvalidData, "Failed to parse hex color", 0);
149 }
150 4 return ret;
151 }
152
153 Color const Color::Black = Color(0x00, 0x00, 0x00);
154 Color const Color::Blue = Color(0x00, 0x00, 0x99);
155 Color const Color::Green = Color(0x00, 0x99, 0x00);
156 Color const Color::Cyan = Color(0x00, 0x99, 0x99);
157 Color const Color::Red = Color(0x99, 0x00, 0x00);
158 Color const Color::Magenta = Color(0x99, 0x00, 0x99);
159 Color const Color::Brown = Color(0x99, 0x66, 0x33);
160 Color const Color::LightGray = Color(0x99, 0x99, 0x99);
161 Color const Color::DarkGray = Color(0x66, 0x66, 0x66);
162 Color const Color::BrightBlue = Color(0x66, 0x66, 0xff);
163 Color const Color::BrightGreen = Color(0x66, 0xff, 0x66);
164 Color const Color::BrightCyan = Color(0x66, 0xff, 0xff);
165 Color const Color::BrightRed = Color(0xff, 0x66, 0x66);
166 Color const Color::BrightMagenta = Color(0xff, 0x66, 0xff);
167 Color const Color::Yellow = Color(0xff, 0xff, 0x66);
168 Color const Color::White = Color(0xff, 0xff, 0xff);
169
170
171
172 528 ColorRGB::ColorRGB(uint8_t r, uint8_t g , uint8_t b)
173 {
174 528 this->r = r;
175 528 this->g = g;
176 528 this->b = b;
177 528 }
178 ColorRGB::ColorRGB(gate_color_rgb_t const& src)
179 : gate_color_rgb_t(src)
180 {
181 }
182 6 ColorRGB::ColorRGB(Color const& src)
183 {
184 6 this->r = src.value.r;
185 6 this->g = src.value.g;
186 6 this->b = src.value.b;
187 6 }
188
189 1 ColorRGB::ColorRGB(gate_color_t const& src)
190 {
191 1 this->r = src.r;
192 1 this->g = src.g;
193 1 this->b = src.b;
194 1 }
195 ColorRGB& ColorRGB::operator=(gate_color_rgb_t const& src)
196 {
197 static_cast<gate_color_rgb_t&>(*this) = src;
198 return *this;
199 }
200 ColorRGB& ColorRGB::operator=(gate_color_t const& src)
201 {
202 this->r = src.r;
203 this->g = src.g;
204 this->b = src.b;
205 return *this;
206 }
207 4 bool_t ColorRGB::operator==(ColorRGB const& src) const
208 {
209
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
4 return this->r == src.r && this->g == src.g && this->b == src.b;
210 }
211 1 bool_t ColorRGB::operator!=(ColorRGB const& src) const
212 {
213 1 return !((*this) == src);
214 }
215 1 bool_t ColorRGB::operator< (ColorRGB const& src) const
216 {
217
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this->r < src.r) return true;
218 if (this->r > src.r) return false;
219 if (this->g < src.g) return true;
220 if (this->g > src.g) return false;
221 return this->b < src.b;
222 }
223 1 bool_t ColorRGB::operator<=(ColorRGB const& src) const
224 {
225
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this->r < src.r) return true;
226 if (this->r > src.r) return false;
227 if (this->g < src.g) return true;
228 if (this->g > src.g) return false;
229 return this->b <= src.b;
230 }
231 bool_t ColorRGB::operator> (ColorRGB const& src) const
232 {
233 return src < *this;
234 }
235 bool_t ColorRGB::operator>=(ColorRGB const& src) const
236 {
237 return src <= *this;
238 }
239
240
241
242 2 size_t ColorPalette::find(ColorRGB findColor, ColorRGB const* palette, size_t paletteLength)
243 {
244 2 return gate_color_palette_rgb8_resolve(findColor, palette, paletteLength);
245 }
246
247 1 void ColorPalette::createRGB4Palette(ColorRGB palette[16])
248 {
249 1 gate_color_palette_rgb4_create(palette);
250 1 }
251
252 1 void ColorPalette::createRGB8Palette(ColorRGB palette[256])
253 {
254 1 gate_color_palette_rgb8_create(palette);
255 1 }
256
257 256 void ColorPalette::loadRGB8Index(uint8_t ndx, ColorRGB& colRgb)
258 {
259 256 gate_color_palette_rgb8_from_index(ndx, &colRgb);
260 256 }
261
262 1 uint8_t ColorPalette::resolveRGB8Index(ColorRGB color)
263 {
264 1 return gate_color_palette_rgb8_index_from_color(color);
265 }
266
267
268
269 1 size_t ColorCodec::loadRgb24(gate_color_t* pixels, size_t pixelsCount, void const* sourceRgb24)
270 {
271 1 return gate_color_load_rgb_24(pixels, pixelsCount, sourceRgb24);
272 }
273 1 size_t ColorCodec::loadRgb32(gate_color_t* pixels, size_t pixelsCount, void const* sourceRgb32)
274 {
275 1 return gate_color_load_rgb_32(pixels, pixelsCount, sourceRgb32);
276 }
277 65025 size_t ColorCodec::loadYuv2(gate_color_t* pixels, size_t pixelsCount, void const* sourceYuv2)
278 {
279 65025 return gate_color_load_yuv2_16(pixels, pixelsCount, sourceYuv2);
280 }
281
282
283
284 } // end of namespace graph
285 } // end of namespace gate
286