FastLED 3.10.10
Loading...
Searching...
No Matches

◆ drawRingCore()

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

Definition at line 1114 of file primitives.h.

1115 {
1116 PixelT* pixels = canvas.pixels;
1117 int width = canvas.width;
1118 int height = canvas.height;
1119
1120 fl::i32 cx8 = detail::toFixed8(cx);
1121 fl::i32 cy8 = detail::toFixed8(cy);
1122 fl::i32 r8 = detail::toFixed8(r);
1123 fl::i32 t8 = detail::toFixed8(thickness);
1124
1125 fl::i32 r_ii8 = r8 - 128;
1126 fl::i32 r_io8 = r8 + 128;
1127 fl::i32 r_oi8 = r8 + t8 - 128;
1128 fl::i32 r_oo8 = r8 + t8 + 128;
1129
1130 if (r_ii8 < 0) r_ii8 = 0;
1131 if (r_io8 < 0) r_io8 = 0;
1132
1133 fl::i32 ii2 = r_ii8 * r_ii8;
1134 fl::i32 io2 = r_io8 * r_io8;
1135 fl::i32 oi2 = r_oi8 * r_oi8;
1136 fl::i32 oo2 = r_oo8 * r_oo8;
1137
1138 fl::i32 inner_band = io2 - ii2;
1139 fl::i32 outer_band = oo2 - oi2;
1140
1141 int ri = (r_oo8 >> 8) + 1;
1142 int cxi = cx8 >> 8;
1143 int cyi = cy8 >> 8;
1144
1145 int xmin = cxi - ri; if (xmin < 0) xmin = 0;
1146 int xmax = cxi + ri; if (xmax >= width) xmax = width - 1;
1147 if (xmin > xmax) return;
1148 if (cyi + ri < 0 || cyi - ri >= height) return;
1149
1150 fl::i32 dx8 = (static_cast<fl::i32>(xmin) << 8) - cx8;
1151 fl::i32 dx2 = dx8 * dx8;
1152
1154 gc.xdelta0 = 512 * dx8 + 65536;
1155 gc.xmin = xmin; gc.xmax = xmax;
1156 gc.ii2 = ii2; gc.io2 = io2; gc.oi2 = oi2; gc.oo2 = oo2;
1157 if (inner_band > 0) detail::computeBandShift(inner_band, gc.inner_shift, gc.inner_inv);
1158 else { gc.inner_shift = 0; gc.inner_inv = 65280u; }
1159 if (outer_band > 0) detail::computeBandShift(outer_band, gc.outer_shift, gc.outer_inv);
1160 else { gc.outer_shift = 0; gc.outer_inv = 65280u; }
1161 gc.color = color;
1162
1163 fl::i32 cyfrac = (static_cast<fl::i32>(cyi) << 8) - cy8;
1164 fl::i32 d2c = dx2 + cyfrac * cyfrac;
1165
1166 if (cyi >= 0 && cyi < height)
1167 detail::renderRingRow<PixelT, Overwrite>(pixels, width, cyi, d2c, gc);
1168
1169 fl::i32 botd2 = d2c, botdelta = 512 * cyfrac + 65536;
1170 fl::i32 topd2 = d2c, topdelta = -512 * cyfrac + 65536;
1171 botd2 += botdelta; botdelta += 131072;
1172 topd2 += topdelta; topdelta += 131072;
1173
1174 for (int dy = 1; dy <= ri; ++dy) {
1175 bool cbot = (botd2 - dx2 <= oo2);
1176 bool ctop = (topd2 - dx2 <= oo2);
1177 if (!cbot && !ctop) break;
1178 int pyb = cyi + dy, pyt = cyi - dy;
1179 if (cbot && pyb >= 0 && pyb < height)
1180 detail::renderRingRow<PixelT, Overwrite>(pixels, width, pyb, botd2, gc);
1181 if (ctop && pyt >= 0 && pyt < height)
1182 detail::renderRingRow<PixelT, Overwrite>(pixels, width, pyt, topd2, gc);
1183 botd2 += botdelta; botdelta += 131072;
1184 topd2 += topdelta; topdelta += 131072;
1185 }
1186}
fl::CanvasRGB canvas(fl::span< CRGB >(leds, NUM_LEDS), WIDTH, HEIGHT)
void renderRingRow(PixelT *buf, int w, int py, fl::i32 d2_row, const RingCtx< PixelT > &g) FL_NO_EXCEPT
Render one scanline of a ring using incremental d² with phase-based scanning.
Definition primitives.h:685
fl::i32 toFixed8(Coord val) FL_NO_EXCEPT
Convert any Coord type to 8.8 fixed-point (fl::i32).
Definition primitives.h:187
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:216
Ring context: bundles all per-circle constants into a struct passed by reference.
Definition primitives.h:633
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186

References canvas, fl::gfx::detail::RingCtx< PixelT >::color, computeBandShift(), fl::FL_NO_EXCEPT, fl::height, fl::gfx::detail::RingCtx< PixelT >::ii2, fl::gfx::detail::RingCtx< PixelT >::inner_inv, fl::gfx::detail::RingCtx< PixelT >::inner_shift, fl::gfx::detail::RingCtx< PixelT >::io2, fl::gfx::detail::RingCtx< PixelT >::oi2, fl::gfx::detail::RingCtx< PixelT >::oo2, fl::gfx::detail::RingCtx< PixelT >::outer_inv, fl::gfx::detail::RingCtx< PixelT >::outer_shift, renderRingRow(), toFixed8(), fl::width, fl::gfx::detail::RingCtx< PixelT >::xdelta0, fl::gfx::detail::RingCtx< PixelT >::xmax, and fl::gfx::detail::RingCtx< PixelT >::xmin.

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

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