26template <
typename RawStreamable>
28 .createRawStream())::element_type;
30template <
typename RawStreamable>
32 typename decltype(std::declval<const RawStreamable>()
33 .CreateClippedRawStream(
34 std::declval<Box>()))::element_type;
36template <
typename RawStreamable>
37using ColorModeOf =
decltype(std::declval<const RawStreamable>().color_mode());
41template <
typename RawPixelStream>
78template <
typename RawPixelStream>
84 int count = extents.
area();
101 while (count-- > 0) {
111template <
typename RawPixelStream>
143template <
typename RawPixelStream>
157 delegate_->skip(width_skip_);
167 for (
int i = 0;
i < count;
i++)
next();
175 std::unique_ptr<RawPixelStream> delegate_;
181template <
typename RawPixelStream>
185 return std::unique_ptr<SubRectangleRawStream<RawPixelStream>>(
193 std::unique_ptr<SubRectangleRawStream<RawStream>>
operator()(
213template <
typename RawStreamable>
216 std::declval<Box>()),
218 std::unique_ptr<NativelyClippedRawStreamTypeOf<RawStreamable>>
operator()(
220 return streamable.CreateClippedRawStream(clip_box);
226template <
typename RawStreamable>
229 std::declval<RawStreamable>(), std::declval<Box>()))::element_type;
231template <
typename RawStreamable>
232std::unique_ptr<ClipperedRawStreamTypeOf<RawStreamable>>
234 const Box &clip_box) {
262 : extents_(0, 0, width - 1, height - 1), color_(
color) {}
267 return std::unique_ptr<RawStream>(
new RawStream(color_));
271 return std::unique_ptr<RawStream>(
new RawStream(color_));
279template <
typename RawStreamable>
286 : streamable_(std::
move(
other.streamable_)) {}
288 Box extents()
const override {
return streamable_.extents(); }
295 return std::unique_ptr<PixelStream>(
297 streamable_.createRawStream()));
301 return std::unique_ptr<PixelStream>(
308 return streamable_.createRawStream();
312 template <
typename RawStream>
315 Stream(std::unique_ptr<RawStream>
raw) : raw_(std::
move(
raw)) {}
317 void Read(Color *buf, uint16_t count)
override {
318 while (count-- > 0) *buf++ = raw_->next();
322 std::unique_ptr<RawStream> raw_;
325 void drawTo(
const Surface &s)
const override {
327 s.clip_box(), streamable_.extents().translate(s.dx(), s.dy()));
328 if (bounds.empty())
return;
329 if (streamable_.extents().width() == bounds.width() &&
330 streamable_.extents().height() == bounds.height()) {
332 auto stream = streamable_.createRawStream();
334 s.bgcolor(), s.fill_mode(),
338 streamable_, bounds.translate(-s.dx(), -s.dy()));
340 s.bgcolor(), s.fill_mode(),
345 RawStreamable streamable_;
348template <
typename RawStreamable>
354template <
typename RawStreamable>
359template <
typename RawStreamable,
360 typename RawStream = RawStreamTypeOf<RawStreamable>>
367template <
typename Resource,
typename ColorMode,
typename RawStreamType>
373 Box(0, 0, width - 1, height - 1),
391 return std::unique_ptr<RawStreamType>(
399 ColorMode color_mode_;
405template <
typename RawStreamable,
407 decltype(std::declval<RawStreamable>().createRawStream())>
410 template <
typename...
Args>
413 extents_(
Box::Intersect(streamable_.extents(), clip_box)) {}
417 extents_(
Box::Intersect(streamable_.extents(), clip_box)) {}
423 return streamable_.color_mode();
431 std::unique_ptr<ClipperedRawStreamTypeOf<RawStreamable>>
442template <
typename RawStreamable>
BufferedRectWriter & writer
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 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.
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).
Buffered writer for sequential color values (used with setAddress()).
Buffered writer for arbitrary pixels with per-pixel colors.
std::unique_ptr< ClipperedRawStreamTypeOf< RawStreamable > > CreateClippedRawStream(const Box &clip_box) const
Clipping(const Box &clip_box, Args &&...args)
std::unique_ptr< ClipperedRawStreamTypeOf< RawStreamable > > createRawStream() const
const Box & extents() const
Box anchorExtents() const
Clipping(const Box &clip_box, RawStreamable streamable)
const ColorModeOf< RawStreamable > & color_mode() const
ARGB8888 color stored as a 32-bit unsigned integer.
constexpr bool isOpaque() const
Return true if the color is fully opaque (alpha = 255).
constexpr uint8_t a() const
Alpha channel.
The abstraction for drawing to a display.
void setAddress(const Box &bounds, BlendingMode blending_mode)
Convenience overload for setAddress() using a Box.
const RawStreamable & contents() const
DrawableRawStreamable(DrawableRawStreamable &&other)
Box extents() const override
Return the bounding box encompassing all pixels that need to be drawn.
std::unique_ptr< PixelStream > createStream(const Box &bounds) const override
Create a stream for the given clipped bounds.
decltype(std::declval< RawStreamable >().createRawStream()) createRawStream() const
Box anchorExtents() const override
Return the bounds used for alignment.
DrawableRawStreamable(RawStreamable streamable)
std::unique_ptr< PixelStream > createStream() const override
Create a stream covering the full extents().
Interface for objects that can be drawn to an output device.
Stream of pixels in row-major order.
void skip(uint32_t count)
TransparencyMode transparency() const
const Box & anchorExtents() const
RawStreamableFilledRect(Box extents, Color color)
RawStreamableFilledRect(uint16_t width, uint16_t height, Color color)
std::unique_ptr< RawStream > CreateClippedRawStream(const Box &clip_box) const
std::unique_ptr< RawStream > createRawStream() const
const Box & extents() const
void setColorMode(const ColorMode &color_mode)
const Box & extents() const
const Box & anchorExtents() const
SimpleRawStreamable(int16_t width, int16_t height, Resource resource, const ColorMode &color_mode=ColorMode())
SimpleRawStreamable(Box extents, Box anchor_extents, Resource resource, const ColorMode &color_mode=ColorMode())
const ColorMode & color_mode() const
const Resource & resource() const
std::unique_ptr< RawStreamType > createRawStream() const
Drawable that can provide a sequential pixel stream.
Low-level handle used to draw to an underlying device.
SubRectangleRawStream(std::unique_ptr< RawPixelStream > delegate, int16_t width, int16_t width_skip)
SubRectangleRawStream(SubRectangleRawStream &&)=default
void skip(uint32_t count)
TransparencyMode transparency() const
void FillRectFromRawStream(DisplayOutput &output, const Box &extents, RawPixelStream *stream, Color bgcolor, FillMode fill_mode, BlendingMode blending_mode)
std::unique_ptr< SubRectangleRawStream< RawPixelStream > > SubRectangle(std::unique_ptr< RawPixelStream > delegate, int16_t width, int16_t width_skip)
Defines 140 opaque HTML named colors.
typename decltype(internal::Clipper< RawStreamable >().operator()(std::declval< RawStreamable >(), std::declval< Box >()))::element_type ClipperedRawStreamTypeOf
std::unique_ptr< ClipperedRawStreamTypeOf< RawStreamable > > CreateClippedRawStreamFor(const RawStreamable &streamable, const Box &clip_box)
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.
@ kSourceOver
Source is placed (alpha-blended) over the destination. This is the default blending mode.
decltype(std::declval< const RawStreamable >().color_mode()) ColorModeOf
DrawableRawStreamable< RawStreamable > MakeDrawableRawStreamable(RawStreamable streamable)
Color AlphaBlend(Color bgc, Color fgc)
TransparencyMode
Transparency information for a stream or color mode.
@ kNone
All colors are fully opaque.
@ kCrude
Colors are either fully opaque or fully transparent.
@ kFull
Colors may include partial transparency (alpha channel).
typename decltype(std::declval< const RawStreamable >() .createRawStream())::element_type RawStreamTypeOf
Color AlphaBlendOverOpaque(Color bgc, Color fgc)
typename decltype(std::declval< const RawStreamable >() .CreateClippedRawStream(std::declval< Box >()))::element_type NativelyClippedRawStreamTypeOf
Drawable * MakeNewDrawableRawStreamable(RawStreamable streamable)
Clipping< RawStreamable > Clipped(const Box &clip_box, RawStreamable streamable)
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).
void streamToSurface(const Surface &s, RawStreamable streamable)
BlendingMode blending_mode
std::unique_ptr< NativelyClippedRawStreamTypeOf< RawStreamable > > operator()(const RawStreamable &streamable, const Box &clip_box) const
std::unique_ptr< SubRectangleRawStream< RawStream > > operator()(const RawStreamable &streamable, const Box &clip_box) const
void operator()(DisplayOutput &output, const Box &extents, Color bgcolor, RawPixelStream *stream, BlendingMode blending_mode, TransparencyMode transparency_mode) const
void operator()(DisplayOutput &output, const Box &extents, Color bgcolor, RawPixelStream *stream, BlendingMode mode, TransparencyMode transparency_mode) const