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

Method interp8

src/fl/math/lut.h:59–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 u32 size() const FL_NOEXCEPT { return length; }
58
59 T interp8(u8 alpha) FL_NOEXCEPT {
60 if (length == 0)
61 return T();
62 if (alpha == 0)
63 return data[0];
64 if (alpha == 255)
65 return data[length - 1];
66
67 // treat alpha/255 as fraction, scale to [0..length-1]
68 u32 maxIndex = length - 1;
69 u32 pos = u32(alpha) * maxIndex; // numerator
70 u32 idx0 = pos / 255; // floor(position)
71 u32 idx1 = idx0 < maxIndex ? idx0 + 1 : maxIndex;
72 u8 blend = pos % 255; // fractional part
73
74 const T &a = data[idx0];
75 const T &b = data[idx1];
76 // a + (b-a) * blend/255
77 return a + (b - a) * blend / 255;
78 }
79
80 T interp16(u16 alpha) FL_NOEXCEPT {
81 if (length == 0)

Callers 1

FL_TEST_FILEFunction · 0.80

Calls 2

TEnum · 0.85
u32Enum · 0.50

Tested by

no test coverage detected