FastLED 3.9.3
Loading...
Searching...
No Matches
frame_interpolator.h
1#pragma once
2
3#include "fx/detail/data_stream.h"
4#include "fx/frame.h"
5#include "namespace.h"
6#include "fx/detail/circular_buffer.h"
7#include "fx/video/high_precision_interval.h"
8
9FASTLED_NAMESPACE_BEGIN
10
11FASTLED_SMART_REF(FrameInterpolator);
12
13// Holds onto frames and allow interpolation. This allows
14// effects to have high effective frame rate and also
15// respond to things like sound which can modify the timing.
17public:
19 FrameInterpolator(size_t nframes, float fpsVideo);
20
21 HighPrecisionInterval& getInterval() { return mInterval; }
22 const HighPrecisionInterval& getInterval() const { return mInterval; }
23
24 // Will search through the array, select the two frames that are closest to the current time
25 // and then interpolate between them, storing the results in the provided frame.
26 // The destination frame will have "now" as the current timestamp if and only if
27 // there are two frames that can be interpolated. Else it's set to the timestamp of the
28 // frame that was selected.
29 // Returns true if the interpolation was successful, false otherwise. If false then
30 // the destination frame will not be modified.
31 // Note that this adjustable_time is allowed to go pause or go backward in time.
32 bool draw(uint32_t adjustable_time, Frame* dst);
33 bool draw(uint32_t adjustable_time, CRGB* leds, uint8_t* alpha, uint32_t* precise_timestamp = nullptr);
34
35 // Frame's resources are copied into the internal data structures.
36 bool add(const Frame& frame);
37
38 // Used for recycling externally.
39 bool pop_back(FrameRef* dst) { return mFrames.pop_back(dst); }
40 bool push_front(FrameRef frame, uint32_t timestamp) {
41 if (mFrames.full()) {
42 return false;
43 }
44 if (!mFrames.empty() && timestamp <= mFrames.front()->getTimestamp()) {
45 return false;
46 }
47 frame->setTimestamp(timestamp);
48 return mFrames.push_front(frame);
49 }
50
51 bool pushNewest(FrameRef frame, uint32_t timestamp) {
52 frame->setTimestamp(timestamp);
53 return push_front(frame, timestamp);
54 }
55 bool popOldest(FrameRef* dst) { return mFrames.pop_back(dst); }
56
57 bool addWithTimestamp(const Frame& frame, uint32_t timestamp);
58
59 // Clear all frames
60 void clear() {
61 mFrames.clear();
62 mInterval.reset(0);
63 }
64
65 // Selects the two frames that are closest to the current time. Returns false on failure.
66 // frameMin will be before or equal to the current time, frameMax will be after.
67 bool selectFrames(uint32_t now, const Frame** frameMin, const Frame** frameMax) const;
68 bool full() const { return mFrames.full(); }
69
70
71 FrameBuffer* getFrames() { return &mFrames; }
72
73 bool needsFrame(uint32_t now, uint32_t* precise_timestamp) const {
74 return mInterval.needsFrame(now, precise_timestamp);
75 }
76
77 void reset(uint32_t startTime) { mInterval.reset(startTime); }
78 void incrementFrameCounter() { mInterval.incrementIntervalCounter(); }
79
80 void pause(uint32_t now) { mInterval.pause(now); }
81 void resume(uint32_t now) { mInterval.resume(now); }
82 bool isPaused() const { return mInterval.isPaused(); }
83
84private:
85 FrameBuffer mFrames;
86 HighPrecisionInterval mInterval;
87};
88
89FASTLED_NAMESPACE_END
90
Definition frame.h:18
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39