FastLED 3.10.8
Loading...
Searching...
No Matches
xmap.h
Go to the documentation of this file.
1#pragma once
2
4#include "fl/math/lut.h"
5#include "fl/stl/int.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9
11 (void)length;
12 return x;
13}
14
16 return length - 1 - x;
17}
18
19// typedef for xMap function type
20typedef u16 (*XFunction)(u16 x, u16 length);
21
22// XMap holds either a function or a look up table to map x coordinates to a 1D
23// index.
24class XMap {
25 public:
27
29 u16 offset = 0) FL_NO_EXCEPT;
30
31 // When a pointer to a lookup table is passed in then we assume it's
32 // owned by someone else and will not be deleted.
34 const u16 *lookUpTable,
35 u16 offset = 0) FL_NO_EXCEPT;
36
37 // is_reverse is false by default for linear layout
38 XMap(u16 length, bool is_reverse = false, u16 offset = 0) FL_NO_EXCEPT;
39
40 XMap(const XMap &other) FL_NO_EXCEPT;
41
42 // define the assignment operator
43 XMap &operator=(const XMap &other) FL_NO_EXCEPT;
44
46
47 u16 mapToIndex(u16 x) const FL_NO_EXCEPT;
48
49 u16 operator()(u16 x) const FL_NO_EXCEPT { return mapToIndex(x); }
50
51 u16 getLength() const FL_NO_EXCEPT;
52
54
55 private:
57 u16 length = 0;
60 const u16 *mData = nullptr;
61 fl::LUT16Ptr mLookUpTable;
62 u16 mOffset = 0; // offset to be added to the output
63};
64
65} // namespace fl
u16 getLength() const FL_NO_EXCEPT
Definition xmap.cpp.hpp:77
Type type
Definition xmap.h:58
void convertToLookUpTable() FL_NO_EXCEPT
Definition xmap.cpp.hpp:40
u16 length
Definition xmap.h:57
u16 mOffset
Definition xmap.h:62
XMap(u16 length, bool is_reverse=false, u16 offset=0) FL_NO_EXCEPT
Definition xmap.cpp.hpp:25
fl::LUT16Ptr mLookUpTable
Definition xmap.h:61
static XMap constructWithUserFunction(u16 length, XFunction xFunction, u16 offset=0) FL_NO_EXCEPT
Definition xmap.cpp.hpp:8
Type getType() const FL_NO_EXCEPT
Definition xmap.cpp.hpp:79
const u16 * mData
Definition xmap.h:60
static XMap constructWithLookUpTable(u16 length, const u16 *lookUpTable, u16 offset=0) FL_NO_EXCEPT
Definition xmap.cpp.hpp:16
@ kFunction
Definition xmap.h:26
@ kLookUpTable
Definition xmap.h:26
@ kLinear
Definition xmap.h:26
@ kReverse
Definition xmap.h:26
u16 mapToIndex(u16 x) const FL_NO_EXCEPT
Definition xmap.cpp.hpp:55
XFunction xFunction
Definition xmap.h:59
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
u16(* XFunction)(u16 x, u16 length)
Definition xmap.h:20
FASTLED_FORCE_INLINE u16 x_linear(u16 x, u16 length) FL_NO_EXCEPT
Definition xmap.h:10
FASTLED_FORCE_INLINE u16 x_reverse(u16 x, u16 length) FL_NO_EXCEPT
Definition xmap.h:15
Base definition for an LED controller.
#define FASTLED_FORCE_INLINE