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
11FASTLED_NAMESPACE_BEGIN
12
13FASTLED_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.
18class Frame : public Referent {
19public:
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;
37private:
38 const size_t mPixelsCount;
39 uint32_t mTimeStamp = 0;
41 scoped_array<uint8_t> mAlpha; // Optional alpha channel.
42};
43
44
45inline 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
54FASTLED_NAMESPACE_END
Definition frame.h:18
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39