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 
42 namespace Pt {
43 
44 namespace Gfx {
45 
46 //inline namespace v2 {
47 
50 template <typename FormatT, typename TraitsT>
51 class BasicImage : public ViewBase
52 {
53  public:
54  typedef FormatT Format;
55  typedef TraitsT Traits;
56 
57  public:
60  explicit BasicImage( const Format& format = FormatT::get() );
61 
64  BasicImage(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding,
65  const Format& format = FormatT::get() );
66 
69  BasicImage(Pt::ssize_t width, Pt::ssize_t height,
70  const Format& format = FormatT::get() );
71 
74  BasicImage(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
75  Pt::ssize_t padding, const Format& format = FormatT::get() );
76 
79  BasicImage(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
80  const Format& format = FormatT::get() );
81 
84  BasicImage(const BasicImage& image);
85 
88  virtual ~BasicImage();
89 
90  BasicImage& operator=(const BasicImage& image);
91 
92  Pt::uint8_t* data()
93  { return _data; }
94 
95  const Pt::uint8_t* data() const
96  { return _data; }
97 
98  const Format& format() const
99  { return *_format; }
100 
101  Pt::ssize_t padding() const
102  { return stride() - width() * pixelStride(); }
103 
106  void reset(Pt::ssize_t width, Pt::ssize_t height,
107  Pt::ssize_t padding, const Format& format);
108 
109  void reset(Pt::ssize_t width, Pt::ssize_t height,
110  const Format& format);
111 
114  void reset(Pt::ssize_t width, Pt::ssize_t height,
115  Pt::ssize_t padding);
116 
117  void reset(Pt::ssize_t width, Pt::ssize_t height);
118 
121  void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
122  Pt::ssize_t padding, const Format& format);
123 
124  void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
125  const Format& format);
126 
129  void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
130  Pt::ssize_t padding);
131 
132  void reset(Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height);
133 
136  void clear();
137 
138  Pt::ssize_t pixelStride() const;
139 
140  std::size_t size() const;
141 
142  private:
143  std::unique_ptr<FormatT> _format;
144  std::vector<Pt::uint8_t> _buffer;
145  Pt::uint8_t* _data;
146 };
147 
150 template <typename FormatT, typename TraitsT>
151 class BasicConstImage : public ViewBase
152 {
153  public:
154  typedef FormatT Format;
155  typedef TraitsT Traits;
156 
157  public:
158  explicit BasicConstImage( const Format& format = FormatT::get() );
159 
160  BasicConstImage(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
161  Pt::ssize_t padding, const Format& format = FormatT::get() );
162 
163  BasicConstImage(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
164  const Format& format = FormatT::get() );
165 
167 
168  BasicConstImage(const BasicConstImage& image);
169 
170  virtual ~BasicConstImage();
171 
172  const Pt::uint8_t* data() const
173  { return _data; }
174 
175  const Format& format() const
176  { return *_format; }
177 
178  Pt::ssize_t padding() const
179  { return stride() - width() * pixelStride(); }
180 
181  void reset(const BasicConstImage& image);
182 
183  void reset(const BasicImage<FormatT, TraitsT>& image);
184 
187  void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
188  Pt::ssize_t padding, const Format& format);
189 
190  void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
191  const Format& format);
192 
195  void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
196  Pt::ssize_t padding);
197 
198  void reset(const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height);
199 
200  void clear();
201 
202  Pt::ssize_t pixelStride() const;
203 
204  std::size_t size() const;
205 
206  private:
207  std::unique_ptr<FormatT> _format;
208  const Pt::uint8_t* _data;
209 };
210 
211 // } // namespace
212 
213 } // namespace
214 
215 } // namespace
216 
217 #include <Pt/Gfx/Image.hpp>
218 
219 #endif
Core module.
Definition: pt-gfx-images.dox:14
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.
virtual ~BasicImage()
Destructor.
void reset(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format)
Reset to new size.
void clear()
Clears the image.
BasicImage(Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format=FormatT::get())
Constructor.
BasicImage(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding, const Format &format=FormatT::get())
Constructor.
ARGB-32 image format.
Definition: Argb32.h:205
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.
Basic const image.
Definition: Image.h:152
BasicImage(Pt::uint8_t *data, Pt::ssize_t width, Pt::ssize_t height, const Format &format=FormatT::get())
Constructor.
BasicImage(Pt::ssize_t width, Pt::ssize_t height, const Format &format=FormatT::get())
Constructor.
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.
Basic image.
Definition: Image.h:52
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
BasicImage(const Format &format=FormatT::get())
Constructor.
BasicImage(const BasicImage &image)
Copy constructor.
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.
void reset(Pt::ssize_t width, Pt::ssize_t height, Pt::ssize_t padding)
Reset to new size, keep existing format.