13#include "roo_io/data/byte_order.h"
14#include "roo_io/data/read.h"
15#include "roo_io/memory/load.h"
16#include "roo_io/memory/memory_iterable.h"
21template <
typename Resource>
22using StreamType =
decltype(std::declval<Resource>().iterator());
39template <
typename ByteStream,
typename ColorMode,
ColorPixelOrder pixel_order,
49template <
typename ByteStream,
typename ColorMode,
ColorPixelOrder pixel_order,
59template <
typename ByteStream,
typename ColorMode,
ColorPixelOrder pixel_order,
74template <
typename Resource,
typename ColorMode,
ColorPixelOrder pixel_order,
76 int pixels_per_byte = ColorTraits<ColorMode>::pixels_per_byte>
81 pixel_index_(
ColorTraits<ColorMode>::pixels_per_byte),
98 return cache_[pixel_index_++];
113 if (pixel_index_ == 0) {
127 io.loadBulk(color_mode_, stream_.read(), cache_);
130 StreamType<Resource> stream_;
131 uint8_t pixel_index_;
132 const ColorMode& color_mode_;
133 Color cache_[ColorTraits<ColorMode>::pixels_per_byte];
137template <
typename Resource,
typename ColorMode,
ColorPixelOrder pixel_order,
156 return read(stream_, color_mode_);
160 stream_.skip(count * ColorMode::bits_per_pixel / 8);
169 const ColorMode& color_mode_;
176 int8_t pixels_per_byte = ColorTraits<ColorMode>::pixels_per_byte,
177 typename storage_type = ColorStorageType<ColorMode>>
179 Color operator()(
const roo::byte* p, uint32_t offset,
180 const ColorMode& color_mode)
const {
181 SubByteColorIo<ColorMode, pixel_order> io;
182 int pixel_index = offset % pixels_per_byte;
183 const roo::byte* target = p + offset / pixels_per_byte;
184 return color_mode.toArgbColor(io.loadRaw(*target, pixel_index));
190 typename storage_type>
191struct Reader<ColorMode, pixel_order, byte_order, 1, storage_type> {
192 Color operator()(
const roo::byte* p, uint32_t offset,
193 const ColorMode& color_mode)
const {
194 const roo::byte* src = p + offset * ColorTraits<ColorMode>::bytes_per_pixel;
195 return ColorIo<ColorMode, byte_order>().load(src, color_mode);
199template <
typename PtrTypeT>
200struct PtrTypeResolver {
201 using PtrType = PtrTypeT;
206struct PtrTypeResolver<
const uint8_t*> {
207 using PtrType =
const roo::byte*;
217template <
typename PtrTypeT,
typename ColorModeT,
219 ByteOrder byte_order = roo_io::kBigEndian>
227 pixel_order, byte_order>;
229 using Reader = internal::Reader<ColorMode, pixel_order, byte_order>;
234 :
Raster(
Box(0, 0, width - 1, height - 1),
264 return std::unique_ptr<StreamType>(
new StreamType(
265 roo_io::UnsafeGenericMemoryIterator<PtrType>(ptr_), color_mode_));
269 return std::unique_ptr<PixelStream>(
new StreamType(
270 roo_io::UnsafeGenericMemoryIterator<PtrType>(ptr_), color_mode_));
275 StreamType(roo_io::UnsafeGenericMemoryIterator<PtrType>(ptr_),
283 while (count-- > 0) {
285 read(ptr_, *x++ - extents_.
xMin() + (*y++ - extents_.
yMin()) * width_,
303 (
static_cast<size_t>(width_) +
309 const roo::byte* data =
reinterpret_cast<const roo::byte*
>(ptr_);
326 return read(ptr_, x - extents_.
xMin() + (y - extents_.
yMin()) * width_,
333 void drawTo(
const Surface&
s)
const override {
336 if (bounds.
empty())
return;
340 s.bgcolor().a() == 0);
365 if (blend_is_source) {
366 int16_t src_x0 = bounds.
xMin() - extents_.
xMin();
367 int16_t src_y0 = bounds.
yMin() - extents_.
yMin();
368 int16_t src_x1 = bounds.
xMax() - extents_.
xMin();
369 int16_t src_y1 = bounds.
yMax() - extents_.
yMin();
370 int16_t dst_x0 = bounds.
xMin() + s.
dx();
371 int16_t dst_y0 = bounds.
yMin() + s.
dy();
372 size_t row_width_bytes;
373 if constexpr (ColorTraits<ColorMode>::pixels_per_byte == 1) {
374 row_width_bytes = width_ * ColorTraits<ColorMode>::bytes_per_pixel;
377 (width_ + ColorTraits<ColorMode>::pixels_per_byte - 1) /
378 ColorTraits<ColorMode>::pixels_per_byte;
381 src_y1, dst_x0, dst_y0);
388 StreamType stream(roo_io::UnsafeGenericMemoryIterator<PtrType>(ptr_),
395 StreamType(roo_io::UnsafeGenericMemoryIterator<PtrType>(ptr_),
411template <
typename ColorMode,
413 ByteOrder byte_order = roo_io::kBigEndian>
415 :
public Raster<roo::byte*, ColorMode, pixel_order, byte_order> {
441template <
typename ColorMode,
443 ByteOrder byte_order = roo_io::kBigEndian>
445 :
public Raster<const roo::byte*, ColorMode, pixel_order, byte_order> {
447 using Raster<
const roo::byte*,
ColorMode, pixel_order, byte_order>::Raster;
472template <
typename ColorMode,
474 ByteOrder byte_order = roo_io::kBigEndian>
476 pixel_order, byte_order> {
505template <
typename ColorMode>
509template <
typename ColorMode>
513template <
typename ColorMode>
517template <
typename ColorMode>
520 roo_io::kLittleEndian>;
522template <
typename ColorMode>
526template <
typename ColorMode>
528 roo_io::kLittleEndian>;
Axis-aligned integer rectangle.
int16_t width() const
Width in pixels (inclusive coordinates).
int16_t xMin() const
Minimum x (inclusive).
int16_t xMax() const
Maximum x (inclusive).
bool empty() const
Return whether the box is empty.
int16_t height() const
Height in pixels (inclusive coordinates).
Box translate(int16_t x_offset, int16_t y_offset) const
Return a translated copy of this box.
int16_t yMax() const
Maximum y (inclusive).
static Box Intersect(const Box &a, const Box &b)
Return the intersection of two boxes (may be empty).
int16_t yMin() const
Minimum y (inclusive).
ARGB8888 color stored as a 32-bit unsigned integer.
ConstDramRaster(int16_t width, int16_t height, Box extents, const uint8_t *ptr, const ColorMode &color_mode=ColorMode())
ConstDramRaster(Box extents, Box anchor_extents, const uint8_t *ptr, const ColorMode &color_mode=ColorMode())
ConstDramRaster(int16_t width, int16_t height, const uint8_t *ptr, const ColorMode &color_mode=ColorMode())
ConstDramRaster(Box extents, const uint8_t *ptr, const ColorMode &color_mode=ColorMode())
virtual void drawDirectRect(const roo::byte *data, size_t row_width_bytes, int16_t src_x0, int16_t src_y0, int16_t src_x1, int16_t src_y1, int16_t dst_x0, int16_t dst_y0)
Draw a rectangle represented in the device's native color format.
DramRaster(Box extents, Box anchor_extents, uint8_t *ptr, const ColorMode &color_mode=ColorMode())
DramRaster(Box extents, uint8_t *ptr, const ColorMode &color_mode=ColorMode())
DramRaster(int16_t width, int16_t height, Box extents, uint8_t *ptr, const ColorMode &color_mode=ColorMode())
DramRaster(int16_t width, int16_t height, uint8_t *ptr, const ColorMode &color_mode=ColorMode())
Stream of pixels in row-major order.
ProgMemRaster(Box extents, Box anchor_extents, const uint8_t *PROGMEM ptr, const ColorMode &color_mode=ColorMode())
ProgMemRaster(int16_t width, int16_t height, Box extents, const uint8_t *PROGMEM ptr, const ColorMode &color_mode=ColorMode())
ProgMemRaster(int16_t width, int16_t height, const uint8_t *PROGMEM ptr, const ColorMode &color_mode=ColorMode())
ProgMemRaster(Box extents, const uint8_t *PROGMEM ptr, const ColorMode &color_mode=ColorMode())
void Skip(uint32_t count) override
Skip count pixels.
void Read(Color *buf, uint16_t size) override
Read up to size pixels into buf.
TransparencyMode transparency() const
const ColorMode & color_mode() const
RasterPixelStream(StreamType< Resource > stream, const ColorMode &color_mode)
void skip(uint32_t count)
Pixel stream that reads from a raw byte resource.
void Read(Color *buf, uint16_t size) override
Read up to size pixels into buf.
const ColorMode & color_mode() const
RasterPixelStream(StreamType< Resource > stream, const ColorMode &color_mode)
void Skip(uint32_t count) override
Skip count pixels.
TransparencyMode transparency() const
void skip(uint32_t count)
Non-owning raster view over a pixel buffer.
void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const override
Read colors for the given points.
bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, Color *result) const override
Read colors for a rectangle.
typename internal::PtrTypeResolver< PtrTypeT >::PtrType PtrType
Box anchorExtents() const override
Return the bounds used for alignment.
std::unique_ptr< PixelStream > createStream() const override
Create a stream covering the full extents().
TransparencyMode transparency() const
Raster(int16_t width, int16_t height, Box extents, PtrTypeT ptr, const ColorMode &color_mode=ColorMode())
Construct a raster with custom extents and buffer dimensions.
TransparencyMode getTransparencyMode() const override
Return the transparency mode for pixels in this stream.
Raster(int16_t width, int16_t height, PtrTypeT ptr, const ColorMode &color_mode=ColorMode())
Construct a raster for a width/height buffer.
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
internal::Reader< ColorMode, pixel_order, byte_order > Reader
std::unique_ptr< PixelStream > createStream(const Box &bounds) const override
Create a stream for the given clipped bounds.
Color get(int16_t x, int16_t y) const
RasterPixelStream< roo_io::UnsafeGenericMemoryIterable< PtrType >, ColorMode, pixel_order, byte_order > StreamType
const PtrType buffer() const
Raster(Box extents, PtrTypeT ptr, const ColorMode &color_mode=ColorMode())
Construct a raster with extents and a buffer pointer.
const ColorMode & color_mode() const
std::unique_ptr< StreamType > createRawStream() const
Raster(Box extents, Box anchor_extents, PtrTypeT ptr, const ColorMode &color_mode=ColorMode())
Construct a raster with extents and anchor extents.
Drawable that can provide a color for any point within its extents.
Low-level handle used to draw to an underlying device.
int16_t dy() const
Return the y offset to apply to drawn objects.
Color bgcolor() const
Return the background color used for blending.
int16_t dx() const
Return the x offset to apply to drawn objects.
BlendingMode blending_mode() const
Return the default blending mode for drawing.
FillMode fill_mode() const
Return the fill mode the drawable should observe. FillMode::kVisible If FillMode::kExtents,...
DisplayOutput & out() const
Return the device output.
SubRectangleStream< Stream > MakeSubRectangle(Stream stream, const Box &extents, const Box &bounds)
void FillRectFromStream(DisplayOutput &output, const Box &extents, PixelStream *stream, Color bgcolor, FillMode fill_mode, BlendingMode blending_mode, TransparencyMode transparency)
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
@ kSourceOverOpaque
Similar to kSourceOver, but assumes that the destination is opaque.
@ kSource
The new ARGB8888 value completely replaces the old one.
@ kSourceIn
The source that overlaps the destination, replaces the destination.
@ kSourceAtop
Source which overlaps the destination, replaces the destination. Destination is placed elsewhere.
@ kSourceOver
Source is placed (alpha-blended) over the destination. This is the default blending mode.
decltype(std::declval< Resource >().iterator()) StreamType
Stream type produced by a resource iterable.
TransparencyMode
Transparency information for a stream or color mode.
@ kNone
All colors are fully opaque.
std::unique_ptr< PixelStream > SubRectangle(Stream stream, const Box &extents, const Box &bounds)
Create a pixel stream over a sub-rectangle of a larger stream.
static const uint8_t font[] PROGMEM
@ kExtents
Fill the entire extents box (possibly with fully transparent pixels).
roo_io::ByteOrder ByteOrder
Color operator()(ByteStream &in, const ColorMode &color_mode) const
Color operator()(ByteStream &in, const ColorMode &color_mode) const
Color operator()(ByteStream &in, const ColorMode &color_mode) const
Color operator()(ByteStream &in, const ColorMode &color_mode) const
Traits for a color mode's storage characteristics.