FastLED 3.10.8
Loading...
Searching...
No Matches

◆ drawAALine()

void fl::FlowFieldFP::drawAALine ( s16x16 x0,
s16x16 y0,
s16x16 x1,
s16x16 y1,
s16x16 t,
s16x16 colorShift )
private

Definition at line 616 of file flowfield.cpp.hpp.

617 {
618 int w = mState.width;
619 int h = mState.height;
620 s16x16 dx = x1 - x0;
621 s16x16 dy = y1 - y0;
622 s16x16 max_delta = fl::max(s16x16::abs(dx), s16x16::abs(dy));
623 int steps = fl::max(1, (max_delta * s16x16(3)).to_int());
624 s16x16 invSteps = s16x16(1) / s16x16(steps);
625
626 i32 *__restrict__ rp = mState.r.data();
627 i32 *__restrict__ gp = mState.g.data();
628 i32 *__restrict__ bp = mState.b.data();
629
630 // Precompute step increments (was recomputing from scratch each iteration)
631 s16x16 dx_step = dx * invSteps;
632 s16x16 dy_step = dy * invSteps;
633 s16x16 u = s16x16();
634 s16x16 px = x0;
635 s16x16 py = y0;
636
637 for (int i = 0; i <= steps; i++, u = u + invSteps, px = px + dx_step, py = py + dy_step) {
638 CRGB c = rainbow(t, colorShift, u);
639
640 int ix = s16x16::floor(px).to_int();
641 int iy = s16x16::floor(py).to_int();
642 s16x16 fx = s16x16::fract(px);
643 s16x16 fy = s16x16::fract(py);
644 constexpr s16x16 one(1.0f);
645 s16x16 inv_fx = one - fx;
646 s16x16 inv_fy = one - fy;
647
648 i32 weights[4] = {
649 (inv_fx * inv_fy).raw(),
650 (fx * inv_fy).raw(),
651 (inv_fx * fy).raw(),
652 (fx * fy).raw(),
653 };
654
655 // Pre-shift color values once per step
656 i32 cr_raw = static_cast<i32>(c.r) << 16;
657 i32 cg_raw = static_cast<i32>(c.g) << 16;
658 i32 cb_raw = static_cast<i32>(c.b) << 16;
659
660 int offX[4] = {0, 1, 0, 1};
661 int offY[4] = {0, 0, 1, 1};
662
663 for (int j = 0; j < 4; j++) {
664 int cx = ix + offX[j];
665 int cy = iy + offY[j];
666 if (cx < 0 || cx >= w || cy < 0 || cy >= h)
667 continue;
668 i32 wt_q16 = weights[j];
669 if (wt_q16 <= 0) continue;
670 int gi = cy * w + cx;
671 // Lerp: old + (new - old) * wt — 1 i64 mul per channel instead of 2
672 rp[gi] += static_cast<i32>((static_cast<i64>(cr_raw - rp[gi]) * wt_q16) >> 16);
673 gp[gi] += static_cast<i32>((static_cast<i64>(cg_raw - gp[gi]) * wt_q16) >> 16);
674 bp[gi] += static_cast<i32>((static_cast<i64>(cb_raw - bp[gi]) * wt_q16) >> 16);
675 }
676 }
677}
void rainbow()
fl::UISlider colorShift("Color Shift", 0.04f, 0.0f, 0.5f, 0.01f)
FlowFieldFPState mState
Definition flowfield.h:400
constexpr FASTLED_FORCE_INLINE s16x16 fract() const FL_NO_EXCEPT
Definition s16x16.h:303
constexpr FASTLED_FORCE_INLINE s16x16 floor() const FL_NO_EXCEPT
Definition s16x16.h:295
constexpr FASTLED_FORCE_INLINE s16x16 abs() const FL_NO_EXCEPT
Definition s16x16.h:307
constexpr i32 to_int() const FL_NO_EXCEPT
Definition s16x16.h:63
fl::UISlider steps("Steps", 100.0f, 1.0f, 200.0f, 1.0f)
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
fl::CRGB CRGB
Definition video.h:18
fl::i64 i64
Definition stdint.h:221

References fl::s16x16::abs(), colorShift, fl::FL_NO_EXCEPT, fl::s16x16::floor(), fl::s16x16::fract(), fl::max(), mState, rainbow(), steps(), fl::t, and fl::s16x16::to_int().

Referenced by emitLissajousLine().

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