FastLED 3.9.12
Loading...
Searching...
No Matches
frame_interpolator.cpp
1#include "fx/video/frame_interpolator.h"
2#include "fl/circular_buffer.h"
3#include "fx/video/pixel_stream.h"
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
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