| 311 | } |
| 312 | |
| 313 | EMSCRIPTEN_KEEPALIVE void jsFillInMissingScreenMaps(ActiveStripData &active_strips) { |
| 314 | struct Function { |
| 315 | static bool isSquare(int num) { |
| 316 | int root = sqrt(num); |
| 317 | return root * root == num; |
| 318 | } |
| 319 | }; |
| 320 | const auto &info = active_strips.getData(); |
| 321 | // check to see if we have any missing screenmaps. |
| 322 | for (const auto &pair : info) { |
| 323 | int stripIndex = pair.first; |
| 324 | const auto &stripData = pair.second; |
| 325 | const bool has_screen_map = active_strips.hasScreenMap(stripIndex); |
| 326 | if (!has_screen_map) { |
| 327 | fl::printf("Missing screenmap for strip %d\n", stripIndex); |
| 328 | // okay now generate a screenmap for this strip, let's assume |
| 329 | // a linear strip with only one row. |
| 330 | const u32 pixel_count = stripData.size() / 3; |
| 331 | ScreenMap screenmap(pixel_count); |
| 332 | if (pixel_count > 255 && Function::isSquare(pixel_count)) { |
| 333 | fl::printf("Creating square screenmap for %d\n", pixel_count); |
| 334 | u32 side = sqrt(pixel_count); |
| 335 | // This is a square matrix, let's assume it's a square matrix |
| 336 | // and generate a screenmap for it. |
| 337 | for (u16 i = 0; i < side; i++) { |
| 338 | for (u16 j = 0; j < side; j++) { |
| 339 | u16 index = i * side + j; |
| 340 | vec2f p = { |
| 341 | static_cast<float>(i), |
| 342 | static_cast<float>(j) |
| 343 | }; |
| 344 | screenmap.set(index, p); |
| 345 | } |
| 346 | } |
| 347 | active_strips.updateScreenMap(stripIndex, screenmap); |
| 348 | // Fire off the event to the JavaScript side that we now have |
| 349 | // a screenmap for this strip. |
| 350 | _jsSetCanvasSize(stripIndex, screenmap); |
| 351 | } else { |
| 352 | fl::printf("Creating linear screenmap for %d\n", pixel_count); |
| 353 | ScreenMap screenmap(pixel_count); |
| 354 | for (u32 i = 0; i < pixel_count; i++) { |
| 355 | screenmap.set(i, {static_cast<float>(i), 0}); |
| 356 | } |
| 357 | active_strips.updateScreenMap(stripIndex, screenmap); |
| 358 | // Fire off the event to the JavaScript side that we now have |
| 359 | // a screenmap for this strip. |
| 360 | _jsSetCanvasSize(stripIndex, screenmap); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Pure C++ Frame Processing Function - Exports data instead of calling JavaScript |
no test coverage detected