FastLED 3.9.15
Loading...
Searching...
No Matches

◆ readFrom()

void fl::Corkscrew::readFrom ( const fl::Grid< CRGB > & source_grid,
bool use_multi_sampling = true )
private

Definition at line 251 of file corkscrew.cpp.

251 {
252
253 if (use_multi_sampling) {
254 readFromMulti(source_grid);
255 return;
256 }
257
258 // Get or create the input surface
259 auto target_surface = getOrCreateInputSurface();
260
261 // Clear surface first
262 target_surface->clear();
263
264 // Iterate through each LED in the corkscrew
265 for (fl::size led_idx = 0; led_idx < mNumLeds; ++led_idx) {
266 // Get the rectangular coordinates for this corkscrew LED
267 vec2f rect_pos = at_no_wrap(static_cast<fl::u16>(led_idx));
268
269 // Convert to integer coordinates for indexing
270 vec2i16 coord(static_cast<fl::i16>(rect_pos.x + 0.5f),
271 static_cast<fl::i16>(rect_pos.y + 0.5f));
272
273 // Clamp coordinates to grid bounds
274 coord.x = MAX(0, MIN(coord.x, static_cast<fl::i16>(source_grid.width()) - 1));
275 coord.y = MAX(0, MIN(coord.y, static_cast<fl::i16>(source_grid.height()) - 1));
276
277 // Sample from the source fl::Grid using its at() method
278 CRGB sampled_color = source_grid.at(coord.x, coord.y);
279
280 // Store the sampled color directly in the target surface
281 if (led_idx < target_surface->size()) {
282 target_surface->data()[led_idx] = sampled_color;
283 }
284 }
285}
fl::shared_ptr< fl::Grid< CRGB > > & getOrCreateInputSurface()
fl::u16 mNumLeds
Definition corkscrew.h:230
void readFromMulti(const fl::Grid< CRGB > &target_grid) const
fl::size size() const
vec2f at_no_wrap(fl::u16 i) const
Definition corkscrew.cpp:98
u32 height() const
Definition grid.h:60
T & at(u32 x, u32 y)
Definition grid.h:53
u32 width() const
Definition grid.h:59
#define MIN(a, b)
Definition math_macros.h:41
#define MAX(a, b)
Definition math_macros.h:37
vec2< float > vec2f
Definition geometry.h:333
vec2< i16 > vec2i16
Definition geometry.h:335

References fl::Grid< T >::at(), at_no_wrap(), getOrCreateInputSurface(), fl::Grid< T >::height(), MAX, MIN, mNumLeds, readFromMulti(), size(), fl::Grid< T >::width(), fl::vec2< T >::x, and fl::vec2< T >::y.

+ Here is the call graph for this function: