comparison DPF-Prymula-audioplugins/dpf/dgl/src/ImageBase.cpp @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents
children
comparison
equal deleted inserted replaced
2:cf2cb71d31dd 3:84e66ea83026
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
4 *
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.
8 *
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.
15 */
16
17 #include "../ImageBase.hpp"
18
19 START_NAMESPACE_DGL
20
21 // --------------------------------------------------------------------------------------------------------------------
22 // protected constructors
23
24 ImageBase::ImageBase()
25 : rawData(nullptr),
26 size(0, 0),
27 format(kImageFormatNull) {}
28
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) {}
33
34 ImageBase::ImageBase(const char* const rdata, const Size<uint>& s, const ImageFormat fmt)
35 : rawData(rdata),
36 size(s),
37 format(fmt) {}
38
39 ImageBase::ImageBase(const ImageBase& image)
40 : rawData(image.rawData),
41 size(image.size),
42 format(image.format) {}
43
44 // --------------------------------------------------------------------------------------------------------------------
45 // public methods
46
47 ImageBase::~ImageBase() {}
48
49 bool ImageBase::isValid() const noexcept
50 {
51 return (rawData != nullptr && size.isValid());
52 }
53
54 bool ImageBase::isInvalid() const noexcept
55 {
56 return (rawData == nullptr || size.isInvalid());
57 }
58
59 uint ImageBase::getWidth() const noexcept
60 {
61 return size.getWidth();
62 }
63
64 uint ImageBase::getHeight() const noexcept
65 {
66 return size.getHeight();
67 }
68
69 const Size<uint>& ImageBase::getSize() const noexcept
70 {
71 return size;
72 }
73
74 const char* ImageBase::getRawData() const noexcept
75 {
76 return rawData;
77 }
78
79 ImageFormat ImageBase::getFormat() const noexcept
80 {
81 return format;
82 }
83
84 void ImageBase::loadFromMemory(const char* const rdata,
85 const uint width,
86 const uint height,
87 const ImageFormat fmt) noexcept
88 {
89 loadFromMemory(rdata, Size<uint>(width, height), fmt);
90 }
91
92 void ImageBase::loadFromMemory(const char* const rdata, const Size<uint>& s, const ImageFormat fmt) noexcept
93 {
94 rawData = rdata;
95 size = s;
96 format = fmt;
97 }
98
99 void ImageBase::draw(const GraphicsContext& context)
100 {
101 drawAt(context, Point<int>(0, 0));
102 }
103
104 void ImageBase::drawAt(const GraphicsContext& context, const int x, const int y)
105 {
106 drawAt(context, Point<int>(x, y));
107 }
108
109 // --------------------------------------------------------------------------------------------------------------------
110 // public operators
111
112 ImageBase& ImageBase::operator=(const ImageBase& image) noexcept
113 {
114 rawData = image.rawData;
115 size = image.size;
116 format = image.format;
117 return *this;
118 }
119
120 bool ImageBase::operator==(const ImageBase& image) const noexcept
121 {
122 return (rawData == image.rawData && size == image.size && format == image.format);
123 }
124
125 bool ImageBase::operator!=(const ImageBase& image) const noexcept
126 {
127 return !operator==(image);
128 }
129
130 // --------------------------------------------------------------------------------------------------------------------
131
132 END_NAMESPACE_DGL