FastLED 3.9.15
Loading...
Searching...
No Matches
frame_interpolator.cpp
Go to the documentation of this file.
3#include "fl/math_macros.h"
4#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
14namespace fl {
15
16FrameInterpolator::FrameInterpolator(size_t nframes, float fps)
17 : mFrameTracker(fps) {
18 size_t capacity = MAX(1, nframes);
19 mFrames.setMaxSize(capacity);
20}
21
22bool FrameInterpolator::draw(uint32_t now, Frame *dst) {
23 bool ok = draw(now, dst->rgb());
24 return ok;
25}
26
27bool FrameInterpolator::draw(uint32_t now, CRGB *leds) {
28 uint32_t frameNumber, nextFrameNumber;
29 uint8_t amountOfNextFrame;
30 // DBG("now: " << now);
31 mFrameTracker.get_interval_frames(now, &frameNumber, &nextFrameNumber,
32 &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:101
CRGB * rgb()
Definition frame.h:29
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:11
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:55