| 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/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 | 1 | RasterImage::RasterImage(gate_rasterimage_t const* image_to_duplicate) | |
| 40 | { | ||
| 41 | 1 | gate_rasterimage_duplicate(&this->impl_instance, image_to_duplicate); | |
| 42 | 1 | } | |
| 43 | |||
| 44 | 44 | RasterImage::RasterImage(unsigned width, unsigned height, PixelFormat format) | |
| 45 | { | ||
| 46 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
|
44 | if (NULL == gate_rasterimage_create(&this->impl_instance, (uint16_t)format, width, height, NULL)) |
| 47 | { | ||
| 48 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 49 | } | ||
| 50 | 44 | } | |
| 51 | 12 | RasterImage::RasterImage(PixelFormat convertToFormat, RasterImage const& fromSource) | |
| 52 | { | ||
| 53 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
|
12 | if (NULL == gate_rasterimage_convert(&this->impl_instance, convertToFormat, fromSource.c_impl())) |
| 54 | { | ||
| 55 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 56 | } | ||
| 57 | 12 | } | |
| 58 | |||
| 59 | 3 | RasterImage::RasterImage(RasterImage const& src) | |
| 60 | { | ||
| 61 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (NULL == gate_rasterimage_duplicate(&this->impl_instance, &src.impl_instance)) |
| 62 | { | ||
| 63 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 64 | } | ||
| 65 | 3 | } | |
| 66 | 3 | RasterImage& RasterImage::operator=(RasterImage const& src) | |
| 67 | { | ||
| 68 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | RasterImage that(src); |
| 69 | 3 | this->swap(that); | |
| 70 | 6 | return *this; | |
| 71 | } | ||
| 72 | 120 | RasterImage::~RasterImage() noexcept | |
| 73 | { | ||
| 74 | 60 | gate_rasterimage_release(&this->impl_instance); | |
| 75 | 60 | } | |
| 76 | |||
| 77 | 13 | void RasterImage::swap(RasterImage& that) noexcept | |
| 78 | { | ||
| 79 | 13 | gate::swapRefsNoExcept(this->impl_instance, that.impl_instance); | |
| 80 | 13 | } | |
| 81 | 27 | gate_rasterimage_t* RasterImage::c_impl() | |
| 82 | { | ||
| 83 | 27 | return &this->impl_instance; | |
| 84 | } | ||
| 85 | 29 | gate_rasterimage_t const* RasterImage::c_impl() const | |
| 86 | { | ||
| 87 | 29 | return &this->impl_instance; | |
| 88 | } | ||
| 89 | 6 | bool_t RasterImage::empty() const | |
| 90 | { | ||
| 91 | 6 | return gate_rasterimage_is_empty(&this->impl_instance); | |
| 92 | } | ||
| 93 | |||
| 94 | 1 | bool_t RasterImage::operator!() const | |
| 95 | { | ||
| 96 | 1 | return this->empty(); | |
| 97 | } | ||
| 98 | |||
| 99 | 1 | RasterImage::PixelFormat RasterImage::getPixelFormat() const | |
| 100 | { | ||
| 101 | 1 | return (PixelFormat)this->impl_instance.pixel_format; | |
| 102 | } | ||
| 103 | |||
| 104 | 10 | unsigned RasterImage::getWidth() const | |
| 105 | { | ||
| 106 | 10 | return gate_rasterimage_width(&this->impl_instance); | |
| 107 | } | ||
| 108 | 10 | unsigned RasterImage::getHeight() const | |
| 109 | { | ||
| 110 | 10 | return gate_rasterimage_height(&this->impl_instance); | |
| 111 | } | ||
| 112 | |||
| 113 | 1 | void RasterImage::setPixel(unsigned x, unsigned y, Color const& color) | |
| 114 | { | ||
| 115 | 1 | gate_result_t result = gate_rasterimage_set_pixel(&this->impl_instance, x, y, &color.value); | |
| 116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 117 | 1 | } | |
| 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 | 1 | Color RasterImage::getPixel(unsigned x, unsigned y) const | |
| 125 | { | ||
| 126 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Color ret; |
| 127 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | gate_result_t result = gate_rasterimage_get_pixel(&this->impl_instance, x, y, ret.c_impl()); |
| 128 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 129 | 1 | 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 | 1 | void* RasterImage::getPixelPtr(unsigned x, unsigned y) | |
| 141 | { | ||
| 142 | 1 | 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 | 1 | void RasterImage::makeGrayscale() | |
| 150 | { | ||
| 151 | 1 | result_t result = gate_rasterimage_to_grayscale(&this->impl_instance); | |
| 152 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 153 | 1 | } | |
| 154 | 1 | void RasterImage::makeMonochrome() | |
| 155 | { | ||
| 156 | 1 | result_t result = gate_rasterimage_to_monochrome(&this->impl_instance); | |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 158 | 1 | } | |
| 159 | 6 | void RasterImage::clear(Color const& col) | |
| 160 | { | ||
| 161 | 6 | result_t result = gate_rasterimage_clear(&this->impl_instance, col.c_impl()); | |
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | GATEXX_CHECK_ERROR(result); |
| 163 | 6 | } | |
| 164 | 1 | void RasterImage::resampleFrom(RasterImage const& src) | |
| 165 | { | ||
| 166 | 1 | result_t result = gate_rasterimage_resample(&this->impl_instance, &src.impl_instance); | |
| 167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 168 | 1 | } | |
| 169 | 1 | void RasterImage::paste(RasterImage const& src, int dstX, int dstY, int srcX, int srcY, int width, int height, bool transparent) | |
| 170 | { | ||
| 171 | 1 | result_t result = gate_rasterimage_paste_image(&this->impl_instance, &src.impl_instance, | |
| 172 | dstX, dstY, srcX, srcY, width, height, transparent); | ||
| 173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_ERROR(result); |
| 174 | 1 | } | |
| 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 | 1 | RasterImage RasterImage::subset(unsigned x, unsigned y, unsigned width, unsigned height) const | |
| 187 | { | ||
| 188 | 1 | RasterImage ret; | |
| 189 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_rasterimage_subset(&ret.impl_instance, &this->impl_instance, x, y, width, height); |
| 190 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(result); |
| 191 | 1 | 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 |