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:
parent
5e42de8062
commit
982ebc8741
@ -117,53 +117,31 @@ static bool wxGIFHandler_BufferedOutput(wxOutputStream *, wxUint8 *buf, int c);
|
||||
bool wxGIFHandler::LoadFile(wxImage *image, wxInputStream& stream,
|
||||
bool verbose, int index)
|
||||
{
|
||||
wxGIFDecoder *decod;
|
||||
wxGIFErrorCode error;
|
||||
bool ok = true;
|
||||
|
||||
// image->Destroy();
|
||||
decod = new wxGIFDecoder();
|
||||
error = decod->LoadGIF(stream);
|
||||
|
||||
if ((error != wxGIF_OK) && (error != wxGIF_TRUNCATED))
|
||||
wxGIFDecoder decod;
|
||||
switch ( decod.LoadGIF(stream) )
|
||||
{
|
||||
if (verbose)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case wxGIF_INVFORMAT:
|
||||
wxLogError(_("GIF: error in GIF image format."));
|
||||
break;
|
||||
case wxGIF_MEMERR:
|
||||
wxLogError(_("GIF: not enough memory."));
|
||||
break;
|
||||
default:
|
||||
wxLogError(_("GIF: unknown error!!!"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete decod;
|
||||
return false;
|
||||
case wxGIF_OK:
|
||||
break;
|
||||
|
||||
case wxGIF_INVFORMAT:
|
||||
if ( verbose )
|
||||
wxLogError(_("GIF: error in GIF image format."));
|
||||
return false;
|
||||
|
||||
case wxGIF_MEMERR:
|
||||
if ( verbose )
|
||||
wxLogError(_("GIF: not enough memory."));
|
||||
return false;
|
||||
|
||||
case wxGIF_TRUNCATED:
|
||||
if ( verbose )
|
||||
wxLogError(_("GIF: data stream seems to be truncated."));
|
||||
|
||||
// go on; image data is OK
|
||||
break;
|
||||
}
|
||||
|
||||
if ((error == wxGIF_TRUNCATED) && verbose)
|
||||
{
|
||||
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;
|
||||
return decod.ConvertToImage(index != -1 ? (size_t)index : 0, image);
|
||||
}
|
||||
|
||||
bool wxGIFHandler::SaveFile(wxImage *image,
|
||||
|
Loading…
Reference in New Issue
Block a user