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

◆ renderStrokeRow()

template<typename PixelT, bool Overwrite>
void fl::gfx::detail::renderStrokeRow ( PixelT * buf,
int w,
int py,
fl::i32 cross_start,
fl::i32 dot_start,
const StrokeCtx< PixelT > & sc )
inline

Render one scanline of a stroke line using phase-based scanning.

Templated on Overwrite for compile-time dispatch (no per-pixel branch). AA uses precomputed shift+reciprocal — zero Coord multiplies.

Definition at line 769 of file primitives.h.

771 {
772 PixelT* ptr = &buf[py * w + sc.xmin];
773 fl::i32 cross = cross_start;
774 fl::i32 dot = dot_start;
775 int px = sc.xmin;
776 const fl::i32 thr = sc.threshold_q;
777 const fl::i32 neg_thr = -thr;
778
779 // Phase 1: Skip pixels outside the band
780 while (px <= sc.xmax && (cross >= thr || cross < neg_thr)) {
781 cross += sc.dy_q;
782 dot += sc.dx_q;
783 ++ptr; ++px;
784 }
785
786 // Hoist per-row endcap ey values (py is constant within a row)
787 fl::i32 py8 = static_cast<fl::i32>(py) << 8;
788 fl::i32 ey8_y0 = py8 - sc.y0_8;
789 fl::i32 ey8_y1 = py8 - sc.y1_8;
790
791 // Phase 2: Process visible pixels (|cross| < threshold)
792 while (px <= sc.xmax && cross < thr && cross >= neg_thr) {
793 fl::i32 abs_cross = (cross < 0) ? -cross : cross;
794 bool on_segment = (dot >= 0 && dot <= sc.len2_q);
795
796 if (on_segment) {
797 // Integer AA: shift+multiply (no Coord multiply)
798 fl::u16 shifted = static_cast<fl::u16>(
799 static_cast<fl::u32>(abs_cross) >> sc.aa_shift);
800 fl::u8 linear_idx = static_cast<fl::u8>((shifted * sc.aa_inv) >> 8);
801 // Fast approximate x/255 ≈ (x + 1 + (x >> 8)) >> 8
802 fl::u16 sq = static_cast<fl::u16>(linear_idx) * linear_idx;
803 fl::u8 sq_idx = static_cast<fl::u8>((sq + 1 + (sq >> 8)) >> 8);
804 PixelT c = sc.color;
805 c.nscale8(FL_PGM_READ_BYTE_NEAR(&distanceAA_LUT[sq_idx]));
806 if (Overwrite) *ptr = c; else *ptr += c;
807 } else if (sc.cap == LineCap::ROUND) {
808 // Endpoint distance in 8.8 fixed-point
809 fl::i32 ex8;
810 fl::i16 ey_s;
811 if (dot < 0) {
812 ex8 = (static_cast<fl::i32>(px) << 8) - sc.x0_8;
813 ey_s = static_cast<fl::i16>(ey8_y0);
814 } else {
815 ex8 = (static_cast<fl::i32>(px) << 8) - sc.x1_8;
816 ey_s = static_cast<fl::i16>(ey8_y1);
817 }
818 fl::i16 ex_s = static_cast<fl::i16>(ex8);
819 // 16×16→32 multiply (4 MUL on AVR vs ~70 for 32×32)
820 fl::i32 ed2 = static_cast<fl::i32>(ex_s) * ex_s +
821 static_cast<fl::i32>(ey_s) * ey_s;
822 if (ed2 < sc.r_max2_8) {
823 fl::u16 shifted = static_cast<fl::u16>(
824 static_cast<fl::u32>(ed2) >> sc.cap_shift);
825 fl::u8 idx = static_cast<fl::u8>((shifted * sc.cap_inv) >> 8);
826 PixelT c = sc.color;
827 c.nscale8(FL_PGM_READ_BYTE_NEAR(&distanceAA_LUT[idx]));
828 if (Overwrite) *ptr = c; else *ptr += c;
829 }
830 } else if (sc.cap == LineCap::SQUARE) {
831 if (dot >= -sc.dot_ext_q && dot <= sc.len2_q + sc.dot_ext_q) {
832 fl::u16 shifted = static_cast<fl::u16>(
833 static_cast<fl::u32>(abs_cross) >> sc.aa_shift);
834 fl::u8 linear_idx = static_cast<fl::u8>((shifted * sc.aa_inv) >> 8);
835 fl::u16 sq = static_cast<fl::u16>(linear_idx) * linear_idx;
836 fl::u8 sq_idx = static_cast<fl::u8>((sq + 1 + (sq >> 8)) >> 8);
837 PixelT c = sc.color;
838 c.nscale8(FL_PGM_READ_BYTE_NEAR(&distanceAA_LUT[sq_idx]));
839 if (Overwrite) *ptr = c; else *ptr += c;
840 }
841 }
842 // FLAT: pixels outside [0, len2] are silently dropped
843
844 cross += sc.dy_q;
845 dot += sc.dx_q;
846 ++ptr; ++px;
847 }
848 // Phase 3: remaining pixels are outside the band — nothing to do
849}
#define FL_PGM_READ_BYTE_NEAR(x)
Read a byte (8-bit) from PROGMEM memory.
unsigned char u8
Definition s16x16x4.h:132
const fl::u8 distanceAA_LUT[256]
Distance antialiasing lookup table Maps normalized squared distance d²/r_max² (scaled 0....

References distanceAA_LUT, fl::FL_NO_EXCEPT, FL_PGM_READ_BYTE_NEAR, and renderStrokeRow().

Referenced by drawStrokeLineCore(), and renderStrokeRow().

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