109 if ((a % b) < 0) --q;
122 if (!(px == px))
return 0;
125 return static_cast<fl::i32
>(px * 65536.0f);
132template<
typename Coord>
144 if (!(val == val))
return 0;
147 return static_cast<fl::i32
>(val * 65536.0);
156 return static_cast<fl::i32
>(val) << 16;
163 const fl::i32 r = val.raw();
174#define FL_POLYAB_POP2(n) n, n + 1, n + 1, n + 2
175#define FL_POLYAB_POP4(n) FL_POLYAB_POP2(n), FL_POLYAB_POP2(n + 1), \
176 FL_POLYAB_POP2(n + 1), FL_POLYAB_POP2(n + 2)
177#define FL_POLYAB_POP6(n) FL_POLYAB_POP4(n), FL_POLYAB_POP4(n + 1), \
178 FL_POLYAB_POP4(n + 1), FL_POLYAB_POP4(n + 2)
194#elif defined(__GNUC__) || defined(__clang__)
195 return (
fl::u8)__builtin_popcount((
unsigned)v);
197 v = v - ((v >> 1) & 0x55u);
198 v = (v & 0x33u) + ((v >> 2) & 0x33u);
199 return (
fl::u8)((v + (v >> 4)) & 0x0Fu);
215 return (p >= 32u) ? 255u : br;
250template<
typename PixelT>
252 int x0,
int x1,
const PixelT&
color,
254 if (x1 <= x0)
return;
256 if (br < 255u) c.nscale8(br);
257 PixelT* row = pixels + py *
width + x0;
259 for (
int i = 0; i < x1 - x0; ++i) row[i] = c;
261 for (
int i = 0; i < x1 - x0; ++i) row[i] += c;
274template<
typename PixelT,
typename Coord,
bool Overwrite,
int MAXN>
277 FL_STATIC_ASSERT(MAXN >= 3 && MAXN <= 256,
"drawPolygon: MAXN must be in [3, 256]");
278 const fl::i32 n =
static_cast<fl::i32
>(pts.size());
280 PixelT* pixels =
canvas.pixels;
285 const int nv = (n < MAXN) ? n : MAXN;
290 for (
int i = 0; i < nv; ++i) {
299 int ymin =
height, ymax = -1;
300 for (
int i = 0; i < nv; ++i) {
301 const int j = (i + 1 == nv) ? 0 : (i + 1);
302 const fl::i32 dy = vy[j] - vy[i];
303 if (dy == 0)
continue;
305 fl::i32 ytop_q, xtop,
B;
306 if (dy > 0) { ytop_q = vy[i]; xtop = vx[i];
B = vx[j] - vx[i]; }
307 else { ytop_q = vy[j]; xtop = vx[j];
B = vx[i] - vx[j]; }
308 const fl::i32 dy2 = (dy > 0) ? dy : -dy;
309 const fl::i32 ybot_q = ytop_q + dy2;
313 int py0 = ytop_q >> 16;
314 int py1 = (ybot_q - 1) >> 16;
315 if (py0 < 0) py0 = 0;
317 if (py0 > py1)
continue;
319 AbEdge& e = edges[nedges++];
330 e.
ytop = (ytop_q + 16383) >> 14;
331 e.
ybot = (ybot_q + 16383) >> 14;
350 const fl::i32 m = (fl::i32)(e.
xinc & 3);
351 const fl::i64 n0 = ((off & 65535L) * (e.
xinc & 65535L)) & 65535L;
357 if (e.
py0 < ymin) ymin = e.
py0;
358 if (e.
py1 > ymax) ymax = e.
py1;
360 if (nedges == 0)
return;
365 fl::i32 cp[4 * MAXN];
367 for (
int py = ymin; py <= ymax; ++py) {
371 for (
int e = 0; e < nedges; ++e) {
373 if (py < ed.py0 || py > ed.
py1)
continue;
379 const fl::i32 sub = (fl::i32)4 * py;
380 fl::i32 rlo32 = ed.
ytop - sub;
382 if (rlo32 < 0) rlo32 = 0;
383 fl::i32 rhi32 = ed.
ybot - 1 - sub;
384 if (rhi32 < 0) rhi32 = 0;
385 if (rhi32 > 3) rhi32 = 3;
386 if (rlo32 > rhi32)
continue;
387 const int rlo = (int)rlo32, rhi = (
int)rhi32;
391 for (
int r = 0; r <= rhi; ++r) {
393 if (r < rlo)
continue;
397 mask ^= (fl::u32)0xFFu << (8 * r);
399 const fl::i32 p = (fl::i32)(X >> 16);
401 const fl::u32 bo = (fl::u32)((X - ((
fl::i64)p << 16)) >> 13);
402 cp[ncp] = (p << 5) | (r << 3) | (fl::i32)bo;
418 for (
int a = 1; a < ncp; ++a) {
419 const fl::i32 v = cp[a];
421 while (b >= 0 && cp[b] > v) { cp[b + 1] = cp[b]; --b; }
429 for (
int k = 0; k < ncp; ) {
430 const int p = cp[k] >> 5;
440 while (k < ncp && (cp[k] >> 5) == p) {
441 rowxor ^= (fl::u32)((1u << (8 - (cp[k] & 7u))) - 1u)
442 << (8 * ((cp[k] >> 3) & 3u));
449 if (br < 255u) c.nscale8(br);
450 PixelT& px = pixels[py *
width + p];
451 if (Overwrite) px = c;
else px += c;
457 mask = (mask & 0x01010101u) * 255u;
460 if (
x <
width && mask != 0)
fl::CanvasRGB canvas(fl::span< CRGB >(leds, NUM_LEDS), WIDTH, HEIGHT)
Canvas types for gfx primitives (implementation)
#define FL_PGM_READ_BYTE_NEAR(x)
Read a byte (8-bit) from PROGMEM memory.
#define FL_PROGMEM
PROGMEM keyword for storage.
Wrapper definitions to allow seamless use of PROGMEM in environments that have it.
fl::u8 polyABAlpha(fl::u32 mask) FL_NO_EXCEPT
Alpha (0..255) for an 8x4 mask: 8 per subpixel, saturating at 255 (32 subpixels would otherwise wrap ...
void drawPolygonABufferCore(Canvas< PixelT > &canvas, const PixelT &color, fl::span< const PolyPoint< Coord > > pts) FL_NO_EXCEPT
A-buffer 8x4 antialiased polygon fill (see file header).
void polyABFillRun(PixelT *pixels, int py, int width, int x0, int x1, const PixelT &color, fl::u8 br, bool overwrite) FL_NO_EXCEPT
Fill a run of [x0, x1) pixels of row py with color at alpha br.
static const fl::i32 polyABQ16Max
Maximum |vertex coordinate| accepted, in Q16.16 units (8191 px keeps all values and edge deltas in i3...
fl::i64 polyABFloorDivI64(fl::i64 a, fl::i64 b) FL_NO_EXCEPT
Floor-divide a by positive b (rounds toward -inf).
fl::i32 polyABToQ16< int >(int val) FL_NO_EXCEPT
fl::u8 polyABPop8(fl::u8 v) FL_NO_EXCEPT
Popcount of a byte.
fl::i32 polyABToQ16< fl::s16x16 >(fl::s16x16 val) FL_NO_EXCEPT
fl::i32 polyABClampPx(float px) FL_NO_EXCEPT
Float -> Q16.16, clamped to ±8191 px.
fl::i32 polyABToQ16(Coord val) FL_NO_EXCEPT
Convert any Coord type to Q16.16, clamped to ±8191 px.
const fl::u8 * polyABPop8Table() FL_NO_EXCEPT
fl::u8 polyABPopcount32(fl::u32 v) FL_NO_EXCEPT
fl::i32 polyABToQ16< double >(double val) FL_NO_EXCEPT
fl::i32 polyABToQ16< float >(float val) FL_NO_EXCEPT
============================================================================
Polygon vertex (x, y coordinate pair) for drawPolygon C++11 aggregate: PolyPoint<float> p{3....
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Base definition for an LED controller.
#define FL_POLYAB_POP6(n)
#define FL_STATIC_ASSERT(...)
Portable compile-time assertion wrapper.
Simple rectangular canvas for graphics operations Combines a pixel buffer with dimensions for cache-o...