FastLED 3.9.15
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
8namespace fl {
9
10Fx2dTo1d::Fx2dTo1d(u16 numLeds, Fx2dPtr fx2d, const ScreenMap &screenMap,
12 : Fx1d(numLeds), mFx2d(fx2d), mScreenMap(screenMap),
13 mInterpolationMode(mode), mGrid(new CRGB[fx2d->getNumLeds()]) {} // ok bare allocation (array new)
14
15void Fx2dTo1d::setFx2d(Fx2dPtr fx2d) {
16 mFx2d = fx2d;
17 // Reallocate grid buffer if needed
18 mGrid.reset(new CRGB[fx2d->getNumLeds()]); // ok bare allocation (array new)
19}
20
22 // Step 1: Render 2D effect to internal grid
23 DrawContext grid_context(context.now, fl::span<CRGB>(mGrid.get(), mFx2d->getNumLeds()));
24 mFx2d->draw(grid_context);
25
26 // Step 2: Sample from grid to 1D output using fl::sample
27 const XYMap &xyMap = mFx2d->getXYMap();
28 SampleMode mode = static_cast<SampleMode>(mInterpolationMode);
29
30 for (u16 i = 0; i < mNumLeds; i++) {
31 vec2f pos = mScreenMap[i];
32 context.leds[i] = fl::sample(mGrid.get(), xyMap, pos.x, pos.y, mode);
33 }
34}
35
37 return fl::string("Fx2dTo1d(") + mFx2d->fxName() + ")";
38}
39
40} // namespace fl
uint8_t pos
Definition Blur.ino:11
u16 xyMap(u16 x) const
Definition fx1d.h:15
Fx1d(u16 numLeds)
Definition fx1d.h:12
InterpolationMode
Interpolation mode for sampling the 2D grid.
Definition fx2d_to_1d.h:39
InterpolationMode mInterpolationMode
Definition fx2d_to_1d.h:79
fl::unique_ptr< CRGB[]> mGrid
Definition fx2d_to_1d.h:82
Fx2dTo1d(u16 numLeds, Fx2dPtr fx2d, const ScreenMap &screenMap, InterpolationMode mode=BILINEAR)
Construct a 2D-to-1D sampling effect.
fl::string fxName() const override
void setFx2d(Fx2dPtr fx2d)
Replace the underlying 2D effect.
ScreenMap mScreenMap
Definition fx2d_to_1d.h:78
void draw(DrawContext context) override
Fx2dPtr mFx2d
Definition fx2d_to_1d.h:77
u16 mNumLeds
Definition fx.h:53
u16 getNumLeds() const
Definition fx.h:49
fl::ScreenMap screenMap
Definition Corkscrew.h:101
vec2< float > vec2f
Definition geometry.h:333
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode)
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
Definition sample.cpp.hpp:9
SampleMode
Interpolation mode for sampling a 2D grid.
Definition sample.h:13
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
fl::span< CRGB > leds