FastLED 3.9.7
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 "fl/ptr.h"
9#include "fl/force_inline.h"
10#include "fl/allocator.h"
11
12#include "fl/namespace.h"
13
14namespace fl {
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_PTR_NO_FWD(LUT16);
37FASTLED_SMART_PTR_NO_FWD(LUTXYFLOAT);
38
39// Templated lookup table.
40template<typename T>
41class LUT : public fl::Referent {
42public:
43 LUT(uint32_t length) : length(length) {
44 T* ptr = LargeBlockAllocator<T>::Alloc(length);
45 mDataHandle.reset(ptr);
46 data = ptr;
47 }
48 // In this version the data is passed in but not managed by this object.
49 LUT(uint32_t length, T* data) : length(length) {
50 this->data = data;
51 }
52 ~LUT() {
53 LargeBlockAllocator<T>::Free(mDataHandle.release());
54 data = mDataHandle.get();
55 }
56
57 const T& operator[](uint32_t index) const {
58 return data[index];
59 }
60
61 const T& operator[](uint16_t index) const {
62 return data[index];
63 }
64
65 T* getData() const {
66 return data;
67 }
68private:
69 fl::scoped_ptr<T> mDataHandle;
70 T* data = nullptr;
71 uint32_t length;
72};
73
74} // namespace fl
75
Definition lut.h:41
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16