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

822 {
823 PixelT* pixels = canvas.pixels;
824 int width = canvas.width;
825 int height = canvas.height;
826
827 fl::i32 x0_8 = detail::toFixed8(x0), y0_8 = detail::toFixed8(y0);
828 fl::i32 x1_8 = detail::toFixed8(x1), y1_8 = detail::toFixed8(y1);
829 fl::i32 dx_8 = x1_8 - x0_8;
830 fl::i32 dy_8 = y1_8 - y0_8;
831 if (dx_8 == 0 && dy_8 == 0) return;
832
833 fl::i32 len2_16 = dx_8 * dx_8 + dy_8 * dy_8;
834 fl::i32 len_8 = static_cast<fl::i32>(
835 fl::isqrt32(static_cast<fl::u32>(len2_16)));
836 fl::i32 thickness_8 = detail::toFixed8(thickness);
837 fl::i32 r_max_8 = thickness_8 >> 1;
838 fl::i32 threshold_q = r_max_8 * len_8;
839
840 if (threshold_q <= 0) return;
841
842 int x0i = x0_8 >> 8, y0i = y0_8 >> 8;
843 int x1i = x1_8 >> 8, y1i = y1_8 >> 8;
844 int margin = ((r_max_8 + 255) >> 8) + 2;
845 int xmin = (x0i < x1i ? x0i : x1i) - margin;
846 int xmax = (x0i > x1i ? x0i : x1i) + margin;
847 int ymin = (y0i < y1i ? y0i : y1i) - margin;
848 int ymax = (y0i > y1i ? y0i : y1i) + margin;
849
850 if (xmin < 0) xmin = 0;
851 if (xmax >= width) xmax = width - 1;
852 if (ymin < 0) ymin = 0;
853 if (ymax >= height) ymax = height - 1;
854 if (xmin > xmax || ymin > ymax) return;
855
856 fl::i32 dx_q = dx_8 << 8;
857 fl::i32 dy_q = dy_8 << 8;
858
859 fl::i32 rx_base_8 = (static_cast<fl::i32>(xmin) << 8) - x0_8;
860 fl::i32 ry_row_8 = (static_cast<fl::i32>(ymin) << 8) - y0_8;
861 fl::i32 cross_row_q = rx_base_8 * dy_8 - ry_row_8 * dx_8;
862 fl::i32 dot_row_q = rx_base_8 * dx_8 + ry_row_8 * dy_8;
863
864 fl::i32 len2_q = len_8 * len_8;
865 fl::i32 dot_ext_q = (cap == LineCap::SQUARE) ? threshold_q : 0;
866
868 sc.threshold_q = threshold_q;
869 sc.len2_q = len2_q;
870 sc.dx_q = dx_q;
871 sc.dy_q = dy_q;
872 sc.dot_ext_q = dot_ext_q;
873 detail::computeBandShift(threshold_q, sc.aa_shift, sc.aa_inv);
874 sc.x0_8 = x0_8; sc.y0_8 = y0_8;
875 sc.x1_8 = x1_8; sc.y1_8 = y1_8;
876 sc.r_max2_8 = r_max_8 * r_max_8;
877 sc.cap_shift = 0; sc.cap_inv = 0;
878 if (cap == LineCap::ROUND && sc.r_max2_8 > 0) {
880 }
881 sc.cap = cap;
882 sc.color = color;
883 sc.xmin = xmin; sc.xmax = xmax;
884
885 for (int py = ymin; py <= ymax; ++py) {
886 if (py >= 0 && py < height) {
888 cross_row_q, dot_row_q, sc);
889 }
890 cross_row_q -= sc.dx_q;
891 dot_row_q += sc.dy_q;
892 }
893}
void renderStrokeRow(PixelT *buf, int w, int py, fl::i32 cross_start, fl::i32 dot_start, const StrokeCtx< PixelT > &sc)
Render one scanline of a stroke line using phase-based scanning.
Definition primitives.h:401
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
Stroke line context: bundles per-line constants into a struct passed by reference.
Definition primitives.h:381
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
FL_OPTIMIZE_FUNCTION constexpr u16 isqrt32(u32 x) FL_NOEXCEPT
Definition isqrt.h:53
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::gfx::Canvas< RGB_T >::height, fl::height, fl::isqrt32(), fl::gfx::detail::StrokeCtx< PixelT >::len2_q, fl::gfx::Canvas< RGB_T >::pixels, fl::gfx::detail::StrokeCtx< PixelT >::r_max2_8, renderStrokeRow(), fl::gfx::detail::StrokeCtx< PixelT >::threshold_q, toFixed8(), fl::gfx::Canvas< RGB_T >::width, 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: