FastLED 3.9.7
Loading...
Searching...
No Matches
frame.cpp
1
2#include <string.h>
3
4#include "frame.h"
5#include "crgb.h"
6#include "fl/namespace.h"
7#include "fl/ptr.h"
8#include "fl/dbg.h"
9#include "fl/allocator.h"
10
11
12namespace fl {
13
14
15Frame::Frame(int pixels_count)
16 : mPixelsCount(pixels_count), mRgb() {
17 mRgb.reset(reinterpret_cast<CRGB *>(LargeBlockAllocate(pixels_count * sizeof(CRGB))));
18 memset(mRgb.get(), 0, pixels_count * sizeof(CRGB));
19}
20
21Frame::~Frame() {
22 if (mRgb) {
23 LargeBlockDeallocate(mRgb.release());
24 }
25}
26
27void Frame::draw(CRGB* leds) const {
28 if (mRgb) {
29 memcpy(leds, mRgb.get(), mPixelsCount * sizeof(CRGB));
30 }
31}
32
33
34void Frame::interpolate(const Frame& frame1, const Frame& frame2, uint8_t amountofFrame2, CRGB* pixels) {
35 if (frame1.size() != frame2.size()) {
36 return; // Frames must have the same size
37 }
38
39 const CRGB* rgbFirst = frame1.rgb();
40 const CRGB* rgbSecond = frame2.rgb();
41
42 if (!rgbFirst || !rgbSecond) {
43 // Error, why are we getting null pointers?
44 return;
45 }
46
47 for (size_t i = 0; i < frame2.size(); ++i) {
48 pixels[i] = CRGB::blend(rgbFirst[i], rgbSecond[i], amountofFrame2);
49 }
50 // We will eventually do something with alpha.
51}
52
53void Frame::interpolate(const Frame& frame1, const Frame& frame2, uint8_t amountOfFrame2) {
54 if (frame1.size() != frame2.size() || frame1.size() != mPixelsCount) {
55 FASTLED_DBG("Frames must have the same size");
56 return; // Frames must have the same size
57 }
58 interpolate(frame1, frame2, amountOfFrame2, mRgb.get());
59}
60
61} // namespace fl
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54