optimize decompress jpg data and fix warnings

This commit is contained in:
Eric Zhong 2014-09-16 21:55:05 +08:00
parent 8de3657f3c
commit ae5f6e63e5
1 changed files with 6 additions and 15 deletions

View File

@ -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 */ /* libjpeg data structure for storing one row, that is, scanline of an image */
JSAMPROW row_pointer[1] = {0}; JSAMPROW row_pointer[1] = {0};
unsigned long location = 0; unsigned long location = 0;
unsigned int i = 0;
bool ret = false; bool ret = false;
do do
@ -885,8 +884,6 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
_width = cinfo.output_width; _width = cinfo.output_width;
_height = cinfo.output_height; _height = cinfo.output_height;
_hasPremultipliedAlpha = false; _hasPremultipliedAlpha = false;
//row_pointer[0] = static_cast<unsigned char*>(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; _dataLen = cinfo.output_width*cinfo.output_height*cinfo.output_components;
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char))); _data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
@ -901,23 +898,17 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
jpeg_read_scanlines(&cinfo, row_pointer, 1); 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
/* When read image file with broken data, jpeg_finish_decompress() may cause error. * with the decompression object.
* Besides, jpeg_destroy_decompress() shall deallocate and release all memory associated * So it doesn't need to call jpeg_finish_decompress().
* with the decompression object. */
* So it doesn't need to call jpeg_finish_decompress(). //jpeg_finish_decompress( &cinfo );
*/
//jpeg_finish_decompress( &cinfo );
jpeg_destroy_decompress( &cinfo ); jpeg_destroy_decompress( &cinfo );
/* wrap up decompression, destroy objects, free pointers and close open files */ /* wrap up decompression, destroy objects, free pointers and close open files */
ret = true; ret = true;
} while (0); } while (0);
if (row_pointer[0] != nullptr)
{
free(row_pointer[0]);
};
return ret; return ret;
#else #else
return false; return false;