FastLED 3.9.15
Loading...
Searching...
No Matches
xmap.cpp
Go to the documentation of this file.
1
2
3#include "fl/xmap.h"
4
5namespace fl {
6
14
16 const u16 *lookUpTable,
17 u16 offset) {
19 out.mData = lookUpTable;
20 out.mOffset = offset;
21 return out;
22}
23
24XMap::XMap(u16 length, bool is_reverse, u16 offset) {
25 type = is_reverse ? kReverse : kLinear;
26 this->length = length;
27 this->mOffset = offset;
28}
29
30XMap::XMap(const XMap &other) {
31 type = other.type;
32 length = other.length;
33 xFunction = other.xFunction;
34 mData = other.mData;
36 mOffset = other.mOffset;
37}
38
40 if (type == kLookUpTable) {
41 return;
42 }
43 mLookUpTable.reset();
45 u16 *dataMutable = mLookUpTable->getDataMutable();
46 mData = mLookUpTable->getData();
47 for (u16 x = 0; x < length; x++) {
48 dataMutable[x] = mapToIndex(x);
49 }
51 xFunction = nullptr;
52}
53
54u16 XMap::mapToIndex(u16 x) const {
55 u16 index;
56 switch (type) {
57 case kLinear:
58 index = x_linear(x, length);
59 break;
60 case kReverse:
61 index = x_reverse(x, length);
62 break;
63 case kFunction:
64 x = x % length;
65 index = xFunction(x, length);
66 break;
67 case kLookUpTable:
68 index = mData[x];
69 break;
70 default:
71 return 0;
72 }
73 return index + mOffset;
74}
75
76u16 XMap::getLength() const { return length; }
77
78XMap::Type XMap::getType() const { return type; }
79
82
83XMap &XMap::operator=(const XMap &other) {
84 if (this != &other) {
85 type = other.type;
86 length = other.length;
87 xFunction = other.xFunction;
88 mData = other.mData;
90 mOffset = other.mOffset;
91 }
92 return *this;
93}
94
95} // namespace fl
int x
Definition simple.h:92
void convertToLookUpTable()
Definition xmap.cpp:39
Type type
Definition xmap.h:62
u16 length
Definition xmap.h:61
u16 mOffset
Definition xmap.h:66
u16 getLength() const
Definition xmap.cpp:76
Type getType() const
Definition xmap.cpp:78
u16 mapToIndex(u16 x) const
Definition xmap.cpp:54
static XMap constructWithLookUpTable(u16 length, const u16 *lookUpTable, u16 offset=0)
Definition xmap.cpp:15
fl::LUT16Ptr mLookUpTable
Definition xmap.h:65
const u16 * mData
Definition xmap.h:64
@ kFunction
Definition xmap.h:30
@ kLookUpTable
Definition xmap.h:30
@ kLinear
Definition xmap.h:30
@ kReverse
Definition xmap.h:30
XMap(u16 length, bool is_reverse=false, u16 offset=0)
Definition xmap.cpp:24
XFunction xFunction
Definition xmap.h:63
static XMap constructWithUserFunction(u16 length, XFunction xFunction, u16 offset=0)
Definition xmap.cpp:7
XMap & operator=(const XMap &other)
Definition xmap.cpp:83
UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
FASTLED_FORCE_INLINE u16 x_linear(u16 x, u16 length)
Definition xmap.h:14
FASTLED_FORCE_INLINE u16 x_reverse(u16 x, u16 length)
Definition xmap.h:19
shared_ptr< T > make_shared(Args &&... args)
Definition shared_ptr.h:348
u16(* XFunction)(u16 x, u16 length)
Definition xmap.h:24
IMPORTANT!
Definition crgb.h:20