From e3df636d826f893d4025c2f09a3d70b38c89b129 Mon Sep 17 00:00:00 2001 From: pavel-t <36256989+pavel-t@users.noreply.github.com> Date: Mon, 23 Jul 2018 08:33:10 +0300 Subject: [PATCH] Make DoLoadPNGFile member function of wxPNGImageData Avoid adding "data." everywhere in DoLoadPNGFile code --- src/common/imagpng.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index 48aee7d5fc..89fee280fe 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -139,6 +139,8 @@ struct wxPNGImageData free( lines ); } + void DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo); + unsigned char** lines; png_uint_32 numLines; bool ok; @@ -299,11 +301,10 @@ void CopyDataFromPNG(wxImage *image, // This function uses wxPNGImageData to store some of its "local" variables in // order to avoid clobbering these variables by longjmp(): having them inside // the stack frame of the caller prevents this from happening. It also -// "returns" its result via "data" parameter: use its "ok" field to check +// "returns" its result via wxPNGImageData: use its "ok" field to check // whether loading succeeded or failed. -static void -DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo, wxPNGImageData& data) +wxPNGImageData::DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo) { // VZ: as this function uses setjmp() the only fool-proof error handling // method is to use goto (setjmp is not really C++ dtors friendly...) @@ -362,10 +363,10 @@ DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo, wxPNGImageData& data) // 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 - if ( !data.Alloc(width, height) ) + if ( !Alloc(width, height) ) goto error; - png_read_image( png_ptr, data.lines ); + png_read_image( png_ptr, lines ); png_read_end( png_ptr, info_ptr ); #if wxUSE_PALETTE @@ -436,10 +437,10 @@ DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo, wxPNGImageData& data) // loaded successfully, now init wxImage with this data - CopyDataFromPNG(image, data.lines, width, height, color_type); + CopyDataFromPNG(image, lines, width, height, color_type); // This will indicate to the caller that loading succeeded. - data.ok = true; + ok = true; error: // Note that we only get here if both png_ptr and info_ptr are valid, @@ -458,7 +459,7 @@ wxPNGHandler::LoadFile(wxImage *image, wxinfo.stream.in = &stream; wxPNGImageData data; - DoLoadPNGFile(image, wxinfo, data); + data.DoLoadPNGFile(image, wxinfo); if ( !data.ok ) {