5#include "roo_backport.h"
6#include "roo_backport/byte.h"
24 line_width_bytes_((
bounds.width() + 7) / 8) {}
28 typename std::enable_if<!std::is_same<U, roo::byte>::value,
34 const roo::byte*
data()
const {
return data_; }
42 if (!bounds_.
contains(x, y))
return inverted_;
48 return (
bool)(b & (roo::byte{0x80} >>
pixel_index)) ^ inverted_;
54 return inverted_ ? isAllUnset(x, y, mask, ~
lines)
55 : isAllSet(x, y, mask,
lines);
61 return inverted_ ? isAllSet(x, y, mask, ~
lines)
62 : isAllUnset(x, y, mask,
lines);
71 const roo::byte*
ptr = data_ + (x - bounds_.
xMin()) / 8 +
72 (y - bounds_.
yMin()) * line_width_bytes_;
74 if ((*
ptr & mask) != mask)
return false;
75 ptr += line_width_bytes_;
80 inline bool isAllUnset(int16_t x, int16_t y, roo::byte mask,
81 uint8_t lines)
const {
82 const roo::byte* ptr = data_ + (x - bounds_.
xMin()) / 8 +
83 (y - bounds_.
yMin()) * line_width_bytes_;
85 if ((*ptr & mask) != roo::byte{0})
return false;
86 ptr += line_width_bytes_;
91 const roo::byte* data_;
99 uint32_t line_width_bytes_;
110 address_window_(0, 0, 0, 0),
118 address_window_ =
Box(x0, y0, x1, y1);
119 blending_mode_ = mode;
129 if (!clip_mask_.
isMasked(cursor_x_, cursor_y_)) {
132 if (++cursor_x_ > address_window_.
xMax()) {
134 cursor_x_ = address_window_.
xMin();
144 if (!clip_mask_.
isMasked(cursor_x_, cursor_y_)) {
145 filler.fillPixel(cursor_x_, cursor_y_);
147 if (++cursor_x_ > address_window_.
xMax()) {
149 cursor_x_ = address_window_.
xMin();
157 while (count-- > 0) {
158 fillSingleRect(mode, *
color++, *x0++, *y0++, *x1++, *y1++);
164 while (count-- > 0) {
165 fillSingleRect(mode,
color, *x0++, *y0++, *x1++, *y1++);
225 if (y0 < bounds.
yMin()) {
226 if (y1 < bounds.
yMin()) {
228 rfiller.fillRect(x0, y0, x1, y1);
233 rfiller.fillRect(x0, y0, x1, bounds.
yMin() - 1);
237 if (x0 < bounds.
xMin()) {
238 if (x1 < bounds.
xMin()) {
240 rfiller.fillRect(x0, y0, x1, y1);
245 rfiller.fillRect(x0, y0, bounds.
xMin() - 1, y1);
249 if (x1 > bounds.
xMax()) {
250 if (x0 > bounds.
xMax()) {
252 rfiller.fillRect(x0, y0, x1, y1);
257 rfiller.fillRect(bounds.
xMax() + 1, y0, x1, y1);
261 if (y1 > bounds.
yMax()) {
262 if (y0 > bounds.
yMax()) {
264 rfiller.fillRect(x0, y0, x1, y1);
269 rfiller.fillRect(x0, bounds.
yMax() + 1, x1, y1);
276 uint8_t yshift = (y0 - bounds.
yMin()) % 8;
277 for (int16_t yc0 = y0; yc0 <= y1;) {
278 int16_t yc1 = yc0 - yshift + 7;
279 if (yc1 > y1) yc1 = y1;
280 uint8_t lines = yc1 - yc0 + 1;
281 uint8_t xshift = (x0 - bounds.
xMin()) % 8;
282 for (int16_t xc0 = x0; xc0 <= x1;) {
283 int16_t xc1 = xc0 - xshift + 7;
284 roo::byte mask = roo::byte{0xFF} >> xshift;
286 mask &= (roo::byte{0xFF} << (xc1 - x1));
289 if (!clip_mask_.
isAllMasked(xc0, yc0, mask, lines)) {
291 rfiller.fillRect(xc0, yc0, xc1, yc1);
294 for (int16_t y = yc0; y <= yc1; ++y) {
295 for (int16_t x = xc0; x <= xc1; ++x) {
297 pfiller.fillPixel(x, y);
304 xc0 = xc0 - xshift + 8;
307 yc0 = yc0 - yshift + 8;
312 const Box& bounds()
const {
return clip_mask_.
bounds(); }
314 DisplayOutput& output_;
BufferedRectWriter & writer
Axis-aligned integer rectangle.
int16_t xMin() const
Minimum x (inclusive).
int16_t xMax() const
Maximum x (inclusive).
bool contains(int16_t x, int16_t y) const
Return whether the point (x, y) lies within the box.
int16_t yMax() const
Maximum y (inclusive).
int16_t yMin() const
Minimum y (inclusive).
Buffered filler for arbitrary pixels using a single color.
Buffered writer for arbitrary pixels with per-pixel colors.
Filtering device that applies a clip mask.
virtual ~ClipMaskFilter()
void setAddress(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, BlendingMode mode) override
Set a rectangular window filled by subsequent calls to write().
void write(Color *color, uint32_t pixel_count) override
Write pixels into the current address window.
void writeRects(BlendingMode mode, Color *color, int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, uint16_t count) override
Draw the specified rectangles (per-rectangle colors). Invalidates the address window.
ClipMaskFilter(DisplayOutput &output, const ClipMask *clip_mask, int16_t dx=0, int16_t dy=0)
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) override
Draw a rectangle represented in the device's native color format.
const ColorFormat & getColorFormat() const override
Return the native color format used by this device for direct drawing.
void fill(Color color, uint32_t pixel_count) override
Write pixel_count copies of the same color into the current address window.
void writePixels(BlendingMode mode, Color *color, int16_t *x, int16_t *y, uint16_t pixel_count) override
Draw the specified pixels (per-pixel colors). Invalidates the address window.
void fillPixels(BlendingMode mode, Color color, int16_t *x, int16_t *y, uint16_t pixel_count) override
Draw the specified pixels using the same color. Invalidates the address window.
void fillRects(BlendingMode mode, Color color, int16_t *x0, int16_t *y0, int16_t *x1, int16_t *y1, uint16_t count) override
Draw the specified rectangles using the same color. Invalidates the address window.
Binary clip mask using a packed bit buffer.
bool isAllMasked(int16_t x, int16_t y, roo::byte mask, uint8_t lines) const
Return whether all bits in a block are masked.
bool isMasked(int16_t x, int16_t y) const
Return whether a point is masked out.
bool inverted() const
Return inversion flag.
const roo::byte * data() const
Return raw data buffer.
ClipMask(const U *data, Box bounds)
Deprecated: use the roo::byte* constructor instead.
void setInverted(bool inverted)
Set inversion behavior.
bool isAllUnmasked(int16_t x, int16_t y, roo::byte mask, uint8_t lines) const
Return whether all bits in a block are unmasked.
const Box & bounds() const
Return mask bounds.
ClipMask(const roo::byte *data, Box bounds, bool inverted=false)
Construct a clip mask.
ARGB8888 color stored as a 32-bit unsigned integer.
The abstraction for drawing to a display.
virtual const ColorFormat & getColorFormat() const =0
Return the native color format used by this device for direct drawing.
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.
virtual void fillPixels(BlendingMode blending_mode, Color color, int16_t *x, int16_t *y, uint16_t pixel_count)=0
Draw the specified pixels using the same color. Invalidates the address window.
virtual void writePixels(BlendingMode blending_mode, Color *color, int16_t *x, int16_t *y, uint16_t pixel_count)=0
Draw the specified pixels (per-pixel colors). Invalidates the address window.
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.