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

◆ drawStrokeLineCore()

template<typename PixelT, typename Coord, bool Overwrite>
void fl::gfx::detail::drawStrokeLineCore ( Canvas< PixelT > & canvas,
const PixelT & color,
Coord x0,
Coord y0,
Coord x1,
Coord y1,
Coord thickness,
LineCap cap )
inline

Definition at line 1202 of file primitives.h.

1204 {
1205 PixelT* pixels = canvas.pixels;
1206 int width = canvas.width;
1207 int height = canvas.height;
1208
1209 fl::i32 x0_8 = detail::toFixed8(x0), y0_8 = detail::toFixed8(y0);
1210 fl::i32 x1_8 = detail::toFixed8(x1), y1_8 = detail::toFixed8(y1);
1211 fl::i32 dx_8 = x1_8 - x0_8;
1212 fl::i32 dy_8 = y1_8 - y0_8;
1213 if (dx_8 == 0 && dy_8 == 0) return;
1214
1215 fl::i32 len2_16 = dx_8 * dx_8 + dy_8 * dy_8;
1216 fl::i32 len_8 = static_cast<fl::i32>(
1217 fl::isqrt32(static_cast<fl::u32>(len2_16)));
1218 fl::i32 thickness_8 = detail::toFixed8(thickness);
1219 fl::i32 r_max_8 = thickness_8 >> 1;
1220 fl::i32 threshold_q = r_max_8 * len_8;
1221
1222 if (threshold_q <= 0) return;
1223
1224 int x0i = x0_8 >> 8, y0i = y0_8 >> 8;
1225 int x1i = x1_8 >> 8, y1i = y1_8 >> 8;
1226 int margin = ((r_max_8 + 255) >> 8) + 2;
1227 int xmin = (x0i < x1i ? x0i : x1i) - margin;
1228 int xmax = (x0i > x1i ? x0i : x1i) + margin;
1229 int ymin = (y0i < y1i ? y0i : y1i) - margin;
1230 int ymax = (y0i > y1i ? y0i : y1i) + margin;
1231
1232 if (xmin < 0) xmin = 0;
1233 if (xmax >= width) xmax = width - 1;
1234 if (ymin < 0) ymin = 0;
1235 if (ymax >= height) ymax = height - 1;
1236 if (xmin > xmax || ymin > ymax) return;
1237
1238 fl::i32 dx_q = dx_8 << 8;
1239 fl::i32 dy_q = dy_8 << 8;
1240
1241 fl::i32 rx_base_8 = (static_cast<fl::i32>(xmin) << 8) - x0_8;
1242 fl::i32 ry_row_8 = (static_cast<fl::i32>(ymin) << 8) - y0_8;
1243 fl::i32 cross_row_q = rx_base_8 * dy_8 - ry_row_8 * dx_8;
1244 fl::i32 dot_row_q = rx_base_8 * dx_8 + ry_row_8 * dy_8;
1245
1246 fl::i32 len2_q = len_8 * len_8;
1247 fl::i32 dot_ext_q = (cap == LineCap::SQUARE) ? threshold_q : 0;
1248
1250 sc.threshold_q = threshold_q;
1251 sc.len2_q = len2_q;
1252 sc.dx_q = dx_q;
1253 sc.dy_q = dy_q;
1254 sc.dot_ext_q = dot_ext_q;
1255 detail::computeBandShift(threshold_q, sc.aa_shift, sc.aa_inv);
1256 sc.x0_8 = x0_8; sc.y0_8 = y0_8;
1257 sc.x1_8 = x1_8; sc.y1_8 = y1_8;
1258 sc.r_max2_8 = r_max_8 * r_max_8;
1259 sc.cap_shift = 0; sc.cap_inv = 0;
1260 if (cap == LineCap::ROUND && sc.r_max2_8 > 0) {
1262 }
1263 sc.cap = cap;
1264 sc.color = color;
1265 sc.xmin = xmin; sc.xmax = xmax;
1266
1267 for (int py = ymin; py <= ymax; ++py) {
1268 if (py >= 0 && py < height) {
1270 cross_row_q, dot_row_q, sc);
1271 }
1272 cross_row_q -= sc.dx_q;
1273 dot_row_q += sc.dy_q;
1274 }
1275}
fl::CanvasRGB canvas(fl::span< CRGB >(leds, NUM_LEDS), WIDTH, HEIGHT)
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
void renderStrokeRow(PixelT *buf, int w, int py, fl::i32 cross_start, fl::i32 dot_start, const StrokeCtx< PixelT > &sc) FL_NO_EXCEPT
Render one scanline of a stroke line using phase-based scanning.
Definition primitives.h:769
Stroke line context: bundles per-line constants into a struct passed by reference.
Definition primitives.h:749
u8 u8 height
Definition blur.h:186
FL_OPTIMIZE_FUNCTION constexpr u16 isqrt32(u32 x) FL_NO_EXCEPT
Definition isqrt.h:53
u8 width
Definition blur.h:186

References fl::gfx::detail::StrokeCtx< PixelT >::aa_inv, fl::gfx::detail::StrokeCtx< PixelT >::aa_shift, canvas, fl::gfx::detail::StrokeCtx< PixelT >::cap, fl::gfx::detail::StrokeCtx< PixelT >::cap_inv, fl::gfx::detail::StrokeCtx< PixelT >::cap_shift, fl::gfx::detail::StrokeCtx< PixelT >::color, computeBandShift(), fl::gfx::detail::StrokeCtx< PixelT >::dot_ext_q, fl::gfx::detail::StrokeCtx< PixelT >::dx_q, fl::gfx::detail::StrokeCtx< PixelT >::dy_q, fl::FL_NO_EXCEPT, fl::height, fl::isqrt32(), fl::gfx::detail::StrokeCtx< PixelT >::len2_q, fl::gfx::detail::StrokeCtx< PixelT >::r_max2_8, renderStrokeRow(), fl::gfx::detail::StrokeCtx< PixelT >::threshold_q, toFixed8(), fl::width, fl::gfx::detail::StrokeCtx< PixelT >::x0_8, fl::gfx::detail::StrokeCtx< PixelT >::x1_8, fl::gfx::detail::StrokeCtx< PixelT >::xmax, fl::gfx::detail::StrokeCtx< PixelT >::xmin, fl::gfx::detail::StrokeCtx< PixelT >::y0_8, and fl::gfx::detail::StrokeCtx< PixelT >::y1_8.

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

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