FastLED
3.9.3
Loading...
Searching...
No Matches
frame.h
1
#pragma once
2
3
#include <string.h>
4
5
#include "namespace.h"
6
#include "crgb.h"
7
#include "ref.h"
8
9
#include "allocator.h"
10
11
FASTLED_NAMESPACE_BEGIN
12
13
FASTLED_SMART_REF(
Frame
);
14
15
// Frames are used to hold led data. This includes an optional alpha channel. This object
16
// is used by the fx and video engines. Most of the memory used for Fx and Video will be located
17
// in instances of this class. See Frame::SetAllocator() for custom memory allocation.
18
class
Frame
:
public
Referent
{
19
public
:
20
// Frames take up a lot of memory. On some devices like ESP32 there is
21
// PSRAM available. You should see allocator.h -> SetLargeBlockAllocator(...)
22
// on setting a custom allocator for these large blocks.
23
explicit
Frame
(
int
pixels_per_frame,
bool
has_alpha =
false
);
24
~Frame
()
override
;
25
CRGB
* rgb() {
return
mRgb.get(); }
26
const
CRGB
* rgb()
const
{
return
mRgb.get(); }
27
size_t
size()
const
{
return
mPixelsCount; }
28
uint8_t* alpha() {
return
mAlpha.get(); }
29
const
uint8_t* alpha()
const
{
return
mAlpha.get(); }
30
void
setTimestamp(uint32_t now) { mTimeStamp = now; }
31
uint32_t getTimestamp()
const
{
return
mTimeStamp; }
32
33
void
copy(
const
Frame
& other);
34
void
interpolate(
const
Frame
& frame1,
const
Frame
& frame2, uint8_t amountofFrame2);
35
static
void
interpolate(
const
Frame
& frame1,
const
Frame
& frame2, uint8_t amountofFrame2,
CRGB
* pixels, uint8_t* alpha);
36
void
draw(
CRGB
* leds, uint8_t* alpha)
const
;
37
private
:
38
const
size_t
mPixelsCount;
39
uint32_t mTimeStamp = 0;
40
scoped_array<CRGB>
mRgb;
41
scoped_array<uint8_t>
mAlpha;
// Optional alpha channel.
42
};
43
44
45
inline
void
Frame::copy(
const
Frame
& other) {
46
memcpy(mRgb.get(), other.mRgb.get(), other.mPixelsCount *
sizeof
(
CRGB
));
47
if
(other.mAlpha) {
48
// mAlpha.reset(new uint8_t[mPixelsCount]);
49
mAlpha.reset(
LargeBlockAllocator<uint8_t>::Alloc
(mPixelsCount));
50
memcpy(mAlpha.get(), other.mAlpha.get(), mPixelsCount);
51
}
52
}
53
54
FASTLED_NAMESPACE_END
Frame
Definition
frame.h:18
LargeBlockAllocator
Definition
allocator.h:17
Referent
Definition
ref.h:384
scoped_array
Definition
scoped_ptr.h:92
CRGB
Representation of an RGB pixel (Red, Green, Blue)
Definition
crgb.h:39
src
fx
frame.h
Generated on Thu Nov 14 2024 00:00:34 for FastLED by
1.11.0