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

◆ draw()

void fl::Corkscrew::draw ( bool use_multi_sampling = true)

Definition at line 317 of file corkscrew.cpp.

317 {
318 // The draw method should map from the rectangular surface to the LED pixel data
319 // This is the reverse of readFrom - we read from our surface and populate LED data
320 auto source_surface = getOrCreateInputSurface();
321
322 // Make sure we have pixel storage
323 if (mPixelStorage.empty()) {
324 // If no pixel storage is configured, there's nothing to draw to
325 return;
326 }
327
328 CRGB* led_data = rawData();
329 if (!led_data) return;
330
331 if (use_multi_sampling) {
332 // Use multi-sampling to get better accuracy
333 for (fl::size led_idx = 0; led_idx < mNumLeds; ++led_idx) {
334 // Get the wrapped tile for this LED position
335 Tile2x2_u8_wrap tile = at_wrap(static_cast<float>(led_idx));
336
337 // Accumulate color from the 4 sample points with their weights
338 fl::u32 r_accum = 0, g_accum = 0, b_accum = 0;
339 fl::u32 total_weight = 0;
340
341 // Sample from each of the 4 corners of the tile
342 for (fl::u8 x = 0; x < 2; x++) {
343 for (fl::u8 y = 0; y < 2; y++) {
344 const auto& entry = tile.at(x, y);
345 vec2<u16> pos = entry.first;
346 fl::u8 weight = entry.second;
347
348 // Bounds check for the source surface
349 if (pos.x < source_surface->width() && pos.y < source_surface->height()) {
350 // Sample from the source surface
351 CRGB sample_color = source_surface->at(pos.x, pos.y);
352
353 // Accumulate weighted color components
354 r_accum += static_cast<fl::u32>(sample_color.r) * weight;
355 g_accum += static_cast<fl::u32>(sample_color.g) * weight;
356 b_accum += static_cast<fl::u32>(sample_color.b) * weight;
357 total_weight += weight;
358 }
359 }
360 }
361
362 // Calculate final color by dividing by total weight
363 CRGB final_color = CRGB::Black;
364 if (total_weight > 0) {
365 final_color.r = static_cast<fl::u8>(r_accum / total_weight);
366 final_color.g = static_cast<fl::u8>(g_accum / total_weight);
367 final_color.b = static_cast<fl::u8>(b_accum / total_weight);
368 }
369
370 // Store the result in the LED data
371 led_data[led_idx] = final_color;
372 }
373 } else {
374 // Simple non-multi-sampling version
375 for (fl::size led_idx = 0; led_idx < mNumLeds; ++led_idx) {
376 // Get the rectangular coordinates for this corkscrew LED
377 vec2f rect_pos = at_no_wrap(static_cast<fl::u16>(led_idx));
378
379 // Convert to integer coordinates for indexing
380 vec2i16 coord(static_cast<fl::i16>(rect_pos.x + 0.5f),
381 static_cast<fl::i16>(rect_pos.y + 0.5f));
382
383 // Clamp coordinates to surface bounds
384 coord.x = MAX(0, MIN(coord.x, static_cast<fl::i16>(source_surface->width()) - 1));
385 coord.y = MAX(0, MIN(coord.y, static_cast<fl::i16>(source_surface->height()) - 1));
386
387 // Sample from the source surface
388 CRGB sampled_color = source_surface->at(coord.x, coord.y);
389
390 // Store the sampled color in the LED data
391 led_data[led_idx] = sampled_color;
392 }
393 }
394}
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()
fl::u16 mNumLeds
Definition corkscrew.h:230
PixelStorage mPixelStorage
Definition corkscrew.h:239
CRGB * rawData()
Tile2x2_u8_wrap at_wrap(float i) const
vec2f at_no_wrap(fl::u16 i) const
Definition corkscrew.cpp:98
#define MIN(a, b)
Definition math_macros.h:41
#define MAX(a, b)
Definition math_macros.h:37
unsigned char u8
Definition int.h:17
vec2< float > vec2f
Definition geometry.h:333
vec2< i16 > vec2i16
Definition geometry.h:335
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:567

References fl::Tile2x2_u8_wrap::at(), at_no_wrap(), at_wrap(), CRGB::Black, getOrCreateInputSurface(), MAX, MIN, mNumLeds, mPixelStorage, pos, rawData(), fl::vec2< T >::x, x, fl::vec2< T >::y, and y.

+ Here is the call graph for this function: