FastLED 3.9.15
Loading...
Searching...
No Matches
frame_interpolator.cpp
Go to the documentation of this file.
4#include "fl/math_macros.h"
5#include "fl/namespace.h"
6
7#include "fl/dbg.h"
8
9#include "fl/math_macros.h"
10#include <math.h>
11
12#define DBG FASTLED_DBG
13
14
15namespace fl {
16
17FrameInterpolator::FrameInterpolator(size_t nframes, float fps)
18 : mFrameTracker(fps) {
19 size_t capacity = MAX(1, nframes);
20 mFrames.setMaxSize(capacity);
21}
22
23bool FrameInterpolator::draw(uint32_t now, Frame *dst) {
24 bool ok = draw(now, dst->rgb());
25 return ok;
26}
27
28bool FrameInterpolator::draw(uint32_t now, CRGB* leds) {
29 uint32_t frameNumber, nextFrameNumber;
30 uint8_t amountOfNextFrame;
31 // DBG("now: " << now);
32 mFrameTracker.get_interval_frames(now, &frameNumber, &nextFrameNumber, &amountOfNextFrame);
33 if (!has(frameNumber)) {
34 return false;
35 }
36
37 if (has(frameNumber) && !has(nextFrameNumber)) {
38 // just paint the current frame
39 Frame* frame = get(frameNumber).get();
40 frame->draw(leds);
41 return true;
42 }
43
44 Frame* frame1 = get(frameNumber).get();
45 Frame* frame2 = get(nextFrameNumber).get();
46
47 Frame::interpolate(*frame1, *frame2, amountOfNextFrame, leds);
48 return true;
49}
50
51} // namespace fl
CRGB leds[NUM_LEDS]
Definition Apa102.ino:11
void draw(CRGB *leds, DrawMode draw_mode=DRAW_MODE_OVERWRITE) const
Definition frame.cpp:29
void interpolate(const Frame &frame1, const Frame &frame2, uint8_t amountOfFrame2)
Definition frame.cpp:98
CRGB * rgb()
Definition frame.h:32
FramePtr get(uint32_t frameNum) const
bool has(uint32_t frameNum) const
FrameInterpolator(size_t nframes, float fpsVideo)
bool draw(uint32_t adjustable_time, Frame *dst)
#define MAX(a, b)
Definition math_macros.h:4
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