Make DoLoadPNGFile member function of wxPNGImageData

Avoid adding "data." everywhere in DoLoadPNGFile code
This commit is contained in:
pavel-t
2018-07-23 08:33:10 +03:00
parent e24e9323e0
commit e3df636d82

View File

@@ -139,6 +139,8 @@ struct wxPNGImageData
free( lines ); free( lines );
} }
void DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo);
unsigned char** lines; unsigned char** lines;
png_uint_32 numLines; png_uint_32 numLines;
bool ok; bool ok;
@@ -299,11 +301,10 @@ void CopyDataFromPNG(wxImage *image,
// This function uses wxPNGImageData to store some of its "local" variables in // This function uses wxPNGImageData to store some of its "local" variables in
// order to avoid clobbering these variables by longjmp(): having them inside // order to avoid clobbering these variables by longjmp(): having them inside
// the stack frame of the caller prevents this from happening. It also // 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. // whether loading succeeded or failed.
static
void 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 // VZ: as this function uses setjmp() the only fool-proof error handling
// method is to use goto (setjmp is not really C++ dtors friendly...) // 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 // 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 // free()d if an error occurs before all of them could be allocated
if ( !data.Alloc(width, height) ) if ( !Alloc(width, height) )
goto error; goto error;
png_read_image( png_ptr, data.lines ); png_read_image( png_ptr, lines );
png_read_end( png_ptr, info_ptr ); png_read_end( png_ptr, info_ptr );
#if wxUSE_PALETTE #if wxUSE_PALETTE
@@ -436,10 +437,10 @@ DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo, wxPNGImageData& data)
// loaded successfully, now init wxImage with this 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. // This will indicate to the caller that loading succeeded.
data.ok = true; ok = true;
error: error:
// Note that we only get here if both png_ptr and info_ptr are valid, // 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; wxinfo.stream.in = &stream;
wxPNGImageData data; wxPNGImageData data;
DoLoadPNGFile(image, wxinfo, data); data.DoLoadPNGFile(image, wxinfo);
if ( !data.ok ) if ( !data.ok )
{ {