diff --git a/editor/export/editor_export_platform.cpp b/editor/export/editor_export_platform.cpp index 8b44a6f88ab..f8358dd0728 100644 --- a/editor/export/editor_export_platform.cpp +++ b/editor/export/editor_export_platform.cpp @@ -35,6 +35,7 @@ #include "core/extension/gdextension.h" #include "core/io/file_access_encrypted.h" #include "core/io/file_access_pack.h" // PACK_HEADER_MAGIC, PACK_FORMAT_VERSION +#include "core/io/image_loader.h" #include "core/io/resource_uid.h" #include "core/io/zip_io.h" #include "core/version.h" @@ -82,6 +83,28 @@ static int _get_pad(int p_alignment, int p_n) { #define PCK_PADDING 16 +Ref EditorExportPlatform::_load_icon_or_splash_image(const String &p_path, Error *r_error) const { + Ref image; + + if (!p_path.is_empty() && ResourceLoader::exists(p_path) && !ResourceLoader::get_resource_type(p_path).is_empty()) { + Ref texture = ResourceLoader::load(p_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, r_error); + if (texture.is_valid()) { + image = texture->get_image(); + if (image.is_valid() && image->is_compressed()) { + image->decompress(); + } + } + } + if (image.is_null()) { + image.instantiate(); + Error err = ImageLoader::load_image(p_path, image); + if (r_error) { + *r_error = err; + } + } + return image; +} + bool EditorExportPlatform::fill_log_messages(RichTextLabel *p_log, Error p_err) { bool has_messages = false; diff --git a/editor/export/editor_export_platform.h b/editor/export/editor_export_platform.h index a79cd4fb528..ed494514335 100644 --- a/editor/export/editor_export_platform.h +++ b/editor/export/editor_export_platform.h @@ -202,6 +202,8 @@ protected: Error _load_patches(const Vector &p_patches); void _unload_patches(); + Ref _load_icon_or_splash_image(const String &p_path, Error *r_error) const; + public: virtual void get_preset_features(const Ref &p_preset, List *r_features) const = 0; diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 9f4650d0833..752acc84995 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -1723,18 +1723,18 @@ void EditorExportPlatformAndroid::_process_launcher_icons(const String &p_file_n void EditorExportPlatformAndroid::load_icon_refs(const Ref &p_preset, Ref &icon, Ref &foreground, Ref &background, Ref &monochrome) { String project_icon_path = GLOBAL_GET("application/config/icon"); - icon.instantiate(); - foreground.instantiate(); - background.instantiate(); - monochrome.instantiate(); + Error err = OK; // Regular icon: user selection -> project icon -> default. String path = static_cast(p_preset->get(LAUNCHER_ICON_OPTION)).strip_edges(); print_verbose("Loading regular icon from " + path); - if (path.is_empty() || ImageLoader::load_image(path, icon) != OK) { + if (!path.is_empty()) { + icon = _load_icon_or_splash_image(path, &err); + } + if (path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) { print_verbose("- falling back to project icon: " + project_icon_path); if (!project_icon_path.is_empty()) { - ImageLoader::load_image(project_icon_path, icon); + icon = _load_icon_or_splash_image(project_icon_path, &err); } else { ERR_PRINT("No project icon specified. Please specify one in the Project Settings under Application -> Config -> Icon"); } @@ -1743,7 +1743,10 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref & // Adaptive foreground: user selection -> regular icon (user selection -> project icon -> default). path = static_cast(p_preset->get(LAUNCHER_ADAPTIVE_ICON_FOREGROUND_OPTION)).strip_edges(); print_verbose("Loading adaptive foreground icon from " + path); - if (path.is_empty() || ImageLoader::load_image(path, foreground) != OK) { + if (!path.is_empty()) { + foreground = _load_icon_or_splash_image(path, &err); + } + if (path.is_empty() || err != OK || foreground.is_null() || foreground->is_empty()) { print_verbose("- falling back to using the regular icon"); foreground = icon; } @@ -1752,14 +1755,14 @@ void EditorExportPlatformAndroid::load_icon_refs(const Ref & path = static_cast(p_preset->get(LAUNCHER_ADAPTIVE_ICON_BACKGROUND_OPTION)).strip_edges(); if (!path.is_empty()) { print_verbose("Loading adaptive background icon from " + path); - ImageLoader::load_image(path, background); + background = _load_icon_or_splash_image(path, &err); } // Adaptive monochrome: user selection -> default. path = static_cast(p_preset->get(LAUNCHER_ADAPTIVE_ICON_MONOCHROME_OPTION)).strip_edges(); if (!path.is_empty()) { print_verbose("Loading adaptive monochrome icon from " + path); - ImageLoader::load_image(path, monochrome); + monochrome = _load_icon_or_splash_image(path, &err); } } diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index 4f5d2b48ded..ea093061120 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -982,9 +982,9 @@ Error EditorExportPlatformIOS::_export_icons(const Ref &p_pr } // Resize main app icon. icon_path = GLOBAL_GET("application/config/icon"); - Ref img = memnew(Image); - Error err = ImageLoader::load_image(icon_path, img); - if (err != OK) { + Error err = OK; + Ref img = _load_icon_or_splash_image(icon_path, &err); + if (err != OK || img.is_null() || img->is_empty()) { add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path)); return ERR_UNCONFIGURED; } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) { @@ -1003,9 +1003,9 @@ Error EditorExportPlatformIOS::_export_icons(const Ref &p_pr } } else { // Load custom icon and resize if required. - Ref img = memnew(Image); - Error err = ImageLoader::load_image(icon_path, img); - if (err != OK) { + Error err = OK; + Ref img = _load_icon_or_splash_image(icon_path, &err); + if (err != OK || img.is_null() || img->is_empty()) { add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat("Invalid icon (%s): '%s'.", info.preset_key, icon_path)); return ERR_UNCONFIGURED; } else if (info.force_opaque && img->detect_alpha() != Image::ALPHA_NONE) { @@ -1089,13 +1089,11 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Refget("storyboard/custom_image@3x"); if (custom_launch_image_2x.length() > 0 && custom_launch_image_3x.length() > 0) { - Ref image; String image_path = p_dest_dir.path_join("splash@2x.png"); - image.instantiate(); - Error err = ImageLoader::load_image(custom_launch_image_2x, image); + Error err = OK; + Ref image = _load_icon_or_splash_image(custom_launch_image_2x, &err); - if (err) { - image.unref(); + if (err != OK || image.is_null() || image->is_empty()) { return err; } @@ -1103,13 +1101,10 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Refis_empty()) { return err; } @@ -1117,19 +1112,16 @@ Error EditorExportPlatformIOS::_export_loading_screen_file(const Ref splash; const String splash_path = GLOBAL_GET("application/boot_splash/image"); if (!splash_path.is_empty()) { - splash.instantiate(); - const Error err = ImageLoader::load_image(splash_path, splash); - if (err) { - splash.unref(); - } + splash = _load_icon_or_splash_image(splash_path, &err); } - if (splash.is_null()) { + if (err != OK || splash.is_null() || splash->is_empty()) { splash.instantiate(boot_splash_png); } diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 66a7637fd77..140839f1a1a 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -1883,10 +1883,8 @@ Error EditorExportPlatformMacOS::export_project(const Ref &p icon->get_buffer(&data.write[0], icon->get_length()); } } else { - Ref icon; - icon.instantiate(); - err = ImageLoader::load_image(icon_path, icon); - if (err == OK && !icon->is_empty()) { + Ref icon = _load_icon_or_splash_image(icon_path, &err); + if (err == OK && icon.is_valid() && !icon->is_empty()) { _make_icon(p_preset, icon, data); } } diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp index ae936eb937b..8929699d2a6 100644 --- a/platform/web/export/export_plugin.cpp +++ b/platform/web/export/export_plugin.cpp @@ -192,9 +192,9 @@ Error EditorExportPlatformWeb::_add_manifest_icon(const String &p_path, const St Ref icon; if (!p_icon.is_empty()) { - icon.instantiate(); - const Error err = ImageLoader::load_image(p_icon, icon); - if (err != OK) { + Error err = OK; + icon = _load_icon_or_splash_image(p_icon, &err); + if (err != OK || icon.is_null() || icon->is_empty()) { add_message(EXPORT_MESSAGE_ERROR, TTR("Icon Creation"), vformat(TTR("Could not read file: \"%s\"."), p_icon)); return err; } diff --git a/platform/web/export/export_plugin.h b/platform/web/export/export_plugin.h index bd449bb16de..d6de8481a73 100644 --- a/platform/web/export/export_plugin.h +++ b/platform/web/export/export_plugin.h @@ -77,20 +77,28 @@ class EditorExportPlatformWeb : public EditorExportPlatform { } Ref _get_project_icon() const { + Error err = OK; Ref icon; icon.instantiate(); const String icon_path = String(GLOBAL_GET("application/config/icon")).strip_edges(); - if (icon_path.is_empty() || ImageLoader::load_image(icon_path, icon) != OK) { + if (!icon_path.is_empty()) { + icon = _load_icon_or_splash_image(icon_path, &err); + } + if (icon_path.is_empty() || err != OK || icon.is_null() || icon->is_empty()) { return EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("DefaultProjectIcon"), EditorStringName(EditorIcons))->get_image(); } return icon; } Ref _get_project_splash() const { + Error err = OK; Ref splash; splash.instantiate(); const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges(); - if (splash_path.is_empty() || ImageLoader::load_image(splash_path, splash) != OK) { + if (!splash_path.is_empty()) { + splash = _load_icon_or_splash_image(splash_path, &err); + } + if (splash_path.is_empty() || err != OK || splash.is_null() || splash->is_empty()) { return Ref(memnew(Image(boot_splash_png))); } return splash; diff --git a/platform/windows/export/export_plugin.cpp b/platform/windows/export/export_plugin.cpp index 4795d2a9753..4111aac8af7 100644 --- a/platform/windows/export/export_plugin.cpp +++ b/platform/windows/export/export_plugin.cpp @@ -93,10 +93,9 @@ Error EditorExportPlatformWindows::_process_icon(const Ref & f->seek(prev_offset); } } else { - Ref src_image; - src_image.instantiate(); - err = ImageLoader::load_image(p_src_path, src_image); - ERR_FAIL_COND_V(err != OK || src_image->is_empty(), ERR_CANT_OPEN); + Ref src_image = _load_icon_or_splash_image(p_src_path, &err); + ERR_FAIL_COND_V(err != OK || src_image.is_null() || src_image->is_empty(), ERR_CANT_OPEN); + for (size_t i = 0; i < sizeof(icon_size) / sizeof(icon_size[0]); ++i) { int size = (icon_size[i] == 0) ? 256 : icon_size[i];