X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7d7b3f69f2b8ab29b3cb8ceb6e2923018cf96562..51c72a7b56ea50fb3c9b082da1bbaddf6a218073:/src/common/imagpng.cpp diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index 474221ae11..14fd9eddb1 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -165,7 +165,9 @@ PNGLINKAGEMODE wx_png_warning(png_structp png_ptr, png_const_charp message) { wxPNGInfoStruct *info = png_ptr ? WX_PNG_INFO(png_ptr) : NULL; if ( !info || info->verbose ) + { wxLogWarning( wxString::FromAscii(message) ); + } } // from pngerror.c @@ -302,7 +304,7 @@ bool wxPNGHandler::DoCanRead( wxInputStream& stream ) { unsigned char hdr[4]; - if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) + if ( !stream.Read(hdr, WXSIZEOF(hdr)) ) // it's ok to modify the stream position here return false; return memcmp(hdr, "\211PNG", WXSIZEOF(hdr)) == 0; @@ -385,7 +387,7 @@ void CopyDataFromPNG(wxImage *image, // must be opaque then as otherwise we shouldn't be // using the mask at all - wxASSERT_MSG( IsOpaque(a), _T("logic error") ); + wxASSERT_MSG( IsOpaque(a), wxT("logic error") ); // fall through @@ -453,7 +455,7 @@ void CopyDataFromPNG(wxImage *image, { // must be opaque then as otherwise we shouldn't be // using the mask at all - wxASSERT_MSG( IsOpaque(a), _T("logic error") ); + wxASSERT_MSG( IsOpaque(a), wxT("logic error") ); // if we couldn't find a unique colour for the // mask, we can have real pixels with the same @@ -558,18 +560,16 @@ wxPNGHandler::LoadFile(wxImage *image, if (!image->Ok()) goto error; - lines = (unsigned char **)malloc( (size_t)(height * sizeof(unsigned char *)) ); + // initialize all line pointers to NULL to ensure that they can be safely + // free()d if an error occurs before all of them could be allocated + lines = (unsigned char **)calloc(height, sizeof(unsigned char *)); if ( !lines ) goto error; for (i = 0; i < height; i++) { if ((lines[i] = (unsigned char *)malloc( (size_t)(width * (sizeof(unsigned char) * 4)))) == NULL) - { - for ( unsigned int n = 0; n < i; n++ ) - free( lines[n] ); goto error; - } } png_read_image( png_ptr, lines ); @@ -610,7 +610,9 @@ wxPNGHandler::LoadFile(wxImage *image, error: if (verbose) + { wxLogError(_("Couldn't load a PNG image - file is corrupted or not enough memory.")); + } if ( image->Ok() ) { @@ -659,7 +661,9 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos if (!png_ptr) { if (verbose) + { wxLogError(_("Couldn't save PNG image.")); + } return false; } @@ -668,7 +672,9 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos { png_destroy_write_struct( &png_ptr, (png_infopp)NULL ); if (verbose) + { wxLogError(_("Couldn't save PNG image.")); + } return false; } @@ -676,7 +682,9 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos { png_destroy_write_struct( &png_ptr, (png_infopp)NULL ); if (verbose) + { wxLogError(_("Couldn't save PNG image.")); + } return false; } @@ -691,9 +699,6 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos ? image->GetOptionInt(wxIMAGE_OPTION_PNG_BITDEPTH) : 8; - wxASSERT_MSG( iBitDepth == 8 || iBitDepth == 16, - _T("PNG bit depth must be 8 or 16") ); - bool bHasAlpha = image->HasAlpha(); bool bHasMask = image->HasMask(); bool bUseAlpha = bHasAlpha || bHasMask; @@ -776,7 +781,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos break; default: - wxFAIL_MSG( _T("unsupported image resolution units") ); + wxFAIL_MSG( wxT("unsupported image resolution units") ); } if ( resX && resY ) @@ -823,7 +828,7 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos switch ( iColorType ) { default: - wxFAIL_MSG( _T("unknown wxPNG_TYPE_XXX") ); + wxFAIL_MSG( wxT("unknown wxPNG_TYPE_XXX") ); // fall through case wxPNG_TYPE_COLOUR: