MCPcopy Create free account
hub / github.com/FastLED/FastLED / drawRingCore

Method drawRingCore

src/fl/gfx/primitives.h:732–804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

730// ---------------------------------------------------------------------------
731template<typename PixelT, typename Coord, bool Overwrite>
732inline void detail::drawRingCore(Canvas<PixelT>& canvas, const PixelT& color,
733 Coord cx, Coord cy, Coord r, Coord thickness) {
734 PixelT* pixels = canvas.pixels;
735 int width = canvas.width;
736 int height = canvas.height;
737
738 fl::i32 cx8 = detail::toFixed8(cx);
739 fl::i32 cy8 = detail::toFixed8(cy);
740 fl::i32 r8 = detail::toFixed8(r);
741 fl::i32 t8 = detail::toFixed8(thickness);
742
743 fl::i32 r_ii8 = r8 - 128;
744 fl::i32 r_io8 = r8 + 128;
745 fl::i32 r_oi8 = r8 + t8 - 128;
746 fl::i32 r_oo8 = r8 + t8 + 128;
747
748 if (r_ii8 < 0) r_ii8 = 0;
749 if (r_io8 < 0) r_io8 = 0;
750
751 fl::i32 ii2 = r_ii8 * r_ii8;
752 fl::i32 io2 = r_io8 * r_io8;
753 fl::i32 oi2 = r_oi8 * r_oi8;
754 fl::i32 oo2 = r_oo8 * r_oo8;
755
756 fl::i32 inner_band = io2 - ii2;
757 fl::i32 outer_band = oo2 - oi2;
758
759 int ri = (r_oo8 >> 8) + 1;
760 int cxi = cx8 >> 8;
761 int cyi = cy8 >> 8;
762
763 int xmin = cxi - ri; if (xmin < 0) xmin = 0;
764 int xmax = cxi + ri; if (xmax >= width) xmax = width - 1;
765 if (xmin > xmax) return;
766 if (cyi + ri < 0 || cyi - ri >= height) return;
767
768 fl::i32 dx8 = (static_cast<fl::i32>(xmin) << 8) - cx8;
769 fl::i32 dx2 = dx8 * dx8;
770
771 detail::RingCtx<PixelT> gc;
772 gc.xdelta0 = 512 * dx8 + 65536;
773 gc.xmin = xmin; gc.xmax = xmax;
774 gc.ii2 = ii2; gc.io2 = io2; gc.oi2 = oi2; gc.oo2 = oo2;
775 if (inner_band > 0) detail::computeBandShift(inner_band, gc.inner_shift, gc.inner_inv);
776 else { gc.inner_shift = 0; gc.inner_inv = 65280u; }
777 if (outer_band > 0) detail::computeBandShift(outer_band, gc.outer_shift, gc.outer_inv);
778 else { gc.outer_shift = 0; gc.outer_inv = 65280u; }
779 gc.color = color;
780
781 fl::i32 cyfrac = (static_cast<fl::i32>(cyi) << 8) - cy8;
782 fl::i32 d2c = dx2 + cyfrac * cyfrac;
783
784 if (cyi >= 0 && cyi < height)
785 detail::renderRingRow<PixelT, Overwrite>(pixels, width, cyi, d2c, gc);
786
787 fl::i32 botd2 = d2c, botdelta = 512 * cyfrac + 65536;
788 fl::i32 topd2 = d2c, topdelta = -512 * cyfrac + 65536;
789 botd2 += botdelta; botdelta += 131072;

Callers

nothing calls this directly

Calls 2

toFixed8Function · 0.85
computeBandShiftFunction · 0.85

Tested by

no test coverage detected