| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/core_bind.h" |
| 34 |
#include "core/io/file_access.h" |
| 35 |
#include "core/io/image.h" |
| 36 |
#include "core/io/resource_loader.h" |
| 37 |
#include "core/object/gdvirtual.gen.inc" |
| 38 |
#include "core/string/ustring.h" |
| 39 |
#include "core/templates/list.h" |
| 40 |
#include "core/variant/binder_common.h" |
| 41 |
|
| 42 |
class ImageLoader; |
| 43 |
|
| 44 |
class ImageFormatLoader : public RefCounted { |
| 45 |
GDCLASS(ImageFormatLoader, RefCounted); |
| 46 |
|
| 47 |
friend class ImageLoader; |
| 48 |
friend class ResourceFormatLoaderImage; |
| 49 |
|
| 50 |
public: |
| 51 |
enum LoaderFlags { |
| 52 |
FLAG_NONE = 0, |
| 53 |
FLAG_FORCE_LINEAR = 1, |
| 54 |
FLAG_CONVERT_COLORS = 2, |
| 55 |
}; |
| 56 |
|
| 57 |
protected: |
| 58 |
static void _bind_methods(); |
| 59 |
|
| 60 |
virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags = FLAG_NONE, float p_scale = 1.0) = 0; |
| 61 |
virtual void get_recognized_extensions(List<String> *p_extensions) const = 0; |
| 62 |
bool recognize(const String &p_extension) const; |
| 63 |
|
| 64 |
public: |
| 65 |
virtual ~ImageFormatLoader() {} |
| 66 |
}; |
| 67 |
|
| 68 |
VARIANT_BITFIELD_CAST(ImageFormatLoader::LoaderFlags); |
| 69 |
|
| 70 |
class ImageFormatLoaderExtension : public ImageFormatLoader { |
| 71 |
GDCLASS(ImageFormatLoaderExtension, ImageFormatLoader); |
| 72 |
|
| 73 |
protected: |
| 74 |
static void _bind_methods(); |
| 75 |
|
| 76 |
public: |
| 77 |
virtual Error load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags = FLAG_NONE, float p_scale = 1.0) override; |
| 78 |
virtual void get_recognized_extensions(List<String> *p_extensions) const override; |
| 79 |
|
| 80 |
void add_format_loader(); |
| 81 |
void remove_format_loader(); |
| 82 |
|
| 83 |
GDVIRTUAL0RC(PackedStringArray, _get_recognized_extensions); |
| 84 |
GDVIRTUAL4R(Error, _load_image, Ref<Image>, Ref<FileAccess>, BitField<ImageFormatLoader::LoaderFlags>, float); |
| 85 |
}; |
| 86 |
|
| 87 |
class ImageLoader { |
| 88 |
static inline Vector<Ref<ImageFormatLoader>> loader; |
| 89 |
friend class ResourceFormatLoaderImage; |
| 90 |
|
| 91 |
protected: |
| 92 |
public: |
| 93 |
static Error load_image(const String &p_file, Ref<Image> p_image, Ref<FileAccess> p_custom = Ref<FileAccess>(), BitField<ImageFormatLoader::LoaderFlags> p_flags = ImageFormatLoader::FLAG_NONE, float p_scale = 1.0); |
| 94 |
static void get_recognized_extensions(List<String> *p_extensions); |
| 95 |
static Ref<ImageFormatLoader> recognize(const String &p_extension); |
| 96 |
|
| 97 |
static void add_image_format_loader(Ref<ImageFormatLoader> p_loader); |
| 98 |
static void remove_image_format_loader(Ref<ImageFormatLoader> p_loader); |
| 99 |
|
| 100 |
static void cleanup(); |
| 101 |
}; |
| 102 |
|
| 103 |
class ResourceFormatLoaderImage : public ResourceFormatLoader { |
| 104 |
GDSOFTCLASS(ResourceFormatLoaderImage, ResourceFormatLoader); |
| 105 |
|
| 106 |
public: |
| 107 |
virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override; |
| 108 |
virtual void get_recognized_extensions(List<String> *p_extensions) const override; |
| 109 |
virtual bool handles_type(const String &p_type) const override; |
| 110 |
virtual String get_resource_type(const String &p_path) const override; |
| 111 |
}; |