| 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/gifimages.hpp" | ||
| 30 | |||
| 31 | #include "gate/graphics/gifimages.h" | ||
| 32 | |||
| 33 | #include "gate/exceptions.hpp" | ||
| 34 | |||
| 35 | namespace gate | ||
| 36 | { | ||
| 37 | namespace graph | ||
| 38 | { | ||
| 39 | |||
| 40 | char const* const GifImages::FileExt = GATE_GRAPHICS_FILE_EXT_GIF; | ||
| 41 | |||
| 42 | |||
| 43 | ✗ | void GifImages::load(RasterImage& destimage, Stream& inputstream, enumint_t flags) | |
| 44 | { | ||
| 45 | ✗ | RasterImage tmp; | |
| 46 | ✗ | result_t result = gate_gifimage_load(inputstream.c_impl(), tmp.c_impl(), flags); | |
| 47 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 48 | ✗ | tmp.swap(destimage); | |
| 49 | ✗ | } | |
| 50 | |||
| 51 | ✗ | void GifImages::save(RasterImage& srcimage, Stream& outputstream, enumint_t flags) | |
| 52 | { | ||
| 53 | ✗ | result_t result = gate_gifimage_save(srcimage.c_impl(), outputstream.c_impl(), flags); | |
| 54 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 55 | ✗ | } | |
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | const enumint_t GifAnimationWriter::Flag_Loop = GATE_GIFANIMATION_FLAG_LOOP; | ||
| 60 | |||
| 61 | |||
| 62 | ✗ | GifAnimationWriter::GifAnimationWriter() | |
| 63 | { | ||
| 64 | ✗ | result_t result = gate_gifanimation_writer_create(&this->impl); | |
| 65 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 66 | ✗ | } | |
| 67 | |||
| 68 | ✗ | GifAnimationWriter::~GifAnimationWriter() noexcept | |
| 69 | { | ||
| 70 | ✗ | gate_gifanimation_writer_destroy(this->impl); | |
| 71 | ✗ | } | |
| 72 | |||
| 73 | ✗ | gate_gifanimation_writer_t GifAnimationWriter::c_impl() const noexcept | |
| 74 | { | ||
| 75 | ✗ | return this->impl; | |
| 76 | } | ||
| 77 | |||
| 78 | ✗ | void GifAnimationWriter::start(Stream& outstream, unsigned width, unsigned height, enumint_t flags) | |
| 79 | { | ||
| 80 | ✗ | result_t result = gate_gifanimation_writer_start(this->impl, outstream.c_impl(), width, height, flags); | |
| 81 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 82 | ✗ | } | |
| 83 | |||
| 84 | ✗ | void GifAnimationWriter::import(Stream& instream, enumint_t flags) | |
| 85 | { | ||
| 86 | ✗ | result_t result = gate_gifanimation_writer_import(this->impl, instream.c_impl(), flags); | |
| 87 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 88 | ✗ | } | |
| 89 | |||
| 90 | ✗ | void GifAnimationWriter::addFrame(RasterImage const& image, unsigned x, unsigned y, time::Milliseconds displayDelayTime, enumint_t flags) | |
| 91 | { | ||
| 92 | ✗ | result_t result = gate_gifanimation_writer_add_frame( | |
| 93 | ✗ | this->impl, image.c_impl(), x, y, static_cast<gate_uint32_t>(displayDelayTime.value()), flags); | |
| 94 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 95 | ✗ | } | |
| 96 | |||
| 97 | ✗ | void GifAnimationWriter::finish(enumint_t flags) | |
| 98 | { | ||
| 99 | ✗ | result_t result = gate_gifanimation_writer_finish(this->impl, flags); | |
| 100 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 101 | ✗ | } | |
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | ✗ | GifAnimationReader::GifAnimationReader() | |
| 106 | { | ||
| 107 | ✗ | result_t result = gate_gifanimation_reader_create(&this->impl); | |
| 108 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 109 | ✗ | } | |
| 110 | |||
| 111 | ✗ | GifAnimationReader::~GifAnimationReader() noexcept | |
| 112 | { | ||
| 113 | ✗ | gate_gifanimation_reader_destroy(this->impl); | |
| 114 | ✗ | } | |
| 115 | |||
| 116 | ✗ | void GifAnimationReader::load(Stream& inputStream) | |
| 117 | { | ||
| 118 | ✗ | result_t result = gate_gifanimation_reader_load( | |
| 119 | this->impl, inputStream.c_impl(), &this->width, &this->height, &this->flags); | ||
| 120 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 121 | ✗ | } | |
| 122 | |||
| 123 | ✗ | unsigned GifAnimationReader::getScreenWidth() const | |
| 124 | { | ||
| 125 | ✗ | return this->width; | |
| 126 | } | ||
| 127 | |||
| 128 | ✗ | unsigned GifAnimationReader::getScreenHeight() const | |
| 129 | { | ||
| 130 | ✗ | return this->height; | |
| 131 | } | ||
| 132 | |||
| 133 | ✗ | enumint_t GifAnimationReader::getFlags() const | |
| 134 | { | ||
| 135 | ✗ | return this->flags; | |
| 136 | } | ||
| 137 | |||
| 138 | ✗ | bool GifAnimationReader::getNextFrame(RasterImage& frame, unsigned& x, unsigned& y, time::Milliseconds& displayTime) | |
| 139 | { | ||
| 140 | ✗ | uint32_t time_ms = 0; | |
| 141 | ✗ | result_t result = gate_gifanimation_reader_get_frame(this->impl, frame.c_impl(), &x, &y, &time_ms); | |
| 142 | ✗ | if (result == GATE_RESULT_ENDOFSTREAM) | |
| 143 | { | ||
| 144 | ✗ | return false; | |
| 145 | } | ||
| 146 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 147 | ✗ | displayTime.value() = static_cast<gate::time::duration_value_t>(time_ms); | |
| 148 | ✗ | return true; | |
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | } // end of namespace graph | ||
| 154 | } // end of namespace gate | ||
| 155 |