#include "png_loader.h" #include "png_driver_common.h" #include "core/os/directory.h" Error PNGLoader::load_image(Ref p_image, const char *f, bool p_force_linear) { return load_image(p_image, String(f), p_force_linear); } Error PNGLoader::save_image(const char *f, const Ref &p_img) { return save_image(String(f), p_img); } // Taken from the Godot Engine (MIT License) // Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. // Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). Error PNGLoader::load_image(Ref p_image, const String &f, bool p_force_linear) { Ref d; d.instance(); Vector file_buffer; d->read_file_into_bin(f, &file_buffer); return PNGDriverCommon::png_to_image(file_buffer.data(), file_buffer.size(), p_force_linear, p_image); } // Taken from the Godot Engine (MIT License) // Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. // Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). Ref PNGLoader::load_mem_png(const uint8_t *p_png, int p_size) { Ref img; img.instance(); // the value of p_force_linear does not matter since it only applies to 16 bit Error err = PNGDriverCommon::png_to_image(p_png, p_size, false, img); ERR_FAIL_COND_V(err, Ref()); return img; } // Taken from the Godot Engine (MIT License) // Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. // Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). Error PNGLoader::save_image(const String &p_path, const Ref &p_img) { Vector buffer; Error err = PNGDriverCommon::image_to_png(p_img, buffer); ERR_FAIL_COND_V_MSG(err, err, "Can't convert image to PNG."); Ref d; d.instance(); err = d->write_file_bin(p_path, buffer); ERR_FAIL_COND_V_MSG(err, err, "Can't save PNG at path: " + p_path); return OK; } // Taken from the Godot Engine (MIT License) // Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. // Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). Vector PNGLoader::save_image_to_buffer(const Ref &p_img) { Vector buffer; Error err = PNGDriverCommon::image_to_png(p_img, buffer); ERR_FAIL_COND_V_MSG(err, Vector(), "Can't convert image to PNG."); return buffer; } PNGLoader::PNGLoader() { }