Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, 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/images.hpp" | ||
30 | #include "gate/memalloc.hpp" | ||
31 | #include "gate/results.hpp" | ||
32 | #include "gate/exceptions.hpp" | ||
33 | |||
34 | namespace gate | ||
35 | { | ||
36 | namespace graph | ||
37 | { | ||
38 | |||
39 | ✗ | RasterImage::RasterImage(gate_rasterimage_t const* image_to_duplicate) | |
40 | { | ||
41 | ✗ | gate_rasterimage_duplicate(&this->impl_instance, image_to_duplicate); | |
42 | ✗ | } | |
43 | |||
44 | 10 | RasterImage::RasterImage(unsigned width, unsigned height, PixelFormat format) | |
45 | { | ||
46 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (NULL == gate_rasterimage_create(&this->impl_instance, (uint16_t)format, width, height, NULL)) |
47 | { | ||
48 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
49 | } | ||
50 | 10 | } | |
51 | ✗ | RasterImage::RasterImage(PixelFormat convertToFormat, RasterImage const& fromSource) | |
52 | { | ||
53 | ✗ | if (NULL == gate_rasterimage_convert(&this->impl_instance, convertToFormat, fromSource.c_impl())) | |
54 | { | ||
55 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
56 | } | ||
57 | ✗ | } | |
58 | |||
59 | 2 | RasterImage::RasterImage(RasterImage const& src) | |
60 | { | ||
61 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (NULL == gate_rasterimage_duplicate(&this->impl_instance, &src.impl_instance)) |
62 | { | ||
63 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
64 | } | ||
65 | 2 | } | |
66 | 2 | RasterImage& RasterImage::operator=(RasterImage const& src) | |
67 | { | ||
68 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | RasterImage that(src); |
69 | 2 | this->swap(that); | |
70 | 4 | return *this; | |
71 | } | ||
72 | 24 | RasterImage::~RasterImage() noexcept | |
73 | { | ||
74 | 12 | gate_rasterimage_release(&this->impl_instance); | |
75 | 12 | } | |
76 | |||
77 | 2 | void RasterImage::swap(RasterImage& that) noexcept | |
78 | { | ||
79 | 2 | gate::swapRefsNoExcept(this->impl_instance, that.impl_instance); | |
80 | 2 | } | |
81 | 3 | gate_rasterimage_t* RasterImage::c_impl() | |
82 | { | ||
83 | 3 | return &this->impl_instance; | |
84 | } | ||
85 | 2 | gate_rasterimage_t const* RasterImage::c_impl() const | |
86 | { | ||
87 | 2 | return &this->impl_instance; | |
88 | } | ||
89 | ✗ | bool_t RasterImage::empty() const | |
90 | { | ||
91 | ✗ | return gate_rasterimage_is_empty(&this->impl_instance); | |
92 | } | ||
93 | |||
94 | ✗ | bool_t RasterImage::operator!() const | |
95 | { | ||
96 | ✗ | return this->empty(); | |
97 | } | ||
98 | |||
99 | ✗ | RasterImage::PixelFormat RasterImage::getPixelFormat() const | |
100 | { | ||
101 | ✗ | return (PixelFormat)this->impl_instance.pixel_format; | |
102 | } | ||
103 | |||
104 | ✗ | unsigned RasterImage::getWidth() const | |
105 | { | ||
106 | ✗ | return gate_rasterimage_width(&this->impl_instance); | |
107 | } | ||
108 | ✗ | unsigned RasterImage::getHeight() const | |
109 | { | ||
110 | ✗ | return gate_rasterimage_height(&this->impl_instance); | |
111 | } | ||
112 | |||
113 | ✗ | void RasterImage::setPixel(unsigned x, unsigned y, Color const& color) | |
114 | { | ||
115 | ✗ | gate_result_t result = gate_rasterimage_set_pixel(&this->impl_instance, x, y, &color.value); | |
116 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
117 | ✗ | } | |
118 | ✗ | void RasterImage::setPixel(unsigned x, unsigned y, gate_color_t const& color) | |
119 | { | ||
120 | ✗ | gate_result_t result = gate_rasterimage_set_pixel(&this->impl_instance, x, y, &color); | |
121 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
122 | ✗ | } | |
123 | |||
124 | ✗ | Color RasterImage::getPixel(unsigned x, unsigned y) const | |
125 | { | ||
126 | ✗ | Color ret; | |
127 | ✗ | gate_result_t result = gate_rasterimage_get_pixel(&this->impl_instance, x, y, ret.c_impl()); | |
128 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
129 | ✗ | return ret; | |
130 | } | ||
131 | ✗ | void RasterImage::getPixel(unsigned x, unsigned y, gate_color_t& color) | |
132 | { | ||
133 | ✗ | gate_result_t result = gate_rasterimage_get_pixel(&this->impl_instance, x, y, &color); | |
134 | ✗ | if (GATE_FAILED(result)) | |
135 | { | ||
136 | ✗ | color.rgba = 0; | |
137 | } | ||
138 | ✗ | } | |
139 | |||
140 | ✗ | void* RasterImage::getPixelPtr(unsigned x, unsigned y) | |
141 | { | ||
142 | ✗ | return gate_rasterimage_get_pixel_ptr(&this->impl_instance, x, y); | |
143 | } | ||
144 | ✗ | void const* RasterImage::getPixelPtr(unsigned x, unsigned y) const | |
145 | { | ||
146 | ✗ | return gate_rasterimage_get_pixel_ptr(&this->impl_instance, x, y); | |
147 | } | ||
148 | |||
149 | ✗ | void RasterImage::makeGrayscale() | |
150 | { | ||
151 | ✗ | result_t result = gate_rasterimage_to_grayscale(&this->impl_instance); | |
152 | ✗ | GATEXX_CHECK_ERROR(result); | |
153 | ✗ | } | |
154 | ✗ | void RasterImage::makeMonochrome() | |
155 | { | ||
156 | ✗ | result_t result = gate_rasterimage_to_monochrome(&this->impl_instance); | |
157 | ✗ | GATEXX_CHECK_ERROR(result); | |
158 | ✗ | } | |
159 | 1 | void RasterImage::clear(Color const& col) | |
160 | { | ||
161 | 1 | result_t result = gate_rasterimage_clear(&this->impl_instance, col.c_impl()); | |
162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
163 | 1 | } | |
164 | ✗ | void RasterImage::resampleFrom(RasterImage const& src) | |
165 | { | ||
166 | ✗ | result_t result = gate_rasterimage_resample(&this->impl_instance, &src.impl_instance); | |
167 | ✗ | GATEXX_CHECK_ERROR(result); | |
168 | ✗ | } | |
169 | ✗ | void RasterImage::paste(RasterImage const& src, int dstX, int dstY, int srcX, int srcY, int width, int height, bool transparent) | |
170 | { | ||
171 | ✗ | result_t result = gate_rasterimage_paste_image(&this->impl_instance, &src.impl_instance, | |
172 | dstX, dstY, srcX, srcY, width, height, transparent); | ||
173 | ✗ | GATEXX_CHECK_ERROR(result); | |
174 | ✗ | } | |
175 | |||
176 | |||
177 | ✗ | RasterImage RasterImage::copy() const | |
178 | { | ||
179 | ✗ | RasterImage ret; | |
180 | ✗ | if (NULL == gate_rasterimage_copy(&ret.impl_instance, &this->impl_instance)) | |
181 | { | ||
182 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
183 | } | ||
184 | ✗ | return ret; | |
185 | } | ||
186 | ✗ | RasterImage RasterImage::subset(unsigned x, unsigned y, unsigned width, unsigned height) const | |
187 | { | ||
188 | ✗ | RasterImage ret; | |
189 | ✗ | result_t result = gate_rasterimage_subset(&ret.impl_instance, &this->impl_instance, x, y, width, height); | |
190 | ✗ | GATEXX_CHECK_ERROR(result); | |
191 | ✗ | return ret; | |
192 | } | ||
193 | 1 | RasterImage RasterImage::rotateLeft() const | |
194 | { | ||
195 | 1 | RasterImage new_image; | |
196 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_rasterimage_rotate_left(&new_image.impl_instance, &this->impl_instance); |
197 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
198 | 1 | return new_image; | |
199 | } | ||
200 | 1 | RasterImage RasterImage::rotateRight() const | |
201 | { | ||
202 | 1 | RasterImage new_image; | |
203 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_rasterimage_rotate_right(&new_image.impl_instance, &this->impl_instance); |
204 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
205 | 1 | return new_image; | |
206 | } | ||
207 | 1 | RasterImage RasterImage::rollOver() const | |
208 | { | ||
209 | 1 | RasterImage new_image; | |
210 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_rasterimage_roll_over(&new_image.impl_instance, &this->impl_instance); |
211 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
212 | 1 | return new_image; | |
213 | } | ||
214 | 1 | RasterImage RasterImage::flipX() const | |
215 | { | ||
216 | 1 | RasterImage new_image; | |
217 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_rasterimage_flip_x(&new_image.impl_instance, &this->impl_instance); |
218 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
219 | 1 | return new_image; | |
220 | } | ||
221 | 1 | RasterImage RasterImage::flipY() const | |
222 | { | ||
223 | 1 | RasterImage new_image; | |
224 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_rasterimage_flip_y(&new_image.impl_instance, &this->impl_instance); |
225 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
226 | 1 | return new_image; | |
227 | } | ||
228 | |||
229 | } // end of namespace graph | ||
230 | } // end of namespace gate | ||
231 |