FastLED 3.10.8
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 822 of file primitives.h.

824 {
825 PixelT* pixels = canvas.pixels;
826 int width = canvas.width;
827 int height = canvas.height;
828
829 fl::i32 x0_8 = detail::toFixed8(x0), y0_8 = detail::toFixed8(y0);
830 fl::i32 x1_8 = detail::toFixed8(x1), y1_8 = detail::toFixed8(y1);
831 fl::i32 dx_8 = x1_8 - x0_8;
832 fl::i32 dy_8 = y1_8 - y0_8;
833 if (dx_8 == 0 && dy_8 == 0) return;
834
835 fl::i32 len2_16 = dx_8 * dx_8 + dy_8 * dy_8;
836 fl::i32 len_8 = static_cast<fl::i32>(
837 fl::isqrt32(static_cast<fl::u32>(len2_16)));
838 fl::i32 thickness_8 = detail::toFixed8(thickness);
839 fl::i32 r_max_8 = thickness_8 >> 1;
840 fl::i32 threshold_q = r_max_8 * len_8;
841
842 if (threshold_q <= 0) return;
843
844 int x0i = x0_8 >> 8, y0i = y0_8 >> 8;
845 int x1i = x1_8 >> 8, y1i = y1_8 >> 8;
846 int margin = ((r_max_8 + 255) >> 8) + 2;
847 int xmin = (x0i < x1i ? x0i : x1i) - margin;
848 int xmax = (x0i > x1i ? x0i : x1i) + margin;
849 int ymin = (y0i < y1i ? y0i : y1i) - margin;
850 int ymax = (y0i > y1i ? y0i : y1i) + margin;
851
852 if (xmin < 0) xmin = 0;
853 if (xmax >= width) xmax = width - 1;
854 if (ymin < 0) ymin = 0;
855 if (ymax >= height) ymax = height - 1;
856 if (xmin > xmax || ymin > ymax) return;
857
858 fl::i32 dx_q = dx_8 << 8;
859 fl::i32 dy_q = dy_8 << 8;
860
861 fl::i32 rx_base_8 = (static_cast<fl::i32>(xmin) << 8) - x0_8;
862 fl::i32 ry_row_8 = (static_cast<fl::i32>(ymin) << 8) - y0_8;
863 fl::i32 cross_row_q = rx_base_8 * dy_8 - ry_row_8 * dx_8;
864 fl::i32 dot_row_q = rx_base_8 * dx_8 + ry_row_8 * dy_8;
865
866 fl::i32 len2_q = len_8 * len_8;
867 fl::i32 dot_ext_q = (cap == LineCap::SQUARE) ? threshold_q : 0;
868
870 sc.threshold_q = threshold_q;
871 sc.len2_q = len2_q;
872 sc.dx_q = dx_q;
873 sc.dy_q = dy_q;
874 sc.dot_ext_q = dot_ext_q;
875 detail::computeBandShift(threshold_q, sc.aa_shift, sc.aa_inv);
876 sc.x0_8 = x0_8; sc.y0_8 = y0_8;
877 sc.x1_8 = x1_8; sc.y1_8 = y1_8;
878 sc.r_max2_8 = r_max_8 * r_max_8;
879 sc.cap_shift = 0; sc.cap_inv = 0;
880 if (cap == LineCap::ROUND && sc.r_max2_8 > 0) {
882 }
883 sc.cap = cap;
884 sc.color = color;
885 sc.xmin = xmin; sc.xmax = xmax;
886
887 for (int py = ymin; py <= ymax; ++py) {
888 if (py >= 0 && py < height) {
890 cross_row_q, dot_row_q, sc);
891 }
892 cross_row_q -= sc.dx_q;
893 dot_row_q += sc.dy_q;
894 }
895}
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
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:403
Stroke line context: bundles per-line constants into a struct passed by reference.
Definition primitives.h:383
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
RGB_T * pixels
Definition canvas.h:72

References fl::gfx::detail::StrokeCtx< PixelT >::aa_inv, fl::gfx::detail::StrokeCtx< PixelT >::aa_shift, 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: