]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagpng.cpp
Removed two instances of 'template<>' - looks like VC6 did not need it after all...
[wxWidgets.git] / src / common / imagpng.cpp
index 528168a609cf1d23eac9bc8f24bb07c8c3ef21b6..14fd9eddb1bae5669b911390af956e76c83d9942 100644 (file)
@@ -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
@@ -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: