FastLED
3.9.7
Loading...
Searching...
No Matches
lut.h
1
#pragma once
2
3
/*
4
LUT - 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
14
namespace
fl
{
15
16
template
<
typename
T>
17
struct
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
24
using
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
30
template
<
typename
T>
31
class
LUT
;
32
33
typedef
LUT<uint16_t>
LUT16
;
34
typedef
LUT<pair_xy_float>
LUTXYFLOAT
;
35
36
FASTLED_SMART_PTR_NO_FWD(
LUT16
);
37
FASTLED_SMART_PTR_NO_FWD(
LUTXYFLOAT
);
38
39
// Templated lookup table.
40
template
<
typename
T>
41
class
LUT
:
public
fl::Referent
{
42
public
:
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
}
68
private
:
69
fl::scoped_ptr<T>
mDataHandle;
70
T* data =
nullptr
;
71
uint32_t length;
72
};
73
74
}
// namespace fl
75
fl::LUT
Definition
lut.h:41
fl::LargeBlockAllocator
Definition
allocator.h:16
fl::Referent
Definition
ptr.h:387
fl::scoped_ptr
Definition
scoped_ptr.h:27
namespace.h
Implements the FastLED namespace macros.
fl
Implements a simple red square effect for 2D LED grids.
Definition
crgb.h:16
fl::pair_xy
Definition
lut.h:17
src
fl
lut.h
Generated on Fri Dec 20 2024 20:54:48 for FastLED by
1.11.0