FastLED 3.9.15
Loading...
Searching...
No Matches
frame.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/cstring.h"
4#include "crgb.h" // IWYU pragma: keep
5#include "fl/stl/shared_ptr.h" // For FASTLED_SHARED_PTR macros
6#include "fl/stl/span.h"
7#include "fl/math/xymap.h" // IWYU pragma: keep
8#include "fl/stl/vector.h"
9#include "fl/stl/stdint.h"
10
11#include "fl/stl/allocator.h"
12#include "fl/gfx/draw_mode.h"
13#include "fl/codec/pixel.h"
14#include "fl/stl/noexcept.h"
15
16namespace fl {
17
19
20// Frames are used to hold led data. This includes an optional alpha channel.
21// This object is used by the fx and video engines. Most of the memory used for
22// Fx and Video will be located in instances of this class. See
23// Frame::SetAllocator() for custom memory allocation.
24class Frame {
25 public:
26 // Frames take up a lot of memory. On some devices like ESP32 there is
27 // PSRAM available. You should see allocator.h ->
28 // SetPSRamAllocator(...) on setting a custom allocator for these large
29 // blocks.
30 explicit Frame(int pixels_per_frame);
31
32 // Constructor for codec-sourced frames
33 Frame(fl::u8* pixels, fl::u16 width, fl::u16 height, PixelFormat format, fl::u32 timestamp = 0);
34
35 // Copy constructor
36 Frame(const Frame& other) FL_NOEXCEPT;
37
38 // Delete copy assignment operator (can't assign due to const member)
39 Frame& operator=(const Frame& other) FL_NOEXCEPT = delete;
40
42 fl::span<CRGB> rgb() { return fl::span<CRGB>(mRgb.data(), mPixelsCount); }
44 size_t size() const { return mPixelsCount; }
45 void copy(const Frame &other);
46 void interpolate(const Frame &frame1, const Frame &frame2,
47 u8 amountOfFrame2);
48 static void interpolate(const Frame &frame1, const Frame &frame2,
49 u8 amountofFrame2, fl::span<CRGB> pixels);
52 DrawMode draw_mode = DrawMode::DRAW_MODE_OVERWRITE) const;
53 void clear();
54
55 // Codec functionality methods
56 bool isValid() const;
57 fl::u32 getTimestamp() const { return mTimestamp; }
58 PixelFormat getFormat() const { return mFormat; }
59 fl::u16 getWidth() const { return mWidth; }
60 fl::u16 getHeight() const { return mHeight; }
61 bool isFromCodec() const { return mIsFromCodec; }
62
63 private:
64 const size_t mPixelsCount;
66
67 // Codec-specific members
68 fl::u16 mWidth = 0;
69 fl::u16 mHeight = 0;
71 fl::u32 mTimestamp = 0;
72 bool mIsFromCodec = false;
73
74 // Helper method for pixel format conversion
76};
77
78inline void Frame::copy(const Frame &other) {
79 fl::memcpy(mRgb.data(), other.mRgb.data(), other.mPixelsCount * sizeof(CRGB));
80}
81
82} // namespace fl
fl::XYMap xyMap
fl::CRGB leds[NUM_LEDS]
PixelFormat mFormat
Definition frame.h:70
fl::span< const CRGB > rgb() const
Definition frame.h:43
fl::u16 mHeight
Definition frame.h:69
size_t size() const
Definition frame.h:44
bool isFromCodec() const
Definition frame.h:61
fl::u16 getWidth() const
Definition frame.h:59
Frame & operator=(const Frame &other) FL_NOEXCEPT=delete
fl::vector_psram< CRGB > mRgb
Definition frame.h:65
void convertPixelsToRgb(fl::u8 *pixels, PixelFormat format)
void drawXY(fl::span< CRGB > leds, const XYMap &xyMap, DrawMode draw_mode=DrawMode::DRAW_MODE_OVERWRITE) const
Definition frame.cpp.hpp:67
~Frame() FL_NOEXCEPT
Definition frame.cpp.hpp:45
PixelFormat getFormat() const
Definition frame.h:58
bool mIsFromCodec
Definition frame.h:72
void draw(fl::span< CRGB > leds, DrawMode draw_mode=DrawMode::DRAW_MODE_OVERWRITE) const
Definition frame.cpp.hpp:49
void interpolate(const Frame &frame1, const Frame &frame2, u8 amountOfFrame2)
fl::span< CRGB > rgb()
Definition frame.h:42
fl::u16 getHeight() const
Definition frame.h:60
const size_t mPixelsCount
Definition frame.h:64
void copy(const Frame &other)
Definition frame.h:78
Frame(int pixels_per_frame)
Definition frame.cpp.hpp:14
fl::u32 mTimestamp
Definition frame.h:71
fl::u32 getTimestamp() const
Definition frame.h:57
bool isValid() const
void clear()
fl::u16 mWidth
Definition frame.h:68
unsigned char u8
Definition s16x16x4.h:132
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
unsigned char u8
Definition stdint.h:131
u8 u8 height
Definition blur.h:186
u8 width
Definition blur.h:186
DrawMode
Definition draw_mode.h:5
@ DRAW_MODE_OVERWRITE
Definition draw_mode.h:5
fl::string format(const char *fmt)
Format with no arguments.
Definition format.h:439
PixelFormat
Definition pixel.h:7
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:535
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38