From ae5f6e63e57c9d956bd62ab16e05354e79d6b7a4 Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Tue, 16 Sep 2014 21:55:05 +0800 Subject: [PATCH] optimize decompress jpg data and fix warnings --- cocos/platform/CCImage.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 40f3247d65..18f99e5f7c 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -835,7 +835,6 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) /* libjpeg data structure for storing one row, that is, scanline of an image */ JSAMPROW row_pointer[1] = {0}; unsigned long location = 0; - unsigned int i = 0; bool ret = false; do @@ -885,8 +884,6 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) _width = cinfo.output_width; _height = cinfo.output_height; _hasPremultipliedAlpha = false; - //row_pointer[0] = static_cast(malloc(cinfo.output_width*cinfo.output_components * sizeof(unsigned char))); - //CC_BREAK_IF(! row_pointer[0]); _dataLen = cinfo.output_width*cinfo.output_height*cinfo.output_components; _data = static_cast(malloc(_dataLen * sizeof(unsigned char))); @@ -900,24 +897,18 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen) location += cinfo.output_width*cinfo.output_components; jpeg_read_scanlines(&cinfo, row_pointer, 1); } - - row_pointer[0] = nullptr; - /* When read image file with broken data, jpeg_finish_decompress() may cause error. - * Besides, jpeg_destroy_decompress() shall deallocate and release all memory associated - * with the decompression object. - * So it doesn't need to call jpeg_finish_decompress(). - */ - //jpeg_finish_decompress( &cinfo ); + /* When read image file with broken data, jpeg_finish_decompress() may cause error. + * Besides, jpeg_destroy_decompress() shall deallocate and release all memory associated + * with the decompression object. + * So it doesn't need to call jpeg_finish_decompress(). + */ + //jpeg_finish_decompress( &cinfo ); jpeg_destroy_decompress( &cinfo ); /* wrap up decompression, destroy objects, free pointers and close open files */ ret = true; } while (0); - if (row_pointer[0] != nullptr) - { - free(row_pointer[0]); - }; return ret; #else return false;