32#include <Pt/Gfx/Api.h>
33#include <Pt/Gfx/ViewBase.h>
34#include <Pt/Gfx/ImageTraits.h>
35#include <Pt/TypeTraits.h>
63template <
typename FormatT,
typename TraitsT>
64class BasicView :
public ViewBase
67 typedef FormatT Format;
68 typedef TraitsT Traits;
71 explicit BasicView(
const Format& format = FormatT::get() );
73 BasicView(
Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
74 Pt::ssize_t padding,
const Format& format = FormatT::get());
77 explicit BasicView(T& source);
80 BasicView(T& source, Int x, Int y, Int w, Int h);
82 BasicView& operator=(
const BasicView&) =
default;
93 const Format& format()
const
96 Pt::ssize_t pixelStride()
const
97 {
return TraitsT::pixelStride(*_format); }
99 Pt::ssize_t padding()
const
100 {
return stride() - width() * pixelStride(); }
106 void setFormat(
const Format& format)
107 { _format = &format; }
111 const Format* _format;
123template <
typename FormatT,
typename TraitsT>
124class BasicConstView :
public ViewBase
127 typedef FormatT Format;
128 typedef TraitsT Traits;
131 explicit BasicConstView(
const Format& format = FormatT::get() );
133 BasicConstView(
const Pt::uint8_t* data, Pt::ssize_t width, Pt::ssize_t height,
134 Pt::ssize_t padding,
const Format& format = FormatT::get());
136 template <
typename T>
137 explicit BasicConstView(
const T& source);
139 template <
typename T>
140 BasicConstView(
const T& source, Int x, Int y, Int w, Int h);
142 BasicConstView& operator=(
const BasicConstView&) =
default;
150 const Format& format()
const
153 Pt::ssize_t pixelStride()
const
154 {
return TraitsT::pixelStride(*_format); }
156 Pt::ssize_t padding()
const
157 {
return stride() - width() * pixelStride(); }
163 void setFormat(
const Format& format)
164 { _format = &format; }
168 const Format* _format;
174 typename T::Traits> view(T& source)
181BasicConstView<
typename T::Format,
182 typename T::Traits> view(
const T& source)
184 return BasicConstView<typename T::Format, typename T::Traits>(source);
189BasicView<
typename T::Format,
190 typename T::Traits> view(T& source, Int x, Int y, Int w, Int h)
192 return BasicView<typename T::Format, typename T::Traits>(source, x, y, w, h);
198 typename T::Traits> view(
const T& source, Int x, Int y, Int w, Int h)
204template <
typename FormatT,
typename TraitsT = ImageTraits<FormatT> >
206 TraitsT> view(
Pt::uint8_t* data, Pt::ssize_t width,
207 Pt::ssize_t height, Pt::ssize_t padding = 0)
213template <
typename FormatT,
typename TraitsT = ImageTraits<FormatT> >
215 TraitsT> view(
const Pt::uint8_t* data, Pt::ssize_t width,
216 Pt::ssize_t height, Pt::ssize_t padding = 0)
224 ImageTraitsF> viewF(T& source)
232 ImageTraitsF> viewF(
const T& source)
240 ImageTraitsF> viewF(T& source, Int x, Int y, Int w, Int h)
248 ImageTraitsF> viewF(
const T& source, Int x, Int y, Int w, Int h)
254inline ImageViewF viewF(
Pt::uint8_t* data, Pt::ssize_t width,
255 Pt::ssize_t height, Pt::ssize_t padding,
258 return ImageViewF(data, width, height, padding, format);
262inline ConstImageViewF viewF(
const Pt::uint8_t* data, Pt::ssize_t width,
263 Pt::ssize_t height, Pt::ssize_t padding,
266 return ConstImageViewF(data, width, height, padding, format);
275template <
typename From,
typename P>
278 ConstSpan<
typename From::Format,
279 typename From::Traits> fromSpan( from, 0, 0, from.width() );
281 for(Pt::ssize_t y = 0; y < from.height(); ++y)
284 fromSpan.advanceLines(1);
293template <
typename From,
typename To>
296 std::size_t w = std::min(from.width(), to.width());
297 Pt::ssize_t h = std::min(from.height(), to.height());
299 ConstSpan<
typename From::Format,
300 typename From::Traits> fromSpan( from, 0, 0, w );
302 Span<
typename To::Format,
303 typename To::Traits> toSpan( to, 0, 0, w );
305 for(Pt::ssize_t y = 0; y < h; ++y)
308 fromSpan.advanceLines(1);
309 toSpan.advanceLines(1);
319#include <Pt/Gfx/View.hpp>
Read-only image region.
Definition View.h:125
Non-owning image region.
Definition View.h:65
uint_type uint8_t
Unsigned 8-bit integer type.
Definition Api-Types.h:24
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 copyViewTo(const From &from, P &to)
Copies the pixels of a view to a pixel position.
Definition View.h:276
void copyView(const From &from, To &to)
Copies the pixels of a view to another one.
Definition View.h:294
Core module.
Definition Allocator.h:33