X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/464122b639263c81fcbd698bae3826313d2165a2..6842d18650b487249b4ae29d0d7e17231b24cde8:/src/common/gifdecod.cpp diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index 047189cc51..e8fcdc7514 100644 --- a/src/common/gifdecod.cpp +++ b/src/common/gifdecod.cpp @@ -2,8 +2,8 @@ // Name: gifdecod.cpp // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation // Author: Guillermo Rodriguez Garcia -// Version: 3.01 -// Last rev: 1999/08/14 +// Version: 3.03 +// RCS-ID: // Copyright: (c) Guillermo Rodriguez Garcia // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -20,14 +20,13 @@ #endif #ifndef WX_PRECOMP -# include "wx/setup.h" +# include "wx/defs.h" #endif -#if wxUSE_STREAMS +#if wxUSE_STREAMS && wxUSE_GIF #include #include -#include "wx/defs.h" #include "wx/gifdecod.h" @@ -85,6 +84,9 @@ bool wxGIFDecoder::ConvertToImage(wxImage *image) const unsigned long i; int transparent; + /* just in case... */ + image->Destroy(); + /* create the image */ image->Create(GetWidth(), GetHeight()); @@ -436,6 +438,23 @@ int wxGIFDecoder::dgif(IMAGEN *img, int interl, int bits) } +// CanRead: +// Returns TRUE if the file looks like a valid GIF, FALSE otherwise. +// +bool wxGIFDecoder::CanRead() +{ + unsigned char buf[3]; + off_t pos; + + pos = m_f->TellI(); + m_f->SeekI(0, wxFromStart); + m_f->Read(buf, 3); + m_f->SeekI(pos, wxFromStart); + + return (memcmp(buf, "GIF", 3) == 0); +} + + // ReadGIF: // Reads and decodes one or more GIF images, depending on whether // animated GIF support is enabled. Can read GIFs with any bit @@ -455,13 +474,14 @@ int wxGIFDecoder::ReadGIF() unsigned char buf[16]; IMAGEN **ppimg, *pimg, *pprev; + /* check GIF signature */ + if (!CanRead()) + return E_FORMATO; - /* check GIF signature and animated GIF support (ver. >= 89a) */ + /* check for and animated GIF support (ver. >= 89a) */ + m_f->SeekI(0, wxFromStart); m_f->Read(buf, 6); - if (memcmp(buf, "GIF", 3) != 0) - return E_FORMATO; - if (memcmp(buf + 3, "89a", 3) < 0) m_anim = FALSE; @@ -523,8 +543,10 @@ int wxGIFDecoder::ReadGIF() /* This line should not be neccessary! * Some images are not loaded correctly * without it. A bug in wxStream? + * Yes. Fixed now. */ // m_f->SeekI(m_f->TellI(), wxFromStart); + m_f->SeekI(i, wxFromCurrent); } } @@ -603,4 +625,4 @@ int wxGIFDecoder::ReadGIF() return E_OK; } -#endif // wxUSE_STREAM +#endif // wxUSE_STREAMS && wxUSE_GIF