FastLED 3.10.8
Loading...
Searching...
No Matches
fx2d_to_1d.cpp.hpp
Go to the documentation of this file.
1#include "fl/fx/fx2d_to_1d.h"
2
3#include "fl/gfx/sample.h"
4#include "fl/math/xymap.h"
5#include "crgb.h"
6#include "fl/stl/allocator.h"
7#include "fl/stl/noexcept.h"
8
9namespace fl {
10
11Fx2dTo1d::Fx2dTo1d(u16 numLeds, Fx2dPtr fx2d, const ScreenMap &screenMap,
13 FL_NO_EXCEPT : Fx1d(numLeds), mFx2d(fx2d), mScreenMap(screenMap),
14 mInterpolationMode(mode), mGrid(new CRGB[fx2d->getNumLeds()]) {} // ok bare allocation (array new)
15
16void Fx2dTo1d::setFx2d(Fx2dPtr fx2d) FL_NO_EXCEPT {
17 mFx2d = fx2d;
18 // Reallocate grid buffer if needed
19 mGrid.reset(new CRGB[fx2d->getNumLeds()]); // ok bare allocation (array new)
20}
21
23 // Step 1: Render 2D effect to internal grid
24 DrawContext grid_context(context.now, fl::span<CRGB>(mGrid.get(), mFx2d->getNumLeds()));
25 mFx2d->draw(grid_context);
26
27 // Step 2: Sample from grid to 1D output using fl::sample
28 const XYMap &xyMap = mFx2d->getXYMap();
29 SampleMode mode = static_cast<SampleMode>(mInterpolationMode);
30
31 for (u16 i = 0; i < mNumLeds; i++) {
32 vec2f pos = mScreenMap[i];
33 context.leds[i] = fl::sample(mGrid.get(), xyMap, pos.x, pos.y, mode);
34 }
35}
36
38 return fl::string("Fx2dTo1d(") + mFx2d->fxName() + ")";
39}
40
41} // namespace fl
uint8_t pos
Definition Blur.ino:11
u16 xyMap(u16 x) const FL_NO_EXCEPT
Definition fx1d.h:16
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
InterpolationMode
Interpolation mode for sampling the 2D grid.
Definition fx2d_to_1d.h:40
InterpolationMode mInterpolationMode
Definition fx2d_to_1d.h:80
void draw(DrawContext context) FL_NO_EXCEPT override
fl::string fxName() const FL_NO_EXCEPT override
fl::unique_ptr< CRGB[]> mGrid
Definition fx2d_to_1d.h:83
ScreenMap mScreenMap
Definition fx2d_to_1d.h:79
Fx2dTo1d(u16 numLeds, Fx2dPtr fx2d, const ScreenMap &screenMap, InterpolationMode mode=BILINEAR) FL_NO_EXCEPT
Construct a 2D-to-1D sampling effect.
void setFx2d(Fx2dPtr fx2d) FL_NO_EXCEPT
Replace the underlying 2D effect.
Fx2dPtr mFx2d
Definition fx2d_to_1d.h:78
u16 mNumLeds
Definition fx.h:53
fl::ScreenMap screenMap
Definition Corkscrew.h:101
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode) FL_NO_EXCEPT
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
vec2< float > vec2f
Definition geometry.h:333
SampleMode
Interpolation mode for sampling a 2D grid.
Definition sample.h:14
Base definition for an LED controller.
Definition crgb.hpp:179
2D grid sampling with bilinear and nearest-neighbor interpolation
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38