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

◆ draw()

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

Definition at line 318 of file corkscrew.cpp.hpp.

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

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

+ Here is the call graph for this function: