Update CCImage.cpp

This commit is contained in:
Anton Sokolchenko 2014-04-13 01:13:58 +03:00
parent a9ccb812ed
commit 65cf2e1256
1 changed files with 13 additions and 10 deletions

View File

@ -804,14 +804,7 @@ bool Image::initWithJpgData(const unsigned char * data, ssize_t dataLen)
_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)));
if(!_data) CC_BREAK_IF(! _data);
{
if (row_pointers != nullptr)
{
free(row_pointers);
}
break;
}
/* now actually read the jpeg into the raw buffer */ /* now actually read the jpeg into the raw buffer */
/* read one scan line at a time */ /* read one scan line at a time */
@ -949,7 +942,14 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
_dataLen = rowbytes * _height; _dataLen = rowbytes * _height;
_data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char))); _data = static_cast<unsigned char*>(malloc(_dataLen * sizeof(unsigned char)));
CC_BREAK_IF(!_data); if(!_data)
{
if (row_pointers != nullptr)
{
free(row_pointers);
}
break;
}
for (unsigned short i = 0; i < _height; ++i) for (unsigned short i = 0; i < _height; ++i)
{ {
@ -964,7 +964,7 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen)
if (row_pointers != nullptr) if (row_pointers != nullptr)
{ {
free(row_pointers); free(row_pointers);
}; }
bRet = true; bRet = true;
} while (0); } while (0);
@ -2035,6 +2035,9 @@ bool Image::saveImageToPNG(const std::string& filePath, bool isToRGB)
{ {
fclose(fp); fclose(fp);
png_destroy_write_struct(&png_ptr, &info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr);
free(row_pointers);
row_pointers = nullptr;
break; break;
} }