| 249 | |
| 250 | |
| 251 | void Corkscrew::readFrom(const fl::Grid<CRGB>& source_grid, bool use_multi_sampling) { |
| 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 = fl::max(0, fl::min(coord.x, static_cast<fl::i16>(source_grid.width()) - 1)); |
| 275 | coord.y = fl::max(0, fl::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->span()[led_idx] = sampled_color; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | void Corkscrew::clear() { |
| 288 | // Clear input surface if it exists |