Image.h
1/* Copyright (C) 2015 Marc Boris Duerner
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 MA 02110-1301 USA
27*/
28
29#ifndef PT_GFX_IMAGE_H
30#define PT_GFX_IMAGE_H
31
32#include <Pt/Gfx/Api.h>
33#include <Pt/Gfx/ImageFormat.h>
34#include <Pt/Gfx/View.h>
35#include <Pt/Gfx/PixelView.h>
36#include <Pt/Gfx/LineView.h>
37#include <Pt/Gfx/ImageTraits.h>
38#include <Pt/Types.h>
39#include <vector>
40#include <memory>
41
42namespace Pt {
43
44namespace Gfx {
45
46//inline namespace v2 {
47
81template <typename FormatT, typename TraitsT>
82class BasicImage : public ViewBase
83{
84 public:
85 typedef FormatT Format;
86 typedef TraitsT Traits;
87
88 public:
91 explicit BasicImage( const Format& format = FormatT::get() );
92
95 BasicImage(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding,
96 const Format& format = FormatT::get() );
97
100 BasicImage(Pt::ssize_t width, Pt::ssize_t height,
101 const Format& format = FormatT::get() );
102
105 BasicImage(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
106 Pt::ssize_t padding, const Format& format = FormatT::get() );
107
110 BasicImage(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
111 const Format& format = FormatT::get() );
112
115 BasicImage(const BasicImage& image);
116
119 virtual ~BasicImage();
120
121 BasicImage& operator=(const BasicImage& image);
122
123 Pt::uint8_t* data()
124 { return _data; }
125
126 const Pt::uint8_t* data() const
127 { return _data; }
128
129 const Format& format() const
130 { return *_format; }
131
132 Pt::ssize_t padding() const
133 { return stride() - width() * pixelStride(); }
134
137 void reset(Pt::ssize_t width, Pt::ssize_t height,
138 Pt::ssize_t padding, const Format& format);
139
140 void reset(Pt::ssize_t width, Pt::ssize_t height,
141 const Format& format);
142
145 void reset(Pt::ssize_t width, Pt::ssize_t height,
146 Pt::ssize_t padding);
147
148 void reset(Pt::ssize_t width, Pt::ssize_t height);
149
152 void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
153 Pt::ssize_t padding, const Format& format);
154
155 void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
156 const Format& format);
157
160 void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
161 Pt::ssize_t padding);
162
163 void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height);
164
167 void clear();
168
169 Pt::ssize_t pixelStride() const;
170
171 std::size_t size() const;
172
173 private:
174 std::unique_ptr<FormatT> _format;
175 std::vector<Pt::uint8_t> _buffer;
176 Pt::uint8_t* _data;
177};
178
187template <typename FormatT, typename TraitsT>
188class BasicConstImage : public ViewBase
189{
190 public:
191 typedef FormatT Format;
192 typedef TraitsT Traits;
193
194 public:
195 explicit BasicConstImage( const Format& format = FormatT::get() );
196
197 BasicConstImage(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
198 Pt::ssize_t padding, const Format& format = FormatT::get() );
199
200 BasicConstImage(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
201 const Format& format = FormatT::get() );
202
203 BasicConstImage(const BasicImage<FormatT, TraitsT>& image);
204
205 BasicConstImage(const BasicConstImage& image);
206
207 virtual ~BasicConstImage();
208
209 const Pt::uint8_t* data() const
210 { return _data; }
211
212 const Format& format() const
213 { return *_format; }
214
215 Pt::ssize_t padding() const
216 { return stride() - width() * pixelStride(); }
217
218 void reset(const BasicConstImage& image);
219
220 void reset(const BasicImage<FormatT, TraitsT>& image);
221
224 void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
225 Pt::ssize_t padding, const Format& format);
226
227 void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
228 const Format& format);
229
232 void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
233 Pt::ssize_t padding);
234
235 void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height);
236
237 void clear();
238
239 Pt::ssize_t pixelStride() const;
240
241 std::size_t size() const;
242
243 private:
244 std::unique_ptr<FormatT> _format;
245 const Pt::uint8_t* _data;
246};
247
248// } // namespace
249
250} // namespace
251
252} // namespace
253
254#include <Pt/Gfx/Image.hpp>
255
256#endif
void reset(const Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding)
Reset to new data, keep existing format.
void reset(const Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format)
Reset to new data.
Image that owns or wraps pixel data.
Definition Image.h:83
void reset(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format)
Reset to new size.
BasicImage(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format=FormatT::get())
Constructs an image of the given size with row padding.
void reset(Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding)
Reset to new data, keep existing format.
BasicImage(const Format &format=FormatT::get())
Constructs an empty image.
void reset(Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format)
Reset to new data.
BasicImage(Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, const Format &format=FormatT::get())
Constructs an image over external pixel data.
void reset(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding)
Reset to new size, keep existing format.
void clear()
Clears the image.
virtual ~BasicImage()
Destructor.
BasicImage(Pt::ssize_t width, Pt::ssize_t height, const Format &format=FormatT::get())
Constructs an image of the given size.
BasicImage(Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format=FormatT::get())
Constructs an image over external pixel data with row padding.
BasicImage(const BasicImage &image)
Copy constructor.
uint_type uint8_t
Unsigned 8-bit integer type.
Definition Api-Types.h:24
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33