FastLED 3.9.15
Loading...
Searching...
No Matches
lut.h
Go to the documentation of this file.
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
35
38
39// Templated lookup table.
40template<typename T>
41class LUT : public fl::Referent {
42public:
43 LUT(uint32_t length) : length(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() {
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:
70 T* data = nullptr;
71 uint32_t length;
72};
73
74} // namespace fl
75
LUT(uint32_t length, T *data)
Definition lut.h:49
const T & operator[](uint32_t index) const
Definition lut.h:57
uint16_t * data
Definition lut.h:70
fl::scoped_ptr< uint16_t > mDataHandle
Definition lut.h:69
LUT(uint32_t length)
Definition lut.h:43
~LUT()
Definition lut.h:52
uint32_t length
Definition lut.h:71
T * getData() const
Definition lut.h:65
const T & operator[](uint16_t index) const
Definition lut.h:61
Definition lut.h:41
static T * Alloc(size_t n)
Definition allocator.h:18
static void Free(T *p)
Definition allocator.h:23
#define FASTLED_SMART_PTR_NO_FWD(type)
Definition ptr.h:21
Implements the FastLED namespace macros.
pair_xy< float > pair_xy_float
Definition lut.h:24
LUT< pair_xy_float > LUTXYFLOAT
Definition lut.h:34
LUT< uint16_t > LUT16
Definition lut.h:33
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
constexpr pair_xy()=default
constexpr pair_xy(T x, T y)
Definition lut.h:21