diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-06-06 11:09:00 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-06-06 11:09:00 -0300 |
commit | 954256268afe89b648d356ee0b296a9e97a07373 (patch) | |
tree | 36c42fb01f05d26bbae438d470676c9487b47a04 /drivers | |
parent | 0e1510214a7585d5446f06344468ab52298cfa81 (diff) | |
parent | ab99671bb835a5fe24a092ec34afe1ad862ac254 (diff) |
Merge branch 'master' of https://github.com/okamstudio/godot
Conflicts:
demos/2d/motion/engine.cfg
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/png/image_loader_png.cpp | 22 | ||||
-rw-r--r-- | drivers/png/image_loader_png.h | 3 |
2 files changed, 21 insertions, 4 deletions
diff --git a/drivers/png/image_loader_png.cpp b/drivers/png/image_loader_png.cpp index 2e1488ff9d..2a4720b07b 100644 --- a/drivers/png/image_loader_png.cpp +++ b/drivers/png/image_loader_png.cpp @@ -31,6 +31,8 @@ #include "print_string.h" #include "os/os.h" + + void ImageLoaderPNG::_read_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length) { FileAccess *f = (FileAccess*)png_get_io_ptr(png_ptr); @@ -253,6 +255,7 @@ void ImageLoaderPNG::get_recognized_extensions(List<String> *p_extensions) const struct PNGReadStatus { int offset; + int size; const unsigned char *image; }; @@ -261,17 +264,26 @@ static void user_read_data(png_structp png_ptr,png_bytep data, png_size_t p_leng PNGReadStatus *rstatus; rstatus=(PNGReadStatus*)png_get_io_ptr(png_ptr); - memcpy(data,&rstatus->image[rstatus->offset],p_length); - rstatus->offset+=p_length; + int to_read=p_length; + if (rstatus->size>=0) { + to_read = MIN( p_length, rstatus->size - rstatus->offset); + } + memcpy(data,&rstatus->image[rstatus->offset],to_read); + rstatus->offset+=to_read; + + if (to_read<p_length) { + memset(&data[to_read],0,p_length-to_read); + } } -static Image _load_mem_png(const uint8_t* p_png) { +static Image _load_mem_png(const uint8_t* p_png,int p_size) { PNGReadStatus prs; prs.image=p_png; prs.offset=0; + prs.size=p_size; Image img; Error err = ImageLoaderPNG::_load_image(&prs,user_read_data,&img); @@ -283,9 +295,10 @@ static Image _load_mem_png(const uint8_t* p_png) { static Image _lossless_unpack_png(const DVector<uint8_t>& p_data) { + int len = p_data.size(); DVector<uint8_t>::Read r = p_data.read(); ERR_FAIL_COND_V(r[0]!='P' || r[1]!='N' || r[2]!='G' || r[3]!=' ',Image()); - return _load_mem_png(&r[4]); + return _load_mem_png(&r[4],len-4); } @@ -424,6 +437,7 @@ static DVector<uint8_t> _lossless_pack_png(const Image& p_image) { ImageLoaderPNG::ImageLoaderPNG() { + Image::_png_mem_loader_func=_load_mem_png; Image::lossless_unpacker=_lossless_unpack_png; Image::lossless_packer=_lossless_pack_png; diff --git a/drivers/png/image_loader_png.h b/drivers/png/image_loader_png.h index 7acfd041ee..8413a7eae1 100644 --- a/drivers/png/image_loader_png.h +++ b/drivers/png/image_loader_png.h @@ -40,7 +40,10 @@ class ImageLoaderPNG : public ImageFormatLoader { static void _read_png_data(png_structp png_ptr,png_bytep data, png_size_t p_length); + public: + + static Error _load_image(void *rf_up,png_rw_ptr p_func,Image *p_image); virtual Error load_image(Image *p_image,FileAccess *f); virtual void get_recognized_extensions(List<String> *p_extensions) const; |