Cleanup
[carla.git] / source / modules / dgl / src / ImageBase.cpp
blob229523bf39ef0767bb0a8439168408caf6fd7ced
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "../ImageBase.hpp"
19 START_NAMESPACE_DGL
21 // --------------------------------------------------------------------------------------------------------------------
22 // protected constructors
24 ImageBase::ImageBase()
25 : rawData(nullptr),
26 size(0, 0),
27 format(kImageFormatNull) {}
29 ImageBase::ImageBase(const char* const rdata, const uint width, const uint height, const ImageFormat fmt)
30 : rawData(rdata),
31 size(width, height),
32 format(fmt) {}
34 ImageBase::ImageBase(const char* const rdata, const Size<uint>& s, const ImageFormat fmt)
35 : rawData(rdata),
36 size(s),
37 format(fmt) {}
39 ImageBase::ImageBase(const ImageBase& image)
40 : rawData(image.rawData),
41 size(image.size),
42 format(image.format) {}
44 // --------------------------------------------------------------------------------------------------------------------
45 // public methods
47 ImageBase::~ImageBase() {}
49 bool ImageBase::isValid() const noexcept
51 return (rawData != nullptr && size.isValid());
54 bool ImageBase::isInvalid() const noexcept
56 return (rawData == nullptr || size.isInvalid());
59 uint ImageBase::getWidth() const noexcept
61 return size.getWidth();
64 uint ImageBase::getHeight() const noexcept
66 return size.getHeight();
69 const Size<uint>& ImageBase::getSize() const noexcept
71 return size;
74 const char* ImageBase::getRawData() const noexcept
76 return rawData;
79 ImageFormat ImageBase::getFormat() const noexcept
81 return format;
84 void ImageBase::loadFromMemory(const char* const rdata,
85 const uint width,
86 const uint height,
87 const ImageFormat fmt) noexcept
89 loadFromMemory(rdata, Size<uint>(width, height), fmt);
92 void ImageBase::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
94 rawData = rdata;
95 size = s;
96 format = fmt;
99 void ImageBase::draw(const GraphicsContext& context)
101 drawAt(context, Point<int>(0, 0));
104 void ImageBase::drawAt(const GraphicsContext& context, const int x, const int y)
106 drawAt(context, Point<int>(x, y));
109 // --------------------------------------------------------------------------------------------------------------------
110 // public operators
112 ImageBase& ImageBase::operator=(const ImageBase& image) noexcept
114 rawData = image.rawData;
115 size = image.size;
116 format = image.format;
117 return *this;
120 bool ImageBase::operator==(const ImageBase& image) const noexcept
122 return (rawData == image.rawData && size == image.size && format == image.format);
125 bool ImageBase::operator!=(const ImageBase& image) const noexcept
127 return !operator==(image);
130 // --------------------------------------------------------------------------------------------------------------------
132 END_NAMESPACE_DGL