FastLED 3.9.3
Loading...
Searching...
No Matches
lut.h
1#pragma once
2
3/*
4LUT - Look up table implementation for various types.
5*/
6
7#include <stdint.h>
8#include "ref.h"
9#include "force_inline.h"
10#include "allocator.h"
11
12#include "namespace.h"
13
14FASTLED_NAMESPACE_BEGIN
15
16template<typename T>
17struct pair_xy {
18 T x = 0;
19 T y = 0;
20 constexpr pair_xy() = default;
21 constexpr pair_xy(T x, T y) : x(x), y(y) {}
22};
23
24using pair_xy_float = pair_xy<float>; // It's just easier if we allow negative values.
25
26// LUT holds a look up table to map data from one
27// value to another. This can be quite big (1/3rd of the frame buffer)
28// so a Referent is used to allow memory sharing.
29
30template<typename T>
31class LUT;
32
33typedef LUT<uint16_t> LUT16;
35
36FASTLED_SMART_REF_NO_FWD(LUT16);
37FASTLED_SMART_REF_NO_FWD(LUTXYFLOAT);
38
39// Templated lookup table.
40template<typename T>
41class LUT : public Referent {
42public:
43 friend class RefTraits<LUT<T>>;
44 LUT(uint32_t length) : length(length) {
45 T* ptr = LargeBlockAllocator<T>::Alloc(length);
46 mDataHandle.reset(ptr);
47 data = ptr;
48 }
49 // In this version the data is passed in but not managed by this object.
50 LUT(uint32_t length, T* data) : length(length) {
51 this->data = data;
52 }
53 ~LUT() {
54 LargeBlockAllocator<T>::Free(mDataHandle.release(), length);
55 data = mDataHandle.get();
56 }
57
58 const T& operator[](uint32_t index) const {
59 return data[index];
60 }
61
62 const T& operator[](uint16_t index) const {
63 return data[index];
64 }
65
66 T* getData() const {
67 return data;
68 }
69private:
70 scoped_ptr<T> mDataHandle;
71 T* data = nullptr;
72 uint32_t length;
73};
74
75FASTLED_NAMESPACE_END
Definition lut.h:41
Definition lut.h:17