- png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
- if (!png_ptr)
- {
- return FALSE;
- }
-
- png_infop info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL)
- {
- png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
- return FALSE;
- }
-
- if (setjmp(png_ptr->jmpbuf))
- {
- png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
- return FALSE;
- }
-
- png_set_write_fn( png_ptr, &stream, _PNG_stream_writer, NULL);
-
- png_set_IHDR( png_ptr, info_ptr, image->GetWidth(), image->GetHeight(), 8,
- PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
-
- png_color_8 sig_bit;
- sig_bit.red = 8;
- sig_bit.green = 8;
- sig_bit.blue = 8;
- sig_bit.alpha = 8;
- png_set_sBIT( png_ptr, info_ptr, &sig_bit );
- png_write_info( png_ptr, info_ptr );
- png_set_shift( png_ptr, &sig_bit );
- png_set_packing( png_ptr );
-
- unsigned char *data = (unsigned char *)malloc( image->GetWidth()*4 );
- if (!data)
- {
- png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
- return FALSE;
- }
-
- for (int y = 0; y < image->GetHeight(); y++)
+ if (verbose)
+ wxLogError(_("Couldn't save PNG image."));
+ return FALSE;
+ }
+
+ png_set_error_fn(png_ptr, (png_voidp)NULL, wx_png_error, wx_png_warning);
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL)
+ {
+ png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
+ if (verbose)
+ wxLogError(_("Couldn't save PNG image."));
+ return FALSE;
+ }
+
+ if (setjmp(wxinfo.jmpbuf))
+ {
+ png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
+ if (verbose)
+ wxLogError(_("Couldn't save PNG image."));
+ return FALSE;
+ }
+
+ // NB: please see the comment near wxPNGInfoStruct declaration for
+ // explanation why this line is mandatory
+ png_set_write_fn( png_ptr, &wxinfo, _PNG_stream_writer, NULL);
+
+ png_set_IHDR( png_ptr, info_ptr, image->GetWidth(), image->GetHeight(), 8,
+ PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+ png_color_8 sig_bit;
+ sig_bit.red = 8;
+ sig_bit.green = 8;
+ sig_bit.blue = 8;
+ sig_bit.alpha = 8;
+ png_set_sBIT( png_ptr, info_ptr, &sig_bit );
+ png_write_info( png_ptr, info_ptr );
+ png_set_shift( png_ptr, &sig_bit );
+ png_set_packing( png_ptr );
+
+ unsigned char *data = (unsigned char *)malloc( image->GetWidth()*4 );
+ if (!data)
+ {
+ png_destroy_write_struct( &png_ptr, (png_infopp)NULL );
+ return FALSE;
+ }
+
+ for (int y = 0; y < image->GetHeight(); y++)
+ {
+ unsigned char *ptr = image->GetData() + (y * image->GetWidth() * 3);
+ for (int x = 0; x < image->GetWidth(); x++)