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

◆ drawDot()

void fl::FlowFieldFP::drawDot ( s16x16 cx,
s16x16 cy,
s16x16 diam,
u8 cr,
u8 cg,
u8 cb )
private

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

570 {
571 int w = mState.width;
572 int h = mState.height;
573 constexpr s16x16 half(0.5f);
574 constexpr s16x16 one(1.0f);
575 s16x16 rad = diam * half;
576
577 int x0 = fl::max(0, s16x16::floor(cx - rad - one).to_int());
578 int x1 = fl::min(w - 1, s16x16::ceil(cx + rad + one).to_int());
579 int y0 = fl::max(0, s16x16::floor(cy - rad - one).to_int());
580 int y1 = fl::min(h - 1, s16x16::ceil(cy + rad + one).to_int());
581
582 s16x16 rad_plus_half = rad + half;
583 // Hoist loop-invariant computations
584 i32 threshold_sq_raw = (rad_plus_half * rad_plus_half).raw();
585 i32 cr_raw = static_cast<i32>(cr) << 16;
586 i32 cg_raw = static_cast<i32>(cg) << 16;
587 i32 cb_raw = static_cast<i32>(cb) << 16;
588 i32 *__restrict__ rp = mState.r.data();
589 i32 *__restrict__ gp = mState.g.data();
590 i32 *__restrict__ bp = mState.b.data();
591
592 for (int y = y0; y <= y1; y++) {
593 s16x16 dy = s16x16(y) + half - cy;
594 i32 dy_sq_raw = (dy * dy).raw();
595 // Early-out: if dy^2 alone exceeds threshold, skip entire row
596 if (dy_sq_raw >= threshold_sq_raw) continue;
597 int row_base = y * w;
598 for (int x = x0; x <= x1; x++) {
599 s16x16 dx = s16x16(x) + half - cx;
600 i32 dist_sq_raw = dy_sq_raw + (dx * dx).raw();
601 if (dist_sq_raw >= threshold_sq_raw)
602 continue;
603 s16x16 dist = s16x16::sqrt(s16x16::from_raw(dist_sq_raw));
604 s16x16 cov = s16x16::clamp(rad_plus_half - dist, s16x16(), one);
605 if (cov.raw() <= 0) continue;
606 int i = row_base + x;
607 // Lerp: old + (new - old) * cov — 1 i64 mul per channel instead of 2
608 i32 cov_q16 = cov.raw();
609 rp[i] += static_cast<i32>((static_cast<i64>(cr_raw - rp[i]) * cov_q16) >> 16);
610 gp[i] += static_cast<i32>((static_cast<i64>(cg_raw - gp[i]) * cov_q16) >> 16);
611 bp[i] += static_cast<i32>((static_cast<i64>(cb_raw - bp[i]) * cov_q16) >> 16);
612 }
613 }
614}
FlowFieldFPState mState
Definition flowfield.h:400
constexpr FASTLED_FORCE_INLINE s16x16 ceil() const FL_NO_EXCEPT
Definition s16x16.h:299
constexpr FASTLED_FORCE_INLINE s16x16 floor() const FL_NO_EXCEPT
Definition s16x16.h:295
static constexpr FASTLED_FORCE_INLINE s16x16 clamp(s16x16 x, s16x16 lo, s16x16 hi) FL_NO_EXCEPT
Definition s16x16.h:188
static constexpr FASTLED_FORCE_INLINE s16x16 from_raw(i32 raw) FL_NO_EXCEPT
Definition s16x16.h:56
constexpr FASTLED_FORCE_INLINE s16x16 sqrt() const FL_NO_EXCEPT
Definition s16x16.h:335
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71
fl::i64 i64
Definition stdint.h:221

References fl::s16x16::ceil(), fl::s16x16::clamp(), fl::FL_NO_EXCEPT, fl::s16x16::floor(), fl::s16x16::from_raw(), fl::max(), fl::min(), mState, fl::s16x16::raw(), fl::s16x16::sqrt(), fl::x, and fl::y.

Referenced by emitLissajousLine(), and emitOrbitalDots().

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