29 #ifndef PT_GFX_LINE_VIEW_H
30 #define PT_GFX_LINE_VIEW_H
32 #include <Pt/Gfx/Api.h>
33 #include <Pt/Gfx/View.h>
34 #include <Pt/Gfx/Span.h>
44 template <
typename FormatT,
typename TraitsT>
47 template <
typename FormatT,
typename TraitsT>
48 class ConstLineIterator;
51 template <
typename FormatT,
typename TraitsT>
55 typedef FormatT Format;
56 typedef TraitsT Traits;
59 using value_type = Span<Format, Traits>;
60 using difference_type = std::ptrdiff_t;
61 using pointer = value_type*;
62 using reference = value_type&;
63 using iterator_category = std::forward_iterator_tag;
66 LineIterator(BasicView<Format, Traits>& view, Pt::ssize_t x, Pt::ssize_t y)
67 : _span(view, x, y, view.width())
73 const reference operator*()
const
79 const value_type* operator->()
const
82 LineIterator& operator++() noexcept
84 _span.advanceLines(1);
88 LineIterator operator++(
int) noexcept
90 LineIterator it(*
this);
95 LineIterator& operator+=(Pt::ssize_t n)
97 _span.advanceLines(n);
101 bool operator==(
const LineIterator& other)
const noexcept
103 return _span.front().equals( other->front() );
106 bool operator!=(
const LineIterator& other)
const noexcept
108 return ! (*
this == other);
112 Span<Format, Traits> _span;
116 template <
typename FormatT,
typename TraitsT>
117 class ConstLineIterator
120 typedef FormatT Format;
121 typedef TraitsT Traits;
124 using value_type = ConstSpan<Format, Traits>;
125 using difference_type = std::ptrdiff_t;
126 using pointer =
const value_type*;
127 using reference =
const value_type&;
128 using iterator_category = std::forward_iterator_tag;
131 ConstLineIterator(
const BasicConstView<Format, Traits>& view, Pt::ssize_t x, Pt::ssize_t y)
132 : _span(view, x, y, view.width())
135 const reference operator*()
const
138 const pointer operator->()
const
141 ConstLineIterator& operator++() noexcept
143 _span.advanceLines(1);
147 ConstLineIterator operator++(
int) noexcept
149 ConstLineIterator it(*
this);
154 ConstLineIterator& operator+=(Pt::ssize_t n)
156 _span.advanceLines(n);
160 bool operator==(
const ConstLineIterator& other)
const noexcept
162 return _span.front().equals( other->front() );
165 bool operator!=(
const ConstLineIterator& other)
const noexcept
167 return ! (*
this == other);
171 ConstSpan<Format, Traits> _span;
175 template <
typename FormatT,
typename TraitsT>
179 typedef FormatT Format;
180 typedef TraitsT Traits;
182 typedef LineIterator<Format, Traits> Iterator;
185 explicit BasicLineView(
const Format& format = FormatT::get() );
187 BasicLineView(
Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
188 Pt::ssize_t padding,
const Format& format = FormatT::get());
190 template <
typename T>
191 explicit BasicLineView(T& source);
193 template <
typename T>
194 BasicLineView(T& source, Int x, Int y, Int w, Int h);
196 BasicLineView& operator=(
const BasicLineView&) =
default;
199 {
return _view.data(); }
202 {
return _view.data(); }
204 Pt::ssize_t width()
const
205 {
return _view.width(); }
207 Pt::ssize_t height()
const
208 {
return _view.height(); }
210 Pt::ssize_t stride()
const
211 {
return _view.stride(); }
213 const Format& format()
const
214 {
return _view.format(); }
216 Pt::ssize_t pixelStride()
const
217 {
return _view.pixelStride(); }
219 Pt::ssize_t padding()
const
220 {
return _view.padding(); }
222 Iterator line(Pt::ssize_t y)
223 {
return Iterator(_view, 0, y); }
226 {
return Iterator(_view, 0, 0); }
229 {
return Iterator(_view, 0, _view.height()); }
232 BasicView<Format, Traits> _view;
236 template <
typename FormatT,
typename TraitsT>
237 class BasicConstLineView
240 typedef FormatT Format;
241 typedef TraitsT Traits;
243 typedef ConstLineIterator<Format, Traits> Iterator;
246 explicit BasicConstLineView(
const Format& format = FormatT::get() );
248 BasicConstLineView(
const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
249 Pt::ssize_t padding,
const Format& format = FormatT::get());
251 template <
typename T>
252 explicit BasicConstLineView(
const T& source);
254 template <
typename T>
255 BasicConstLineView(
const T& source, Int x, Int y, Int w, Int h);
257 BasicConstLineView& operator=(
const BasicConstLineView&) =
default;
260 {
return _view.data(); }
262 Pt::ssize_t width()
const
263 {
return _view.width(); }
265 Pt::ssize_t height()
const
266 {
return _view.height(); }
268 Pt::ssize_t stride()
const
269 {
return _view.stride(); }
271 const Format& format()
const
272 {
return _view.format(); }
274 Pt::ssize_t pixelStride()
const
275 {
return _view.pixelStride(); }
277 Pt::ssize_t padding()
const
278 {
return _view.padding(); }
280 Iterator line(Pt::ssize_t y)
const
281 {
return Iterator(_view, 0, y); }
283 Iterator begin()
const
284 {
return Iterator(_view, 0, 0); }
287 {
return Iterator(_view, 0, _view.height()); }
290 BasicConstView<Format, Traits> _view;
294 template <
typename T>
295 BasicLineView<
typename T::Format,
296 typename T::Traits> lineView(T& source)
298 return BasicLineView<typename T::Format, typename T::Traits>(source);
302 template <
typename T>
303 BasicConstLineView<
typename T::Format,
304 typename T::Traits> lineView(
const T& source)
306 return BasicConstLineView<typename T::Format, typename T::Traits>(source);
310 template <
typename T>
311 BasicLineView<
typename T::Format,
312 typename T::Traits> lineView(T& source, Int x, Int y, Int w, Int h)
314 return BasicLineView<typename T::Format, typename T::Traits>(source, x, y, w, h);
318 template <
typename T>
319 BasicConstLineView<
typename T::Format,
320 typename T::Traits> lineView(
const T& source, Int x, Int y, Int w, Int h)
322 return BasicConstLineView<typename T::Format, typename T::Traits>(source, x, y, w, h);
326 template <
typename FormatT,
typename TraitsT = ImageTraits<FormatT> >
327 BasicLineView<FormatT,
328 TraitsT> lineView(
Pt::uint8_t* data, Pt::ssize_t width,
329 Pt::ssize_t height, Pt::ssize_t padding = 0)
331 return BasicLineView<FormatT, TraitsT>(data, width, height, padding, FormatT::get());
335 template <
typename FormatT,
typename TraitsT = ImageTraits<FormatT> >
336 BasicConstLineView<FormatT,
337 TraitsT> lineView(
const Pt::uint8_t* data, Pt::ssize_t width,
338 Pt::ssize_t height, Pt::ssize_t padding = 0)
340 return BasicConstLineView<FormatT, TraitsT>(data, width, height, padding, FormatT::get());
344 template <
typename T>
345 BasicLineView<
typename T::Format,
346 ImageTraitsF> lineViewF(T& source)
348 return BasicLineView<typename T::Format, ImageTraitsF>(source);
352 template <
typename T>
353 BasicConstLineView<
typename T::Format,
354 ImageTraitsF> lineViewF(
const T& source)
356 return BasicConstLineView<typename T::Format, ImageTraitsF>(source);
360 template <
typename T>
361 BasicLineView<
typename T::Format,
362 ImageTraitsF> lineViewF(T& source, Int x, Int y, Int w, Int h)
364 return BasicLineView<typename T::Format, ImageTraitsF>(source, x, y, w, h);
368 template <
typename T>
369 BasicConstLineView<
typename T::Format,
370 ImageTraitsF> lineViewF(
const T& source, Int x, Int y, Int w, Int h)
372 return BasicConstLineView<typename T::Format, ImageTraitsF>(source, x, y, w, h);
376 inline LineViewF lineViewF(
Pt::uint8_t* data, Pt::ssize_t width,
377 Pt::ssize_t height, Pt::ssize_t padding,
378 const ImageFormat& format)
380 return LineViewF(data, width, height, padding, format);
384 inline ConstLineViewF lineViewF(
const Pt::uint8_t* data, Pt::ssize_t width,
385 Pt::ssize_t height, Pt::ssize_t padding,
386 const ImageFormat& format)
388 return ConstLineViewF(data, width, height, padding, format);
397 #include <Pt/Gfx/LineView.hpp>
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18