FastLED 3.10.8
Loading...
Searching...
No Matches
frame_interpolator.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/fx/frame.h"
4#include "fl/stl/flat_map.h"
5#include "fl/stl/shared_ptr.h"
6#include "fl/stl/span.h"
7#include "fl/fx/frame.h"
9#include "fl/stl/noexcept.h"
10
11namespace fl {
12namespace video {
13
15
16// Holds onto frames and allow interpolation. This allows
17// effects to have high effective frame rate and also
18// respond to things like sound which can modify the timing.
20 public:
21 struct Less {
22 bool operator()(fl::u32 a, fl::u32 b) const FL_NO_EXCEPT { return a < b; }
23 };
25 FrameInterpolator(size_t nframes, float fpsVideo) FL_NO_EXCEPT;
26
27 // Will search through the array, select the two frames that are closest to
28 // the current time and then interpolate between them, storing the results
29 // in the provided frame. The destination frame will have "now" as the
30 // current timestamp if and only if there are two frames that can be
31 // interpolated. Else it's set to the timestamp of the frame that was
32 // selected. Returns true if the interpolation was successful, false
33 // otherwise. If false then the destination frame will not be modified. Note
34 // that this adjustable_time is allowed to go pause or go backward in time.
35 bool draw(fl::u32 adjustable_time, Frame *dst) FL_NO_EXCEPT;
36 bool draw(fl::u32 adjustable_time, fl::span<CRGB> leds) FL_NO_EXCEPT;
37 bool insert(fl::u32 frameNumber, FramePtr frame) FL_NO_EXCEPT {
39 mFrames.insert(frameNumber, frame, &result);
41 }
42
43 // Clear all frames
44 void clear() FL_NO_EXCEPT { mFrames.clear(); }
45
46 bool empty() const FL_NO_EXCEPT { return mFrames.empty(); }
47
48 bool has(fl::u32 frameNum) const FL_NO_EXCEPT { return mFrames.has(frameNum); }
49
50 FramePtr erase(fl::u32 frameNum) FL_NO_EXCEPT {
51 FramePtr out;
52 auto it = mFrames.find(frameNum);
53 if (it == mFrames.end()) {
54 return out;
55 }
56 out = it->second;
57 mFrames.erase(it);
58 return out;
59 }
60
61 FramePtr get(fl::u32 frameNum) const FL_NO_EXCEPT {
62 auto it = mFrames.find(frameNum);
63 if (it != mFrames.end()) {
64 return it->second;
65 }
66 return FramePtr();
67 }
68
69 bool full() const FL_NO_EXCEPT { return mFrames.full(); }
70 size_t capacity() const FL_NO_EXCEPT { return mFrames.capacity(); }
71
73
74 bool needsFrame(fl::u32 now, fl::u32 *currentFrameNumber,
75 fl::u32 *nextFrameNumber) const FL_NO_EXCEPT {
76 mFrameTracker.get_interval_frames(now, currentFrameNumber,
77 nextFrameNumber);
78 return !has(*currentFrameNumber) || !has(*nextFrameNumber);
79 }
80
81 bool get_newest_frame_number(fl::u32 *frameNumber) const FL_NO_EXCEPT {
82 if (mFrames.empty()) {
83 return false;
84 }
85 auto &front = mFrames.back();
86 *frameNumber = front.first;
87 return true;
88 }
89
90 bool get_oldest_frame_number(fl::u32 *frameNumber) const FL_NO_EXCEPT {
91 if (mFrames.empty()) {
92 return false;
93 }
94 auto &front = mFrames.front();
95 *frameNumber = front.first;
96 return true;
97 }
98
99 fl::u32 get_exact_timestamp_ms(fl::u32 frameNumber) const FL_NO_EXCEPT {
100 return mFrameTracker.get_exact_timestamp_ms(frameNumber);
101 }
102
104
105 private:
108};
109
110} // namespace video
111} // namespace fl
CRGB leds[1]
bool insert(fl::u32 frameNumber, FramePtr frame) FL_NO_EXCEPT
bool full() const FL_NO_EXCEPT
FrameInterpolator(size_t nframes, float fpsVideo) FL_NO_EXCEPT
bool get_newest_frame_number(fl::u32 *frameNumber) const FL_NO_EXCEPT
size_t capacity() const FL_NO_EXCEPT
FrameTracker & getFrameTracker() FL_NO_EXCEPT
bool empty() const FL_NO_EXCEPT
bool has(fl::u32 frameNum) const FL_NO_EXCEPT
fl::u32 get_exact_timestamp_ms(fl::u32 frameNumber) const FL_NO_EXCEPT
bool get_oldest_frame_number(fl::u32 *frameNumber) const FL_NO_EXCEPT
FrameBuffer * getFrames() FL_NO_EXCEPT
bool draw(fl::u32 adjustable_time, Frame *dst) FL_NO_EXCEPT
fl::flat_map< fl::u32, FramePtr, Less > FrameBuffer
FramePtr erase(fl::u32 frameNum) FL_NO_EXCEPT
bool needsFrame(fl::u32 now, fl::u32 *currentFrameNumber, fl::u32 *nextFrameNumber) const FL_NO_EXCEPT
FramePtr get(fl::u32 frameNum) const FL_NO_EXCEPT
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
Base definition for an LED controller.
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
bool operator()(fl::u32 a, fl::u32 b) const FL_NO_EXCEPT