+ wxinfo.verbose = verbose;
+ wxinfo.stream.in = &stream;
+
+ image->Destroy();
+
+ png_structp png_ptr = png_create_read_struct
+ (
+ PNG_LIBPNG_VER_STRING,
+ (voidp) NULL,
+ wx_png_error,
+ wx_png_warning
+ );
+ if (!png_ptr)
+ goto error;
+
+ // NB: please see the comment near wxPNGInfoStruct declaration for
+ // explanation why this line is mandatory
+ png_set_read_fn( png_ptr, &wxinfo, wx_PNG_stream_reader);
+
+ info_ptr = png_create_info_struct( png_ptr );
+ if (!info_ptr)
+ goto error;
+
+ if (setjmp(wxinfo.jmpbuf))
+ goto error;
+
+ png_read_info( png_ptr, info_ptr );
+ png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, (int*) NULL, (int*) NULL );
+
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ png_set_expand( png_ptr );
+
+ // Fix for Bug [ 439207 ] Monochrome PNG images come up black
+ if (bit_depth < 8)
+ png_set_expand( png_ptr );
+
+ png_set_strip_16( png_ptr );
+ png_set_packing( png_ptr );
+ if (png_get_valid( png_ptr, info_ptr, PNG_INFO_tRNS))
+ png_set_expand( png_ptr );
+ png_set_filler( png_ptr, 0xff, PNG_FILLER_AFTER );
+
+ image->Create((int)width, (int)height, (bool) false /* no need to init pixels */);
+
+ if (!image->Ok())
+ goto error;
+
+ lines = (unsigned char **)malloc( (size_t)(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)