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

◆ readFromMulti()

void fl::Corkscrew::readFromMulti ( const fl::Grid< CRGB > & target_grid) const
private

Definition at line 396 of file corkscrew.cpp.

396 {
397 // Get the target surface and clear it
398 auto target_surface = const_cast<Corkscrew*>(this)->getOrCreateInputSurface();
399 target_surface->clear();
400 const u16 width = static_cast<u16>(source_grid.width());
401 const u16 height = static_cast<u16>(source_grid.height());
402
403 // Iterate through each LED in the corkscrew
404 for (fl::size led_idx = 0; led_idx < mNumLeds; ++led_idx) {
405 // Get the wrapped tile for this LED position
406 Tile2x2_u8_wrap tile = at_wrap(static_cast<float>(led_idx));
407
408 // Accumulate color from the 4 sample points with their weights
409 fl::u32 r_accum = 0, g_accum = 0, b_accum = 0;
410 fl::u32 total_weight = 0;
411
412 // Sample from each of the 4 corners of the tile
413 for (fl::u8 x = 0; x < 2; x++) {
414 for (fl::u8 y = 0; y < 2; y++) {
415 const auto& entry = tile.at(x, y);
416 vec2<u16> pos = entry.first; // position is the first element of the pair
417 fl::u8 weight = entry.second; // weight is the second element of the pair
418
419 // Bounds check for the source grid
420 if (pos.x >= 0 && pos.x < width &&
421 pos.y >= 0 && pos.y < height) {
422
423 // Sample from the source grid
424 CRGB sample_color = source_grid.at(pos.x, pos.y);
425
426 // Accumulate weighted color components
427 r_accum += static_cast<fl::u32>(sample_color.r) * weight;
428 g_accum += static_cast<fl::u32>(sample_color.g) * weight;
429 b_accum += static_cast<fl::u32>(sample_color.b) * weight;
430 total_weight += weight;
431 }
432 }
433 }
434
435 // Calculate final color by dividing by total weight
436 CRGB final_color = CRGB::Black;
437 if (total_weight > 0) {
438 final_color.r = static_cast<fl::u8>(r_accum / total_weight);
439 final_color.g = static_cast<fl::u8>(g_accum / total_weight);
440 final_color.b = static_cast<fl::u8>(b_accum / total_weight);
441 }
442
443 // Store the result in the target surface at the LED index position
444 auto target_surface = const_cast<Corkscrew*>(this)->getOrCreateInputSurface();
445 if (led_idx < target_surface->size()) {
446 target_surface->data()[led_idx] = final_color;
447 }
448 }
449}
int y
Definition simple.h:93
int x
Definition simple.h:92
uint8_t pos
Definition Blur.ino:11
fl::shared_ptr< fl::Grid< CRGB > > & getOrCreateInputSurface()
Corkscrew(float totalTurns, fl::u16 numLeds, bool invert=false, const Gap &gapParams=Gap())
Definition corkscrew.cpp:81
fl::u16 mNumLeds
Definition corkscrew.h:230
Tile2x2_u8_wrap at_wrap(float i) const
fl::size size() const
void clear()
Definition grid.h:30
unsigned char u8
Definition int.h:17
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:567

References Corkscrew(), fl::Grid< T >::at(), fl::Tile2x2_u8_wrap::at(), at_wrap(), CRGB::Black, fl::Grid< T >::clear(), getOrCreateInputSurface(), fl::Grid< T >::height(), mNumLeds, pos, size(), fl::Grid< T >::width(), x, and y.

Referenced by readFrom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: