FastLED 3.10.8
Loading...
Searching...
No Matches

◆ drawDiscCore()

template<typename PixelT, typename Coord, bool Overwrite>
void fl::gfx::detail::drawDiscCore ( Canvas< PixelT > & canvas,
const PixelT & color,
Coord cx,
Coord cy,
Coord r )
inline

Definition at line 658 of file primitives.h.

659 {
660 PixelT* pixels = canvas.pixels;
661 int width = canvas.width;
662 int height = canvas.height;
663
664 fl::i32 cx8 = detail::toFixed8(cx);
665 fl::i32 cy8 = detail::toFixed8(cy);
666 fl::i32 r8 = detail::toFixed8(r);
667
668 fl::i32 rin8 = r8 - 128; // r - 0.5 in 8.8
669 fl::i32 rout8 = r8 + 128; // r + 0.5 in 8.8
670
671 fl::i32 rin2 = rin8 * rin8;
672 fl::i32 rout2 = rout8 * rout8;
673 fl::i32 band = rout2 - rin2;
674 if (band <= 0) return;
675
676 int ri = (rout8 >> 8) + 1;
677 int cxi = cx8 >> 8;
678 int cyi = cy8 >> 8;
679
680 int xmin = cxi - ri; if (xmin < 0) xmin = 0;
681 int xmax = cxi + ri; if (xmax >= width) xmax = width - 1;
682 if (xmin > xmax) return;
683 if (cyi + ri < 0 || cyi - ri >= height) return;
684
685 fl::i32 dx8 = (static_cast<fl::i32>(xmin) << 8) - cx8;
686 fl::i32 dx2 = dx8 * dx8;
687
689 fc.xdelta0 = 512 * dx8 + 65536;
690 fc.xmin = xmin; fc.xmax = xmax;
691 fc.rin2 = rin2; fc.rout2 = rout2;
693 fc.color = color;
694
695 fl::i32 cyfrac = (static_cast<fl::i32>(cyi) << 8) - cy8;
696 fl::i32 d2c = dx2 + cyfrac * cyfrac;
697
698 if (cyi >= 0 && cyi < height)
699 detail::renderDiscRow<PixelT, Overwrite>(pixels, width, cyi, d2c, fc);
700
701 fl::i32 botd2 = d2c, botdelta = 512 * cyfrac + 65536;
702 fl::i32 topd2 = d2c, topdelta = -512 * cyfrac + 65536;
703 botd2 += botdelta; botdelta += 131072;
704 topd2 += topdelta; topdelta += 131072;
705
706 for (int dy = 1; dy <= ri; ++dy) {
707 bool cbot = (botd2 - dx2 <= rout2);
708 bool ctop = (topd2 - dx2 <= rout2);
709 if (!cbot && !ctop) break;
710 int pyb = cyi + dy, pyt = cyi - dy;
711 if (cbot && pyb >= 0 && pyb < height)
712 detail::renderDiscRow<PixelT, Overwrite>(pixels, width, pyb, botd2, fc);
713 if (ctop && pyt >= 0 && pyt < height)
714 detail::renderDiscRow<PixelT, Overwrite>(pixels, width, pyt, topd2, fc);
715 botd2 += botdelta; botdelta += 131072;
716 topd2 += topdelta; topdelta += 131072;
717 }
718}
void renderDiscRow(PixelT *buf, int w, int py, fl::i32 d2_row, const DiscCtx< PixelT > &f) FL_NO_EXCEPT
Render one scanline of a disc using incremental d².
Definition primitives.h:280
fl::i32 toFixed8(Coord val) FL_NO_EXCEPT
Convert any Coord type to 8.8 fixed-point (fl::i32).
Definition primitives.h:182
void computeBandShift(fl::i32 band, fl::u8 &shift_out, fl::u16 &inv_out) FL_NO_EXCEPT
Precompute right-shift and reciprocal multiplier for AA division.
Definition primitives.h:211
Disc context: bundles per-circle constants into a struct passed by reference.
Definition primitives.h:254
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
RGB_T * pixels
Definition canvas.h:72

References fl::gfx::detail::DiscCtx< PixelT >::band_inv, fl::gfx::detail::DiscCtx< PixelT >::band_shift, fl::gfx::detail::DiscCtx< PixelT >::color, computeBandShift(), fl::FL_NO_EXCEPT, fl::height, renderDiscRow(), fl::gfx::detail::DiscCtx< PixelT >::rin2, fl::gfx::detail::DiscCtx< PixelT >::rout2, toFixed8(), fl::width, fl::gfx::detail::DiscCtx< PixelT >::xdelta0, fl::gfx::detail::DiscCtx< PixelT >::xmax, and fl::gfx::detail::DiscCtx< PixelT >::xmin.

Referenced by fl::gfx::drawDisc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: