30 #ifndef PT_GFX_BASICIMAGE_H
31 #define PT_GFX_BASICIMAGE_H
33 #include <Pt/Gfx/Api.h>
34 #include <Pt/Gfx/Size.h>
42 template <
typename ModelT>
47 typedef typename ModelT::Pixel Pixel;
48 typedef typename ModelT::ConstPixel ConstPixel;
53 PixelIterator(BasicView& view, Pt::ssize_t x, Pt::ssize_t y)
57 PixelIterator(
const PixelIterator& it)
61 PixelIterator& operator=(
const PixelIterator& it)
63 _pixel.reset(it._pixel);
73 PixelIterator& operator++()
79 PixelIterator& operator+=(Pt::ssize_t n)
85 bool operator!=(
const PixelIterator& it)
const
86 {
return _pixel != it._pixel; }
88 bool operator==(
const PixelIterator& it)
const
89 {
return _pixel == it._pixel; }
91 std::size_t pixelStride()
const
92 {
return Model::pixelStride(); }
98 class ConstPixelIterator
101 ConstPixelIterator(
const BasicView& view, Pt::ssize_t x, Pt::ssize_t y)
105 ConstPixelIterator(
const ConstPixelIterator& it)
109 ConstPixelIterator& operator=(
const ConstPixelIterator& it)
111 _pixel.reset(it._pixel);
115 const ConstPixel& operator*()
const
118 const ConstPixel* operator->()
const
121 ConstPixelIterator& operator++()
127 ConstPixelIterator& operator+=(Pt::ssize_t n)
133 bool operator!=(
const ConstPixelIterator& it)
const
134 {
return _pixel != it._pixel; }
136 bool operator==(
const ConstPixelIterator& it)
const
137 {
return _pixel == it._pixel; }
139 std::size_t pixelStride()
const
140 {
return Model::pixelStride(); }
147 BasicView(
Pt::uint8_t* data,
const Size& size, Pt::ssize_t padding = 0)
153 _stride = (_size.width() * ModelT::pixelStride()) + _padding;
158 PixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
159 {
return PixelIterator(*
this, x, y); }
163 PixelIterator begin()
164 {
return PixelIterator(*
this, 0, 0); }
169 {
return PixelIterator(*
this, 0, height()); }
173 ConstPixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
const
174 {
return ConstPixelIterator(*
this, x, y); }
178 ConstPixelIterator begin()
const
179 {
return PixelIterator(*
this, 0, 0); }
183 ConstPixelIterator end()
const
184 {
return PixelIterator(*
this, 0, height()); }
188 const Size& size()
const
191 Pt::ssize_t width()
const
192 {
return _size.
width(); }
194 Pt::ssize_t height()
const
195 {
return _size.height(); }
198 {
return _size.width() == 0 || _size.height() == 0; }
206 Pt::ssize_t stride()
const
209 Pt::ssize_t padding()
const
212 std::size_t pixelStride()
const
213 {
return Model::pixelStride(); }
218 Pt::ssize_t _padding;
223 template <
typename ModelT,
typename ViewT = BasicView<ModelT> >
227 typedef ModelT Model;
228 typedef typename ModelT::Pixel Pixel;
229 typedef typename ModelT::ConstPixel ConstPixel;
232 typedef typename View::PixelIterator PixelIterator;
233 typedef typename View::ConstPixelIterator ConstPixelIterator;
236 BasicImage(
const Size& size, Pt::ssize_t padding = 0)
237 : _buffer( Model::imageSize(size, padding) )
238 , _view(_buffer.empty() ? 0 : &_buffer[0], size, padding)
241 BasicImage(
Pt::uint8_t* data,
const Size& size, Pt::ssize_t padding = 0)
242 : _view(data, size, padding)
245 virtual ~BasicImage()
250 PixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
251 {
return _view.pixel(x, y); }
255 PixelIterator begin()
256 {
return _view.begin(); }
261 {
return _view.end(); }
265 ConstPixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
const
266 {
return _view.pixel(x, y); }
270 ConstPixelIterator begin()
const
271 {
return _view.begin(); }
275 ConstPixelIterator end()
const
276 {
return _view.end(); }
280 const Size& size()
const
281 {
return _view.size(); }
283 Pt::ssize_t width()
const
284 {
return _view.
width(); }
286 Pt::ssize_t height()
const
287 {
return _view.height(); }
289 Pt::ssize_t padding()
const
290 {
return _view.padding(); }
293 {
return _view.data(); }
296 {
return _view.data(); }
299 {
return _view.empty(); }
301 const View& view()
const
305 std::vector<Pt::uint8_t> _buffer;
T width() const
Returns the width.
Definition: Size.h:65
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18