FastLED 3.9.15
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 568 of file flowfield.cpp.hpp.

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

References fl::s16x16::ceil(), fl::s16x16::clamp(), 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: