diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-11-07 16:38:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-07 16:38:09 +0100 |
commit | 329d2c1ced685a107b1c27e67b212b5620968a0a (patch) | |
tree | a737d8af45d01138c8b21ccb20c230614deade35 /modules/bmp/image_loader_bmp.cpp | |
parent | df6fa6c306409b28385e40c945fe7d5f201a3fd2 (diff) | |
parent | 0209e3790e4ab984b811f2994947ae71eef69b82 (diff) |
Merge pull request #42947 from Calinou/image-load-bmp-from-buffer
Add `Image.load_bmp_from_buffer()` for run-time BMP image loading
Diffstat (limited to 'modules/bmp/image_loader_bmp.cpp')
-rw-r--r-- | modules/bmp/image_loader_bmp.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 757afeb9e3..b08970d110 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -30,6 +30,8 @@ #include "image_loader_bmp.h" +#include "core/io/file_access_memory.h" + Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const uint8_t *p_color_buffer, @@ -293,9 +295,21 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f, return err; } -void ImageLoaderBMP::get_recognized_extensions( - List<String> *p_extensions) const { +void ImageLoaderBMP::get_recognized_extensions(List<String> *p_extensions) const { p_extensions->push_back("bmp"); } -ImageLoaderBMP::ImageLoaderBMP() {} +static Ref<Image> _bmp_mem_loader_func(const uint8_t *p_bmp, int p_size) { + FileAccessMemory memfile; + Error open_memfile_error = memfile.open_custom(p_bmp, p_size); + ERR_FAIL_COND_V_MSG(open_memfile_error, Ref<Image>(), "Could not create memfile for BMP image buffer."); + Ref<Image> img; + img.instance(); + Error load_error = ImageLoaderBMP().load_image(img, &memfile, false, 1.0f); + ERR_FAIL_COND_V_MSG(load_error, Ref<Image>(), "Failed to load BMP image."); + return img; +} + +ImageLoaderBMP::ImageLoaderBMP() { + Image::_bmp_mem_loader_func = _bmp_mem_loader_func; +} |