diff options
Diffstat (limited to 'drivers/png')
-rw-r--r-- | drivers/png/image_loader_png.cpp | 26 | ||||
-rw-r--r-- | drivers/png/image_loader_png.h | 4 | ||||
-rw-r--r-- | drivers/png/png_driver_common.cpp | 20 | ||||
-rw-r--r-- | drivers/png/png_driver_common.h | 3 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.cpp | 12 | ||||
-rw-r--r-- | drivers/png/resource_saver_png.h | 2 |
6 files changed, 33 insertions, 34 deletions
diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index eb7d196e1d..4cb93a821c 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -39,19 +39,19 @@ Error ImageLoaderPNG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { const size_t buffer_size = f->get_len(); - PoolVector<uint8_t> file_buffer; + Vector<uint8_t> file_buffer; Error err = file_buffer.resize(buffer_size); if (err) { f->close(); return err; } { - PoolVector<uint8_t>::Write writer = file_buffer.write(); - f->get_buffer(writer.ptr(), buffer_size); + uint8_t *writer = file_buffer.ptrw(); + f->get_buffer(writer, buffer_size); f->close(); } - PoolVector<uint8_t>::Read reader = file_buffer.read(); - return PNGDriverCommon::png_to_image(reader.ptr(), buffer_size, p_image); + const uint8_t *reader = file_buffer.ptr(); + return PNGDriverCommon::png_to_image(reader, buffer_size, p_image); } void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const { @@ -70,34 +70,34 @@ Ref<Image> ImageLoaderPNG::load_mem_png(const uint8_t *p_png, int p_size) { return img; } -Ref<Image> ImageLoaderPNG::lossless_unpack_png(const PoolVector<uint8_t> &p_data) { +Ref<Image> ImageLoaderPNG::lossless_unpack_png(const Vector<uint8_t> &p_data) { const int len = p_data.size(); ERR_FAIL_COND_V(len < 4, Ref<Image>()); - PoolVector<uint8_t>::Read r = p_data.read(); + const uint8_t *r = p_data.ptr(); ERR_FAIL_COND_V(r[0] != 'P' || r[1] != 'N' || r[2] != 'G' || r[3] != ' ', Ref<Image>()); return load_mem_png(&r[4], len - 4); } -PoolVector<uint8_t> ImageLoaderPNG::lossless_pack_png(const Ref<Image> &p_image) { +Vector<uint8_t> ImageLoaderPNG::lossless_pack_png(const Ref<Image> &p_image) { - PoolVector<uint8_t> out_buffer; + Vector<uint8_t> out_buffer; // add Godot's own "PNG " prefix if (out_buffer.resize(4) != OK) { - ERR_FAIL_V(PoolVector<uint8_t>()); + ERR_FAIL_V(Vector<uint8_t>()); } // scope for writer lifetime { // must be closed before call to image_to_png - PoolVector<uint8_t>::Write writer = out_buffer.write(); - copymem(writer.ptr(), "PNG ", 4); + uint8_t *writer = out_buffer.ptrw(); + copymem(writer, "PNG ", 4); } Error err = PNGDriverCommon::image_to_png(p_image, out_buffer); if (err) { - ERR_FAIL_V(PoolVector<uint8_t>()); + ERR_FAIL_V(Vector<uint8_t>()); } return out_buffer; diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h index 57f8aa314d..0154be0398 100644 --- a/drivers/png/image_loader_png.h +++ b/drivers/png/image_loader_png.h @@ -35,8 +35,8 @@ class ImageLoaderPNG : public ImageFormatLoader { private: - static PoolVector<uint8_t> lossless_pack_png(const Ref<Image> &p_image); - static Ref<Image> lossless_unpack_png(const PoolVector<uint8_t> &p_data); + static Vector<uint8_t> lossless_pack_png(const Ref<Image> &p_image); + static Ref<Image> lossless_unpack_png(const Vector<uint8_t> &p_data); static Ref<Image> load_mem_png(const uint8_t *p_png, int p_size); public: diff --git a/drivers/png/png_driver_common.cpp b/drivers/png/png_driver_common.cpp index 750d00eb59..efd488fd5c 100644 --- a/drivers/png/png_driver_common.cpp +++ b/drivers/png/png_driver_common.cpp @@ -101,16 +101,16 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) { } const png_uint_32 stride = PNG_IMAGE_ROW_STRIDE(png_img); - PoolVector<uint8_t> buffer; + Vector<uint8_t> buffer; Error err = buffer.resize(PNG_IMAGE_BUFFER_SIZE(png_img, stride)); if (err) { png_image_free(&png_img); // only required when we return before finish_read return err; } - PoolVector<uint8_t>::Write writer = buffer.write(); + uint8_t *writer = buffer.ptrw(); // read image data to buffer and release libpng resources - success = png_image_finish_read(&png_img, NULL, writer.ptr(), stride, NULL); + success = png_image_finish_read(&png_img, NULL, writer, stride, NULL); ERR_FAIL_COND_V_MSG(check_error(png_img), ERR_FILE_CORRUPT, png_img.message); ERR_FAIL_COND_V(!success, ERR_FILE_CORRUPT); @@ -120,7 +120,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image) { return OK; } -Error image_to_png(const Ref<Image> &p_image, PoolVector<uint8_t> &p_buffer) { +Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer) { Ref<Image> source_image = p_image->duplicate(); @@ -158,8 +158,8 @@ Error image_to_png(const Ref<Image> &p_image, PoolVector<uint8_t> &p_buffer) { } } - const PoolVector<uint8_t> image_data = source_image->get_data(); - const PoolVector<uint8_t>::Read reader = image_data.read(); + const Vector<uint8_t> image_data = source_image->get_data(); + const uint8_t *reader = image_data.ptr(); // we may be passed a buffer with existing content we're expected to append to const int buffer_offset = p_buffer.size(); @@ -173,9 +173,9 @@ Error image_to_png(const Ref<Image> &p_image, PoolVector<uint8_t> &p_buffer) { Error err = p_buffer.resize(buffer_offset + png_size_estimate); ERR_FAIL_COND_V(err, err); - PoolVector<uint8_t>::Write writer = p_buffer.write(); + uint8_t *writer = p_buffer.ptrw(); success = png_image_write_to_memory(&png_img, &writer[buffer_offset], - &compressed_size, 0, reader.ptr(), 0, NULL); + &compressed_size, 0, reader, 0, NULL); ERR_FAIL_COND_V_MSG(check_error(png_img), FAILED, png_img.message); } if (!success) { @@ -187,9 +187,9 @@ Error image_to_png(const Ref<Image> &p_image, PoolVector<uint8_t> &p_buffer) { Error err = p_buffer.resize(buffer_offset + compressed_size); ERR_FAIL_COND_V(err, err); - PoolVector<uint8_t>::Write writer = p_buffer.write(); + uint8_t *writer = p_buffer.ptrw(); success = png_image_write_to_memory(&png_img, &writer[buffer_offset], - &compressed_size, 0, reader.ptr(), 0, NULL); + &compressed_size, 0, reader, 0, NULL); ERR_FAIL_COND_V_MSG(check_error(png_img), FAILED, png_img.message); ERR_FAIL_COND_V(!success, FAILED); } diff --git a/drivers/png/png_driver_common.h b/drivers/png/png_driver_common.h index ee1d32ce68..12129f034e 100644 --- a/drivers/png/png_driver_common.h +++ b/drivers/png/png_driver_common.h @@ -32,7 +32,6 @@ #define PNG_DRIVER_COMMON_H #include "core/image.h" -#include "core/pool_vector.h" namespace PNGDriverCommon { @@ -41,7 +40,7 @@ Error png_to_image(const uint8_t *p_source, size_t p_size, Ref<Image> p_image); // Append p_image, as a png, to p_buffer. // Contents of p_buffer is unspecified if error returned. -Error image_to_png(const Ref<Image> &p_image, PoolVector<uint8_t> &p_buffer); +Error image_to_png(const Ref<Image> &p_image, Vector<uint8_t> &p_buffer); } // namespace PNGDriverCommon diff --git a/drivers/png/resource_saver_png.cpp b/drivers/png/resource_saver_png.cpp index 566bfbcc1d..2380c2685f 100644 --- a/drivers/png/resource_saver_png.cpp +++ b/drivers/png/resource_saver_png.cpp @@ -51,15 +51,15 @@ Error ResourceSaverPNG::save(const String &p_path, const RES &p_resource, uint32 Error ResourceSaverPNG::save_image(const String &p_path, const Ref<Image> &p_img) { - PoolVector<uint8_t> buffer; + Vector<uint8_t> buffer; Error err = PNGDriverCommon::image_to_png(p_img, buffer); ERR_FAIL_COND_V_MSG(err, err, "Can't convert image to PNG."); FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); ERR_FAIL_COND_V_MSG(err, err, vformat("Can't save PNG at path: '%s'.", p_path)); - PoolVector<uint8_t>::Read reader = buffer.read(); + const uint8_t *reader = buffer.ptr(); - file->store_buffer(reader.ptr(), buffer.size()); + file->store_buffer(reader, buffer.size()); if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) { memdelete(file); return ERR_CANT_CREATE; @@ -71,11 +71,11 @@ 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) { +Vector<uint8_t> ResourceSaverPNG::save_image_to_buffer(const Ref<Image> &p_img) { - PoolVector<uint8_t> buffer; + Vector<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."); + ERR_FAIL_COND_V_MSG(err, Vector<uint8_t>(), "Can't convert image to PNG."); return buffer; } diff --git a/drivers/png/resource_saver_png.h b/drivers/png/resource_saver_png.h index 2cac20991a..c32b383521 100644 --- a/drivers/png/resource_saver_png.h +++ b/drivers/png/resource_saver_png.h @@ -37,7 +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); + static Vector<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; |