MCPcopy Create free account
hub / github.com/FastLED/FastLED / interp16

Method interp16

src/fl/math/lut.h:80–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 }
79
80 T interp16(u16 alpha) FL_NOEXCEPT {
81 if (length == 0)
82 return T();
83 if (alpha == 0)
84 return data[0];
85 if (alpha == 65535)
86 return data[length - 1];
87
88 // treat alpha/65535 as fraction, scale to [0..length-1]
89 u32 maxIndex = length - 1;
90 u32 pos = u32(alpha) * maxIndex; // numerator
91 u32 idx0 = pos / 65535; // floor(position)
92 u32 idx1 = idx0 < maxIndex ? idx0 + 1 : maxIndex;
93 u16 blend = pos % 65535; // fractional part
94
95 const T &a = data[idx0];
96 const T &b = data[idx1];
97 // a + (b-a) * blend/65535
98 return a + (b - a) * blend / 65535;
99 }
100
101 private:
102 fl::unique_ptr<T> mDataHandle;

Callers 1

FL_TEST_FILEFunction · 0.80

Calls 2

TEnum · 0.85
u32Enum · 0.50

Tested by

no test coverage detected