diff options
Diffstat (limited to 'drivers/png')
-rw-r--r-- | drivers/png/png_driver_common.cpp | 1 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.cpp | 9 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.h | 1 |
3 files changed, 11 insertions, 0 deletions
diff --git a/drivers/png/png_driver_common.cpp b/drivers/png/png_driver_common.cpp index f4dbf135bb..750d00eb59 100644 --- a/drivers/png/png_driver_common.cpp +++ b/drivers/png/png_driver_common.cpp @@ -114,6 +114,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) { ERR_FAIL_COND_V_MSG(check_error(png_img), ERR_FILE_CORRUPT, png_img.message); ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT); + //print_line("png width: "+itos(png_img.width)+" height: "+itos(png_img.height)); p_image->create(png_img.width, png_img.height, 0, dest_format, buffer); return OK; diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index b15a84d3b9..566bfbcc1d 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -71,6 +71,14 @@ Error ResourceSaverPNG::save_image(const String &p_path, const Ref<Image> &p_img return OK; } +PoolVector<uint8_t> ResourceSaverPNG::save_image_to_buffer(const Ref<Image> &p_img) { + + PoolVector<uint8_t> buffer; + Error err = PNGDriverCommon::image_to_png(p_img, buffer); + ERR_FAIL_COND_V_MSG(err, PoolVector<uint8_t>(), "Can't convert image to PNG."); + return buffer; +} + bool ResourceSaverPNG::recognize(const RES &p_resource) const { return (p_resource.is_valid() && p_resource->is_class("ImageTexture")); @@ -86,4 +94,5 @@ void ResourceSaverPNG::get_recognized_extensions(const RES &p_resource, List<Str ResourceSaverPNG::ResourceSaverPNG() { Image::save_png_func = &save_image; + Image::save_png_buffer_func = &save_image_to_buffer; }; diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h index 6eb1db2004..2cac20991a 100644 --- a/drivers/png/resource_saver_png.h +++ b/drivers/png/resource_saver_png.h @@ -37,6 +37,7 @@ class ResourceSaverPNG : public ResourceFormatSaver { public: static Error save_image(const String &p_path, const Ref<Image> &p_img); + static PoolVector<uint8_t> save_image_to_buffer(const Ref<Image> &p_img); virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); virtual bool recognize(const RES &p_resource) const; |