FastLED 3.10.6
Loading...
Searching...
No Matches

◆ inverseResponseQ16()

i32 fl::anonymous_namespace{pipeline.cpp.hpp}::inverseResponseQ16 ( i32 light,
const vector< u16 > & values )

Invert piecewise-linear code-to-light data.

The first sample that reaches the requested light wins at a plateau; zero and full-scale are exact.

Definition at line 31 of file pipeline.cpp.hpp.

31 {
32 if (light <= 0) return 0;
33 if (light >= 65536) return 65536;
34 const u32 target =
35 (static_cast<u32>(light) * 65535u + 32768u) >> 16;
36 u32 low = 1;
37 u32 high = static_cast<u32>(values.size() - 1);
38 while (low < high) {
39 const u32 middle = low + (high - low) / 2;
40 if (values[middle] >= target) high = middle;
41 else low = middle + 1;
42 }
43 high = low;
44 const u32 low_value = values[high - 1];
45 const u32 high_value = values[high];
46 // A plateau at the requested light maps to its first attainable code.
47 if (high_value == low_value) {
48 return static_cast<i32>((high - 1) * 65536u /
49 static_cast<u32>(values.size() - 1));
50 }
51 const u32 interval = high_value - low_value;
52 const u32 fraction =
53 ((target - low_value) * 65536u + interval / 2) / interval;
54 const u32 segments = static_cast<u32>(values.size() - 1);
55 return static_cast<i32>(((high - 1) * 65536u + fraction + segments / 2) /
56 segments);
57}
fl::size size() const FL_NO_EXCEPT

References fl::FL_NO_EXCEPT, and inverseResponseQ16().

Referenced by inverseResponseQ16().

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