FastLED 3.9.3
Loading...
Searching...
No Matches
video.hpp
1
2
3#pragma once
4
5#include "FastLED.h"
6#include "fx/detail/data_stream.h"
7#include "fx/fx2d.h"
8#include "fx/video/frame_interpolator.h"
9#include "ref.h"
10
11FASTLED_NAMESPACE_BEGIN
12
13
14
15FASTLED_SMART_REF(VideoFx);
16
17
18
19#if 0
20
21FASTLED_SMART_REF(VideoFx);
22
23// Converts a FxGrid to a video effect. This primarily allows for
24// fixed frame rates and frame interpolation.
25class VideoFx : public FxGrid {
26 public:
27 VideoFx(XYMap xymap) : FxGrid(xymap) {}
28
29 void begin(uint32_t now, FxGridRef fx,uint16_t nFrameHistory, float fps = -1) {
30 mDelegate = fx;
31 if (!mDelegate) {
32 return; // Early return if delegate is null
33 }
34 mDelegate->getXYMap().setRectangularGrid();
35 mFps = fps < 0 ? 30 : fps;
36 mDelegate->hasFixedFrameRate(&mFps);
37 mFrameInterpolator = FrameInterpolatorRef::New(nFrameHistory, mFps);
38 mFrameInterpolator->reset(now);
39 }
40
41 void lazyInit() override {
42 if (!mInitialized) {
43 mInitialized = true;
44 mDelegate->lazyInit();
45 }
46 }
47
48 void draw(DrawContext context) override {
49 if (!mDelegate) {
50 return;
51 }
52
53 uint32_t precise_timestamp;
54 if (mFrameInterpolator->needsFrame(context.now, &precise_timestamp)) {
55 FrameRef frame;
56 bool wasFullBeforePop = mFrameInterpolator->full();
57 if (wasFullBeforePop) {
58 if (!mFrameInterpolator->popOldest(&frame)) {
59 return; // Failed to pop, something went wrong
60 }
61 if (mFrameInterpolator->full()) {
62 return; // Still full after popping, something went wrong
63 }
64 } else {
65 frame = FrameRef::New(mDelegate->getNumLeds(), mDelegate->hasAlphaChannel());
66 }
67
68 if (!frame) {
69 return; // Something went wrong.
70 }
71
72 DrawContext delegateContext = context;
73 delegateContext.leds = frame->rgb();
74 delegateContext.alpha_channel = frame->alpha();
75 delegateContext.now = precise_timestamp;
76 mDelegate->draw(delegateContext);
77
78 mFrameInterpolator->pushNewest(frame, precise_timestamp);
79 mFrameInterpolator->incrementFrameCounter();
80 }
81
82 mFrameInterpolator->draw(context.now, context.leds, context.alpha_channel);
83 }
84
85 const char *fxName(int) const override { return "video_fx"; }
86
87 private:
88 Ref<FxGrid> mDelegate;
89 bool mInitialized = false;
90 FrameInterpolatorRef mFrameInterpolator;
91 float mFps;
92};
93
94#endif
95
96FASTLED_NAMESPACE_END
central include file for FastLED, defines the CFastLED class/object
Definition fx2d.h:16
Definition ref.h:99
void draw(DrawContext context) override
Definition video.cpp:234
Definition xymap.h:39