1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-25 15:37:42 +00:00

Add Image.load_exr_from_buffer and enable tinyexr by default

This commit is contained in:
metamuffin
2025-01-08 00:40:08 +01:00
parent b79fe2e020
commit 6145b0ca29
8 changed files with 52 additions and 4 deletions

View File

@@ -34,6 +34,8 @@
#include "thirdparty/tinyexr/tinyexr.h"
#include "core/io/file_access_memory.h"
Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, Ref<FileAccess> f, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) {
Vector<uint8_t> src_image;
uint64_t src_image_len = f->get_length();
@@ -291,5 +293,19 @@ void ImageLoaderTinyEXR::get_recognized_extensions(List<String> *p_extensions) c
p_extensions->push_back("exr");
}
ImageLoaderTinyEXR::ImageLoaderTinyEXR() {
static Ref<Image> _tinyexr_mem_loader_func(const uint8_t *p_exr, int p_size) {
Ref<FileAccessMemory> memfile;
memfile.instantiate();
Error open_memfile_error = memfile->open_custom(p_exr, p_size);
ERR_FAIL_COND_V_MSG(open_memfile_error, Ref<Image>(), "Could not create memfile for EXR image buffer.");
Ref<Image> img;
img.instantiate();
Error load_error = ImageLoaderTinyEXR().load_image(img, memfile, false, 1.0f);
ERR_FAIL_COND_V_MSG(load_error, Ref<Image>(), "Failed to load EXR image.");
return img;
}
ImageLoaderTinyEXR::ImageLoaderTinyEXR() {
Image::_exr_mem_loader_func = _tinyexr_mem_loader_func;
}