Simplify wxGIFHandler::LoadFile().

Don't use heap-allocated wxGIFDecoder when a stack-allocated object would do
just as well.

Don't handle errors different from the defined wxGIF_XXX constants: they can
never happen because LoadGIF() has no way of returning them.

Don't check for "ok" variable being false when it was set to true and never
changed until this check.
This commit is contained in:
Vadim Zeitlin
2015-05-24 01:50:08 +02:00
parent 5e42de8062
commit 982ebc8741

View File

@@ -117,53 +117,31 @@ static bool wxGIFHandler_BufferedOutput(wxOutputStream *, wxUint8 *buf, int c);
bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream, bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
bool verbose, int index) bool verbose, int index)
{ {
wxGIFDecoder *decod; wxGIFDecoder decod;
wxGIFErrorCode error; switch ( decod.LoadGIF(stream) )
bool ok = true;
// image->Destroy();
decod = new wxGIFDecoder();
error = decod->LoadGIF(stream);
if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
{ {
if (verbose) case wxGIF_OK:
{ break;
switch (error)
{ case wxGIF_INVFORMAT:
case wxGIF_INVFORMAT: if ( verbose )
wxLogError(_("GIF: error in GIF image format.")); wxLogError(_("GIF: error in GIF image format."));
break; return false;
case wxGIF_MEMERR:
wxLogError(_("GIF: not enough memory.")); case wxGIF_MEMERR:
break; if ( verbose )
default: wxLogError(_("GIF: not enough memory."));
wxLogError(_("GIF: unknown error!!!")); return false;
break;
} case wxGIF_TRUNCATED:
} if ( verbose )
delete decod; wxLogError(_("GIF: data stream seems to be truncated."));
return false;
// go on; image data is OK
break;
} }
if ((error == wxGIF_TRUNCATED) && verbose) return decod.ConvertToImage(index != -1 ? (size_t)index : 0, image);
{
wxLogError(_("GIF: data stream seems to be truncated."));
// go on; image data is OK
}
if (ok)
{
ok = decod->ConvertToImage(index != -1 ? (size_t)index : 0, image);
}
else
{
wxLogError(_("GIF: Invalid gif index."));
}
delete decod;
return ok;
} }
bool wxGIFHandler::SaveFile(wxImage *image, bool wxGIFHandler::SaveFile(wxImage *image,