7class Stream :
public PixelStream {
9 Stream(
const Rasterizable *data, Box bounds)
11 bounds_(std::move(bounds)),
15 void Read(Color *buf, uint16_t size)
override {
18 for (
int i = 0; i < size; ++i) {
21 if (x_ < bounds_.xMax()) {
28 if (y[0] == y[size - 1]) {
29 if (data_->readColorRect(x[0], y[0], x[size - 1], y[0], buf)) {
30 for (
int i = 1; i < size; ++i) {
35 data_->readColors(x, y, size, buf);
39 void Skip(uint32_t count)
override {
40 auto w = bounds_.width();
43 if (x_ > bounds_.xMax()) {
50 const Rasterizable *data_;
55static const int kMaxBufSize = 32;
76 if (count == 0)
return;
87 while (offset < count) {
91 if (bounds.
contains(x[offset], y[offset])) {
135 return std::unique_ptr<PixelStream>(
new Stream(
this, this->
extents()));
139 const Box &bounds)
const {
140 return std::unique_ptr<PixelStream>(
new Stream(
this, bounds));
161 object.readColorRect(extents.
xMin() - dx, extents.
yMin() - dy,
167 output.
write(buf, count);
171inline void FillPaintRectOverOpaqueBg(DisplayOutput &output,
const Box &extents,
172 int16_t dx, int16_t dy, Color
bgcolor,
173 const Rasterizable &
object,
175 int32_t count = extents.area();
178 object.readColorRect(extents.xMin() - dx, extents.yMin() - dy,
179 extents.xMax() - dx, extents.yMax() - dy, buf);
183 for (
int i = 0; i < count; i++) {
186 output.setAddress(extents, mode);
187 output.write(buf, count);
191inline void FillPaintRectOverBg(DisplayOutput &output,
const Box &extents,
192 int16_t dx, int16_t dy, Color
bgcolor,
194 int32_t count = extents.area();
197 object.readColorRect(extents.xMin() - dx, extents.yMin() - dy,
198 extents.xMax() - dx, extents.yMax() - dy, buf);
202 for (
int i = 0; i < count; i++) {
205 output.setAddress(extents, mode);
206 output.write(buf, count);
211inline void WriteRectVisible(DisplayOutput &output,
const Box &extents,
212 int16_t dx, int16_t dy,
const Rasterizable &
object,
214 int32_t count = extents.area();
217 object.readColorRect(extents.xMin() - dx, extents.yMin() - dy,
218 extents.xMax() - dx, extents.yMax() - dy, buf);
220 if (buf[0] != color::Transparent) {
221 output.fillRect(mode, extents, buf[0]);
224 BufferedPixelWriter
writer(output, mode);
226 for (int16_t j = extents.yMin(); j <= extents.yMax(); ++j) {
227 for (int16_t i = extents.xMin(); i <= extents.xMax(); ++i) {
235inline void WriteRectVisibleOverOpaqueBg(DisplayOutput &output,
236 const Box &extents, int16_t dx,
238 const Rasterizable &
object,
240 int32_t count = extents.area();
243 object.readColorRect(extents.xMin() - dx, extents.yMin() - dy,
244 extents.xMax() - dx, extents.yMax() - dy, buf);
246 if (buf[0] != color::Transparent) {
250 BufferedPixelWriter
writer(output, mode);
252 for (int16_t j = extents.yMin(); j <= extents.yMax(); ++j) {
253 for (int16_t i = extents.xMin(); i <= extents.xMax(); ++i) {
254 if (*ptr != color::Transparent)
262inline void WriteRectVisibleOverBg(DisplayOutput &output,
const Box &extents,
263 int16_t dx, int16_t dy, Color
bgcolor,
264 const Rasterizable &
object,
266 int32_t count = extents.area();
269 object.readColorRect(extents.xMin() - dx, extents.yMin() - dy,
270 extents.xMax() - dx, extents.yMax() - dy, buf);
272 if (buf[0] != color::Transparent) {
276 BufferedPixelWriter
writer(output, mode);
278 for (int16_t j = extents.yMin(); j <= extents.yMax(); ++j) {
279 for (int16_t i = extents.xMin(); i <= extents.xMax(); ++i) {
280 if (*ptr != color::Transparent)
316 Box(std::max(x,
box.xMin()), std::max(y,
box.yMin()),
319 s.dx(),
s.dy(), *
this, mode);
322 }
else if (
bgcolor.a() == 0xFF) {
332 Box(std::max(x,
box.xMin()), std::max(y,
box.yMin()),
347 Box(std::max(x,
box.xMin()), std::max(y,
box.yMin()),
363 Box(std::max(x,
box.xMin()), std::max(y,
box.yMin()),
366 s.dx(),
s.dy(), *
this, mode);
369 }
else if (
bgcolor.a() == 0xFF) {
379 Box(std::max(x,
box.xMin()), std::max(y,
box.yMin()),
395 Box(std::max(x,
box.xMin()), std::max(y,
box.yMin()),
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).
int32_t area() const
Area in pixels.
int16_t yMin() const
Minimum y (inclusive).
void writePixel(int16_t x, int16_t y, Color color)
ARGB8888 color stored as a 32-bit unsigned integer.
The abstraction for drawing to a display.
virtual void write(Color *color, uint32_t pixel_count)=0
Write pixels into the current address window.
void fillRect(BlendingMode blending_mode, const Box &rect, Color color)
Fill a single rectangle. Invalidates the address window.
void setAddress(const Box &bounds, BlendingMode blending_mode)
Convenience overload for setAddress() using a Box.
virtual Box extents() const =0
Return the bounding box encompassing all pixels that need to be drawn.
Drawable that can provide a color for any point within its extents.
void readColorsMaybeOutOfBounds(const int16_t *x, const int16_t *y, uint32_t count, Color *result, Color out_of_bounds_color=color::Transparent) const
Read colors for points that may be out of bounds.
void drawTo(const Surface &s) const override
Default drawTo() using readColors().
std::unique_ptr< PixelStream > createStream() const override
Default createStream() using readColors().
virtual void readColors(const int16_t *x, const int16_t *y, uint32_t count, Color *result) const =0
Read colors for the given points.
virtual bool readColorRect(int16_t xMin, int16_t yMin, int16_t xMax, int16_t yMax, Color *result) const
Read colors for a rectangle.
virtual TransparencyMode getTransparencyMode() const
Return the transparency mode for pixels in this stream.
Low-level handle used to draw to an underlying device.
Defines 140 opaque HTML named colors.
BlendingMode
Porter-Duff style blending modes.
Color AlphaBlend(Color bgc, Color fgc)
TransparencyMode
Transparency information for a stream or color mode.
@ kNone
All colors are fully opaque.
Color AlphaBlendOverOpaque(Color bgc, Color fgc)
FillMode
Specifies whether a Drawable should fill its entire extents box, including fully transparent pixels.
@ kExtents
Fill the entire extents box (possibly with fully transparent pixels).