[Core] Make ImageFormatLoader extensible.
This commit is contained in:
@@ -142,7 +142,7 @@ void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const
|
||||
p_extensions->push_back("svg");
|
||||
}
|
||||
|
||||
Error ImageLoaderSVG::load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, uint32_t p_flags, float p_scale) {
|
||||
Error ImageLoaderSVG::load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) {
|
||||
String svg = p_fileaccess->get_as_utf8_string();
|
||||
|
||||
if (p_flags & FLAG_CONVERT_COLORS) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
void create_image_from_string(Ref<Image> p_image, String p_string, float p_scale, bool p_upsample, const HashMap<Color, Color> &p_color_map);
|
||||
|
||||
virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, uint32_t p_flags, float p_scale) override;
|
||||
virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) override;
|
||||
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include <thorvg.h>
|
||||
|
||||
static ImageLoaderSVG *image_loader_svg = nullptr;
|
||||
static Ref<ImageLoaderSVG> image_loader_svg;
|
||||
|
||||
void initialize_svg_module(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
@@ -45,7 +45,8 @@ void initialize_svg_module(ModuleInitializationLevel p_level) {
|
||||
if (tvg::Initializer::init(tvgEngine, 1) != tvg::Result::Success) {
|
||||
return;
|
||||
}
|
||||
image_loader_svg = memnew(ImageLoaderSVG);
|
||||
|
||||
image_loader_svg.instantiate();
|
||||
ImageLoader::add_image_format_loader(image_loader_svg);
|
||||
}
|
||||
|
||||
@@ -54,9 +55,12 @@ void uninitialize_svg_module(ModuleInitializationLevel p_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!image_loader_svg) {
|
||||
if (image_loader_svg.is_null()) {
|
||||
// It failed to initialize so it was not added.
|
||||
return;
|
||||
}
|
||||
memdelete(image_loader_svg);
|
||||
|
||||
ImageLoader::remove_image_format_loader(image_loader_svg);
|
||||
image_loader_svg.unref();
|
||||
tvg::Initializer::term(tvg::CanvasEngine::Sw);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user