FastLED 3.9.15
Loading...
Searching...
No Matches
raster_sparse.cpp
Go to the documentation of this file.
1#include "fl/stdint.h"
2
3#include "fl/draw_visitor.h"
4#include "fl/leds.h"
5#include "fl/raster_sparse.h"
6#include "fl/tile2x2.h"
7
8namespace fl {
9
10void XYRasterU8Sparse::draw(const CRGB &color, const XYMap &xymap, CRGB *out) {
11 XYDrawComposited visitor(color, xymap, out);
12 draw(xymap, visitor);
13}
14
15void XYRasterU8Sparse::draw(const CRGB &color, Leds *leds) {
16 draw(color, leds->xymap(), leds->rgb());
17}
18
20 const XYMap &xymap, CRGB *out) {
21 XYDrawGradient visitor(gradient, xymap, out);
22 draw(xymap, visitor);
23}
24
26 drawGradient(gradient, leds->xymap(), leds->rgb());
27}
28
30 // Tile2x2_u8::Rasterize(tiles, this, mAbsoluteBoundsSet ? &mAbsoluteBounds
31 // : nullptr);
32 if (tiles.size() == 0) {
33 FASTLED_WARN("Rasterize: no tiles");
34 return;
35 }
36 const rect<u16> *optional_bounds =
38
39 // Check if the bounds are set.
40 // draw all now unconditionally.
41 for (const auto &tile : tiles) {
42 // Rasterize the tile.
43 rasterize_internal(tile, optional_bounds);
44 }
45 return;
46}
47
49 const rect<u16> *optional_bounds) {
50 const vec2<u16> &origin = tile.origin();
51 for (int x = 0; x < 2; ++x) {
52 for (int y = 0; y < 2; ++y) {
53 u8 value = tile.at(x, y);
54 if (!value) {
55 continue;
56 }
57 int xx = origin.x + x;
58 int yy = origin.y + y;
59 if (optional_bounds && !optional_bounds->contains(xx, yy)) {
60 continue;
61 }
62 write(vec2<u16>(xx, yy), value);
63 }
64 }
65}
66
67} // namespace fl
68
69// XYRasterSparse_CRGB implementation
71 for (const auto &it : mSparseGrid) {
72 auto pt = it.first;
73 if (!xymap.has(pt.x, pt.y)) {
74 continue;
75 }
76 u32 index = xymap(pt.x, pt.y);
77 const CRGB &color = it.second;
78 // Only draw non-black pixels (since black represents "no data")
79 if (color.r != 0 || color.g != 0 || color.b != 0) {
80 out[index] = color;
81 }
82 }
83}
84
86 draw(leds->xymap(), leds->rgb());
87}
CRGB leds[NUM_LEDS]
int y
Definition simple.h:93
int x
Definition simple.h:92
XYMap xymap(WIDTH, HEIGHT, SERPENTINE)
fl::size size() const
Definition slice.h:142
u8 & at(int x, int y)
Definition tile2x2.h:39
vec2< u16 > origin() const
Definition tile2x2.h:56
void draw(const XYMap &xymap, CRGB *out)
void rasterize(const vec2< u16 > &pt, u8 value)
fl::rect< u16 > mAbsoluteBounds
void draw(const CRGB &color, const XYMap &xymap, CRGB *out)
void drawGradient(const Gradient &gradient, const XYMap &xymap, CRGB *out)
void rasterize_internal(const Tile2x2_u8 &tile, const rect< u16 > *optional_bounds=nullptr)
void write(const vec2< u16 > &pt, u8 value)
void draw(float pos)
Definition curr.h:538
unsigned char u8
Definition int.h:17
Slice< T > span
Definition span.h:8
IMPORTANT!
Definition crgb.h:20
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:86
bool contains(const vec2< T > &p) const
Definition geometry.h:453
value_type y
Definition geometry.h:191
value_type x
Definition geometry.h:190
#define FASTLED_WARN
Definition warn.h:7