FastLED 3.9.7
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 // DBG("FrameInterpolator::draw");
25 bool ok = draw(now, dst->rgb());
26 if (ok) {
27 // dst->setTimestamp(now);
28 }
29 return ok;
30}
31
32bool FrameInterpolator::draw(uint32_t now, CRGB* leds) {
33 uint32_t frameNumber, nextFrameNumber;
34 uint8_t amountOfNextFrame;
35 // DBG("now: " << now);
36 mFrameTracker.get_interval_frames(now, &frameNumber, &nextFrameNumber, &amountOfNextFrame);
37 if (!has(frameNumber)) {
38 return false;
39 }
40
41 if (has(frameNumber) && !has(nextFrameNumber)) {
42 // just paint the current frame
43 Frame* frame = get(frameNumber).get();
44 frame->draw(leds);
45 return true;
46 }
47
48 Frame* frame1 = get(frameNumber).get();
49 Frame* frame2 = get(nextFrameNumber).get();
50
51 Frame::interpolate(*frame1, *frame2, amountOfNextFrame, leds);
52 // DBG("Interpolated frame " << frameNumber << " and " << nextFrameNumber);
53 return true;
54}
55
56} // 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