29 #ifndef PT_GFX_PIXELBASE_H
30 #define PT_GFX_PIXELBASE_H
32 #include <Pt/Gfx/Api.h>
33 #include <Pt/Gfx/ViewBase.h>
34 #include <Pt/Gfx/Color.h>
62 const ViewBase& view()
const
76 void advance(Pt::ssize_t n)
83 _base = onSkipPadding();
86 void advanceLines(Pt::ssize_t n)
88 _base = onAdvanceLines(n);
91 template <
typename ColorT>
92 ColorT getColor()
const;
94 void getColors(
ColorF* colors, std::size_t length)
const
96 onGetColors(colors, length);
99 void getColors(
Color* colors, std::size_t length)
const
101 onGetColors(colors, length);
104 void assign(
const ColorF& color)
109 void assign(
const Color& color)
114 void assign(
const Color* colors, std::size_t length)
116 onAssign(colors, length);
119 void assign(
const ColorF* colors, std::size_t length)
121 onAssign(colors, length);
124 bool assign(
const PixelBase& p, std::size_t length)
126 return onAssignPixels(p, length);
129 void fill(std::size_t n,
const ColorF& color)
131 onFillColor(n, color);
134 void fill(std::size_t n,
const Color& color)
136 onFillColor(n, color);
139 bool copy(
PixelBase& p, std::size_t length)
const
141 return onCopyPixels(p, length);
144 PixelBase* clone(PixelStorage& store)
const
146 return onClone(store);
149 const std::type_info& getType()
const
154 template <
typename T>
156 {
return getType() ==
typeid(T) ? static_cast<T*>(
this) :
nullptr; }
158 template <
typename T>
159 const T* tryCast()
const
160 {
return getType() ==
typeid(T) ? static_cast<const T*>(
this) :
nullptr; }
163 virtual PixelBase* onClone(PixelStorage& store)
const
166 virtual const std::type_info& onGetType()
const = 0;
178 virtual ColorF onGetColorF()
const = 0;
180 virtual Color onGetColor()
const = 0;
182 virtual void onGetColors(
ColorF* colors, std::size_t length)
const = 0;
184 virtual void onGetColors(
Color* colors, std::size_t length)
const = 0;
186 virtual void onSetColor(
const ColorF& color)
188 onFillColor(1, color);
191 virtual void onSetColor(
const Color& color)
193 onFillColor(1, color);
196 virtual void onAssign(
const Color* colors, std::size_t length) = 0;
198 virtual void onAssign(
const ColorF* colors, std::size_t length) = 0;
200 virtual void onFillColor(std::size_t n,
const ColorF& color) = 0;
202 virtual void onFillColor(std::size_t n,
const Color& color) = 0;
204 virtual bool onAssignPixels(
const PixelBase& p, std::size_t length)
207 virtual bool onCopyPixels(
PixelBase& p, std::size_t length)
const
211 const ViewBase* _view;
216 template <
typename ColorT>
217 inline ColorT PixelBase::getColor()
const
219 return this->onGetColorF();
224 inline ColorF PixelBase::getColor<ColorF>()
const
226 return this->onGetColorF();
231 inline Color PixelBase::getColor<Color>()
const
233 return this->onGetColor();
243 static const std::size_t MaxSize =
sizeof(
void*) * 16;
246 template <
typename T,
typename... Args>
247 T* create(Args&&... args)
249 static_assert(
sizeof(T) <= PixelStorage::MaxSize,
250 "insufficient pixel storage");
252 return new (&_data.mem) T(std::forward<Args>(args)...);
262 alignas(PixelBase)
char mem[PixelStorage::MaxSize];
Standard color type.
Definition: Color.h:46
uint_type uint8_t
Unsigned 8-bit integer type.
Definition: Types.h:18
Pixel base class.
Definition: PixelBase.h:51