Frames are used to hold led data. This includes an optional alpha channel. This object is used by the fx and video engines. Most of the memory used for Fx and Video will be located in instances of this class. See Frame::SetAllocator() for custom memory allocation.
| 22 | // Fx and Video will be located in instances of this class. See |
| 23 | // Frame::SetAllocator() for custom memory allocation. |
| 24 | class 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 | |
| 41 | ~Frame() FL_NOEXCEPT; |
| 42 | fl::span<CRGB> rgb() { return fl::span<CRGB>(mRgb.data(), mPixelsCount); } |
| 43 | fl::span<const CRGB> rgb() const { return fl::span<const 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); |
| 50 | void draw(fl::span<CRGB> leds, DrawMode draw_mode = DrawMode::DRAW_MODE_OVERWRITE) const; |
| 51 | void drawXY(fl::span<CRGB> leds, const XYMap &xyMap, |
| 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; |
| 65 | fl::vector_psram<CRGB> mRgb; |
| 66 | |
| 67 | // Codec-specific members |
| 68 | fl::u16 mWidth = 0; |
| 69 | fl::u16 mHeight = 0; |
| 70 | PixelFormat mFormat = PixelFormat::RGB888; |
| 71 | fl::u32 mTimestamp = 0; |
| 72 | bool mIsFromCodec = false; |
| 73 | |
| 74 | // Helper method for pixel format conversion |
| 75 | void convertPixelsToRgb(fl::u8* pixels, PixelFormat format); |
| 76 | }; |
| 77 | |
| 78 | inline void Frame::copy(const Frame &other) { |
| 79 | fl::memcpy(mRgb.data(), other.mRgb.data(), other.mPixelsCount * sizeof(CRGB)); |
no outgoing calls
no test coverage detected