29 #ifndef PT_GFX_IMAGEVIEW_H
30 #define PT_GFX_IMAGEVIEW_H
32 #include <Pt/Gfx/Api.h>
33 #include <Pt/Gfx/Size.h>
34 #include <Pt/Gfx/Color.h>
35 #include <Pt/Gfx/ImageFormat.h>
36 #include <Pt/Gfx/CompositionMode.h>
62 assign(p, CompositionMode::SourceCopy);
68 assign(p, CompositionMode::SourceCopy);
72 Pixel& operator=(
const Color& color)
74 assign(color, CompositionMode::SourceCopy);
78 void reset(
ImageView& view, Pt::ssize_t x, Pt::ssize_t y);
80 void reset(
const Pixel& p)
90 void advance( Pt::ssize_t n );
92 void assign(
const Color& color, CompositionMode mode);
94 void assign(
const Pixel& p, CompositionMode mode)
96 assign(p.toColor(), mode);
99 void assign(
const ConstPixel& p, CompositionMode mode);
101 Color toColor()
const;
106 Pt::ssize_t x()
const
109 Pt::ssize_t y()
const
118 bool operator!=(
const Pixel& p)
const
119 {
return _base != p._base; }
121 bool operator==(
const Pixel& p)
const
122 {
return _base == p._base; }
124 std::size_t pixelStride()
const;
147 void reset(
const ImageView& view, Pt::ssize_t x, Pt::ssize_t y);
159 void advance( Pt::ssize_t n );
161 Color toColor()
const;
166 Pt::ssize_t x()
const
169 Pt::ssize_t y()
const
176 {
return _base != p._base; }
179 {
return _base == p._base; }
181 std::size_t pixelStride()
const;
201 PixelIterator(
ImageView& image, Pt::ssize_t x, Pt::ssize_t y)
202 : _pixel(image, x, y)
205 PixelIterator(
const PixelIterator& it)
209 PixelIterator& operator=(
const PixelIterator& it)
211 _pixel.reset(it._pixel);
215 bool operator!=(
const PixelIterator& it)
const
216 {
return _pixel != it._pixel; }
218 bool operator==(
const PixelIterator& it)
const
219 {
return _pixel == it._pixel; }
227 PixelIterator& operator++()
233 PixelIterator& operator+=(Pt::ssize_t n)
239 std::size_t pixelStride()
const
240 {
return _pixel.pixelStride(); }
246 class ConstPixelIterator
249 ConstPixelIterator(
const ImageView& image, Pt::ssize_t x, Pt::ssize_t y)
250 : _pixel(image, x, y)
253 ConstPixelIterator(
const ConstPixelIterator& it)
257 ConstPixelIterator& operator=(
const ConstPixelIterator& it)
259 _pixel.reset(it._pixel);
263 bool operator!=(
const ConstPixelIterator& it)
const
264 {
return _pixel != it._pixel; }
266 bool operator==(
const ConstPixelIterator& it)
const
267 {
return _pixel == it._pixel; }
275 ConstPixelIterator& operator++()
281 ConstPixelIterator& operator+=(Pt::ssize_t n)
287 std::size_t pixelStride()
const
288 {
return _pixel.pixelStride(); }
296 : _format( &ImageFormat::argb32() )
312 const Size& size, Pt::ssize_t padding)
325 const Size& size, Pt::ssize_t padding)
334 PixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
335 {
return PixelIterator(*
this, x, y); }
337 PixelIterator begin()
338 {
return PixelIterator(*
this, 0, 0); }
341 {
return PixelIterator(*
this, 0, height()); }
343 ConstPixelIterator pixel(Pt::ssize_t x, Pt::ssize_t y)
const
344 {
return ConstPixelIterator(*
this, x, y); }
346 ConstPixelIterator begin()
const
347 {
return ConstPixelIterator(*
this, 0, 0); }
349 ConstPixelIterator end()
const
350 {
return ConstPixelIterator(*
this, 0, height()); }
355 const Size& size()
const
358 Pt::ssize_t width()
const
359 {
return _size.
width(); }
361 Pt::ssize_t height()
const
362 {
return _size.
height(); }
365 {
return _size.
width() == 0 || _size.
height() == 0; }
373 std::size_t pixelStride()
const
376 Pt::ssize_t stride()
const
379 Pt::ssize_t padding()
const
387 Pt::ssize_t _padding;
396 inline Pixel::Pixel(
ImageView& view, Pt::ssize_t x, Pt::ssize_t y)
401 _base = view.data() + view.stride() * y + x * view.pixelStride();
405 inline void Pixel::reset(ImageView& view, Pt::ssize_t x, Pt::ssize_t y)
411 _base = view.data() + view.stride() * _y + _x * view.pixelStride();
415 inline void Pixel::advance()
417 if( ++_x >= _view->width() )
422 _base += _view->padding();
425 _base += _view->pixelStride();
429 inline void Pixel::advance(Pt::ssize_t n)
431 Pt::ssize_t off = _x + n;
432 _y += off / _view->width();
433 _x = off % _view->width();
435 _base = _view->data() + _view->stride() * _y + _x * _view->pixelStride();
439 inline void Pixel::assign(
const Color& color, CompositionMode mode)
441 _view->format().
setPixel(*
this, color, mode);
445 inline void Pixel::assign(
const ConstPixel& p, CompositionMode mode)
447 assign(p.toColor(), mode);
451 inline Color Pixel::toColor()
const
453 return _view->format().
getColor(*
this);
457 inline std::size_t Pixel::pixelStride()
const
459 return _view->pixelStride();
467 inline ConstPixel::ConstPixel(
const ImageView& view, Pt::ssize_t x, Pt::ssize_t y)
472 _base = view.data() + view.stride() * y + x * view.pixelStride();
476 inline void ConstPixel::reset(
const ImageView& view, Pt::ssize_t x, Pt::ssize_t y)
482 _base = view.data() + view.stride() * _y + _x * view.pixelStride();
486 inline void ConstPixel::advance()
488 if( ++_x >= _view->width() )
493 _base += _view->padding();
496 _base += _view->pixelStride();
500 inline void ConstPixel::advance(Pt::ssize_t n)
502 Pt::ssize_t off = _x + n;
503 _y += off / _view->width();
504 _x += off % _view->width();
506 _base = _view->data() + _view->stride() * _y + _x * _view->pixelStride();
510 inline Color ConstPixel::toColor()
const
512 return _view->format().
getColor(*
this);
516 inline std::size_t ConstPixel::pixelStride()
const
518 return _view->pixelStride();
T width() const
Returns the width.
Definition: Size.h:65
View on image data.
Definition: ImageView.h:192
Pixel in an image.
Definition: ImageView.h:48
T height() const
Returns the height.
Definition: Size.h:69
Const pixel in an image.
Definition: ImageView.h:135
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18