See header for documentation. */
| 2493 | |
| 2494 | /* See header for documentation. */ |
| 2495 | astcenc_image_ptr load_ncimage( |
| 2496 | const char* filename, |
| 2497 | bool y_flip, |
| 2498 | bool& is_hdr, |
| 2499 | unsigned int& component_count |
| 2500 | ) { |
| 2501 | // Get the file extension |
| 2502 | const char* eptr = strrchr(filename, '.'); |
| 2503 | if (!eptr) |
| 2504 | { |
| 2505 | eptr = filename; |
| 2506 | } |
| 2507 | |
| 2508 | // Scan through descriptors until a matching loader is found |
| 2509 | image_loader loader { nullptr }; |
| 2510 | for (size_t i = 0; i < loader_descr_count; i++) |
| 2511 | { |
| 2512 | if (loader_descs[i].ending1 == nullptr |
| 2513 | || strcmp(eptr, loader_descs[i].ending1) == 0 |
| 2514 | || strcmp(eptr, loader_descs[i].ending2) == 0) |
| 2515 | { |
| 2516 | loader = loader_descs[i].loader_func; |
| 2517 | break; |
| 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | // We must always match a loader - stb_image provides a generic handler |
| 2522 | assert(loader); |
| 2523 | |
| 2524 | try |
| 2525 | { |
| 2526 | return loader(filename, y_flip, is_hdr, component_count); |
| 2527 | } |
| 2528 | catch (const std::bad_alloc &e) |
| 2529 | { |
| 2530 | ASTCENC_UNUSED(e); |
| 2531 | print_error("ERROR: Image memory allocation failed '%s'\n", filename); |
| 2532 | return nullptr; |
| 2533 | } |
| 2534 | } |
| 2535 | |
| 2536 | /* See header for documentation. */ |
| 2537 | bool store_ncimage( |
no test coverage detected