29#ifndef PT_GFX_BASIC_SPAN_H
30#define PT_GFX_BASIC_SPAN_H
32#include <Pt/Gfx/Api.h>
33#include <Pt/Gfx/View.h>
34#include <Pt/Gfx/CopyPixel.h>
45template <
typename FormatT,
typename TraitsT>
48template <
typename FormatT,
typename TraitsT>
49class ConstSpanIterator;
52template <
typename FormatT,
typename TraitsT>
55 template <
typename F,
typename T>
56 friend class ConstSpanIterator;
59 typedef FormatT Format;
60 typedef TraitsT Traits;
62 typedef typename Traits::Pixel Pixel;
63 typedef typename Traits::ConstPixel ConstPixel;
65 typedef ConstSpanIterator<Format, Traits> ConstIterator;
68 using iterator_category = std::forward_iterator_tag;
69 using value_type = Pixel;
70 using difference_type = std::ptrdiff_t;
71 using pointer = Pixel*;
72 using reference = Pixel&;
75 explicit SpanIterator(
const Pixel& pixel)
79 SpanIterator(
const SpanIterator& it)
83 SpanIterator& operator=(
const SpanIterator& it)
85 _pixel.reset(it._pixel);
89 bool operator!=(
const SpanIterator& it)
const
90 {
return ! _pixel.equals(it._pixel); }
92 bool operator!=(
const ConstIterator& it)
const
93 {
return ! _pixel.equals(it._pixel); }
95 bool operator==(
const SpanIterator& it)
const
96 {
return _pixel.equals(it._pixel); }
98 bool operator==(
const ConstIterator& it)
const
99 {
return _pixel.equals(it._pixel); }
107 SpanIterator& operator++()
113 SpanIterator& operator+=(Pt::ssize_t n)
124template <
typename FormatT,
typename TraitsT>
125class ConstSpanIterator
127 template <
typename F,
typename T>
128 friend class SpanIterator;
131 typedef FormatT Format;
132 typedef TraitsT Traits;
134 typedef typename Traits::Pixel Pixel;
135 typedef typename Traits::ConstPixel ConstPixel;
137 typedef SpanIterator<Format, Traits> Iterator;
140 using iterator_category = std::forward_iterator_tag;
141 using value_type = ConstPixel;
142 using difference_type = std::ptrdiff_t;
143 using pointer = ConstPixel*;
144 using reference = ConstPixel&;
147 explicit ConstSpanIterator(
const ConstPixel& pixel)
151 explicit ConstSpanIterator(
const Pixel& pixel)
155 ConstSpanIterator(
const ConstSpanIterator& it)
159 ConstSpanIterator& operator=(
const ConstSpanIterator& it)
161 _pixel.reset(it._pixel);
165 bool operator!=(
const ConstSpanIterator& it)
const
166 {
return ! _pixel.equals(it._pixel); }
168 bool operator!=(
const Iterator& it)
const
169 {
return ! _pixel.equals(it._pixel); }
171 bool operator==(
const ConstSpanIterator& it)
const
172 {
return _pixel.equals(it._pixel); }
174 bool operator==(
const Iterator& it)
const
175 {
return _pixel.equals(it._pixel); }
177 const ConstPixel& operator*()
const
180 const ConstPixel* operator->()
const
183 ConstSpanIterator& operator++()
189 ConstSpanIterator& operator+=(Pt::ssize_t n)
200template <
typename FormatT,
typename TraitsT>
204 typedef FormatT Format;
205 typedef TraitsT Traits;
207 typedef typename TraitsT::Pixel Pixel;
208 typedef typename TraitsT::ConstPixel ConstPixel;
210 typedef SpanIterator<Format, Traits> Iterator;
213 template <
typename T>
214 Span(T& view, Pt::ssize_t x, Pt::ssize_t y, std::size_t length)
219 Span(
const Span& span)
221 , _length(span._length)
224 Span& operator=(
const Span& span)
227 _length = span._length;
232 {
return _length == 0; }
234 std::size_t length()
const
237 void setLength(std::size_t length)
238 { _length = length; }
240 void advance(std::size_t n)
244 { _p.skipPadding(); }
246 void advanceLines(std::size_t n)
247 { _p.advanceLines(n); }
252 const Pixel& front()
const
256 {
return Iterator(_p); }
271template <
typename FormatT,
typename TraitsT>
275 typedef FormatT Format;
276 typedef TraitsT Traits;
278 typedef typename TraitsT::Pixel Pixel;
279 typedef typename TraitsT::ConstPixel ConstPixel;
281 typedef ConstSpanIterator<Format, Traits> Iterator;
284 template <
typename T>
285 ConstSpan(
const T& view, Pt::ssize_t x, Pt::ssize_t y, std::size_t length)
290 template <
typename T>
291 ConstSpan(T& view, Pt::ssize_t x, Pt::ssize_t y, std::size_t length)
296 ConstSpan(
const ConstSpan& span)
298 , _length(span._length)
301 ConstSpan(
const Span<Format, Traits>& span)
303 , _length(span.length())
306 ConstSpan& operator=(
const ConstSpan& span)
309 _length = span._length;
314 {
return _length == 0; }
316 std::size_t length()
const
319 void setLength(std::size_t length)
320 { _length = length; }
322 void advance(std::size_t n)
326 { _p.skipPadding(); }
328 void advanceLines(std::size_t n)
329 { _p.advanceLines(n); }
334 const ConstPixel& front()
const
337 Iterator begin()
const
338 {
return Iterator(_p); }
354Span<
typename T::Format,
355 typename T::Traits> span(T& source,
360 return Span<typename T::Format, typename T::Traits>(source, x, y, length);
365ConstSpan<
typename T::Format,
366 typename T::Traits> span(
const T& source,
371 return ConstSpan<typename T::Format, typename T::Traits>(source, x, y, length);
376Span<
typename T::Format,
377 ImageTraitsF> spanF(T& source,
382 return Span<typename T::Format, ImageTraitsF>(source, x, y, length);
387ConstSpan<
typename T::Format,
388 ImageTraitsF> spanF(
const T& source,
393 return ConstSpan<typename T::Format, ImageTraitsF>(source, x, y, length);
402template <
typename SpanT,
typename P>
405 copyPixel(from.front(), to, from.length());
412template <
typename FromSpanT,
typename ToSpanT>
415 std::size_t n = std::min(from.length(), to.length());
Graphics and imaging services.
Definition Api-Argb32Image.h:12
void copySpanTo(const SpanT &from, P &to)
Copies the pixels of a span to a pixel position.
Definition Span.h:403
void copySpan(const FromSpanT &from, ToSpanT &to)
Copies the pixels of a span to another span.
Definition Span.h:413
void copyPixel(const P1 &from, P2 &to)
Copies a single pixel.
Definition CopyPixel.h:146
Core module.
Definition Allocator.h:33