FastLED
3.9.3
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 "ref.h"
9
#include "force_inline.h"
10
#include "allocator.h"
11
12
#include "namespace.h"
13
14
FASTLED_NAMESPACE_BEGIN
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_REF_NO_FWD(
LUT16
);
37
FASTLED_SMART_REF_NO_FWD(
LUTXYFLOAT
);
38
39
// Templated lookup table.
40
template
<
typename
T>
41
class
LUT
:
public
Referent
{
42
public
:
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
}
69
private
:
70
scoped_ptr<T>
mDataHandle;
71
T* data =
nullptr
;
72
uint32_t length;
73
};
74
75
FASTLED_NAMESPACE_END
LUT
Definition
lut.h:41
LargeBlockAllocator
Definition
allocator.h:17
RefTraits
Definition
ref.h:44
Referent
Definition
ref.h:384
scoped_ptr
Definition
scoped_ptr.h:27
pair_xy
Definition
lut.h:17
src
lut.h
Generated on Thu Nov 14 2024 00:00:34 for FastLED by
1.11.0