| 503 | } |
| 504 | |
| 505 | inline void LoadAsAssetImage(const std::string &path, const u32 custom_width, const u32 custom_height) { |
| 506 | if(path.empty()) { |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | void *img_data; |
| 511 | size_t img_data_size; |
| 512 | if(path[0] == '?') { |
| 513 | const auto asset_path = "assets/" + path.substr(1); |
| 514 | |
| 515 | auto f = fopen(asset_path.c_str(), "rb"); |
| 516 | if(f) { |
| 517 | fseek(f, 0, SEEK_END); |
| 518 | img_data_size = ftell(f); |
| 519 | rewind(f); |
| 520 | |
| 521 | img_data = malloc(img_data_size); |
| 522 | fread(img_data, img_data_size, 1, f); |
| 523 | fclose(f); |
| 524 | } |
| 525 | else { |
| 526 | emscripten_log(EM_LOG_CONSOLE, "Unable to load asset file '%s'...", asset_path.c_str()); |
| 527 | } |
| 528 | } |
| 529 | else { |
| 530 | int zip_rc; |
| 531 | for(u32 i = 0; i < std::size(AllowedImageFormats); i++) { |
| 532 | zip_rc = zip_entry_open(g_ThemeFile, (path + "." + AllowedImageFormats[i]).c_str()); |
| 533 | if(zip_rc == 0) { |
| 534 | break; |
| 535 | } |
| 536 | } |
| 537 | if(zip_rc != 0) { |
| 538 | zip_entry_close(g_ThemeFile); |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | if(zip_entry_read(g_ThemeFile, &img_data, &img_data_size) <= 0) { |
| 543 | emscripten_log(EM_LOG_CONSOLE, "Unable to read image '%s' from theme ZIP", path.c_str()); |
| 544 | zip_entry_close(g_ThemeFile); |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | zip_entry_close(g_ThemeFile); |
| 549 | } |
| 550 | |
| 551 | this->LoadAsRawImage(img_data, img_data_size, custom_width, custom_height); |
| 552 | } |
| 553 | |
| 554 | inline void LoadAsRawImage(void *img_data, const size_t img_data_size, const u32 custom_width, const u32 custom_height) { |
| 555 | this->el_img.Dispose(); |