From 7d4b3e65876af61452a13c23bec1829a0a2de77f Mon Sep 17 00:00:00 2001 From: Paul Herman Date: Thu, 21 May 2020 13:46:44 +0200 Subject: Expose loading TGA images in Image. --- modules/tga/image_loader_tga.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'modules') diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp index ce889a4928..1475d24792 100644 --- a/modules/tga/image_loader_tga.cpp +++ b/modules/tga/image_loader_tga.cpp @@ -30,6 +30,8 @@ #include "image_loader_tga.h" +#include "core/error_macros.h" +#include "core/io/file_access_memory.h" #include "core/os/os.h" #include "core/print_string.h" @@ -311,5 +313,17 @@ void ImageLoaderTGA::get_recognized_extensions(List *p_extensions) const p_extensions->push_back("tga"); } +static Ref _tga_mem_loader_func(const uint8_t *p_png, int p_size) { + FileAccessMemory memfile; + Error open_memfile_error = memfile.open_custom(p_png, p_size); + ERR_FAIL_COND_V_MSG(open_memfile_error, Ref(), "Could not create memfile for TGA image buffer."); + Ref img; + img.instance(); + Error load_error = ImageLoaderTGA().load_image(img, &memfile, false, 1.0f); + ERR_FAIL_COND_V_MSG(load_error, Ref(), "Failed to load TGA image."); + return img; +} + ImageLoaderTGA::ImageLoaderTGA() { + Image::_tga_mem_loader_func = _tga_mem_loader_func; } -- cgit v1.2.3