FastLED 3.9.15
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 656 of file primitives.h.

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