From: Guillermo Rodriguez Garcia Date: Tue, 24 Aug 1999 22:13:26 +0000 (+0000) Subject: Added CanRead() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3c87527e89228b537800d06e1c32a62900417beb?ds=inline Added CanRead() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gifdecod.h b/include/wx/gifdecod.h index 30fa11cfed..35e073fdc8 100644 --- a/include/wx/gifdecod.h +++ b/include/wx/gifdecod.h @@ -2,8 +2,8 @@ // Name: gifdecod.h // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation // Author: Guillermo Rodriguez Garcia -// Version: 3.0 -// Last rev: 1999/08/10 +// Version: 3.02 +// Last rev: 1999/08/18 // Copyright: (c) Guillermo Rodriguez Garcia // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -29,7 +29,7 @@ typedef struct _IMAGEN unsigned int left; /* x coord (in logical screen) */ unsigned int top; /* y coord (in logical screen) */ int transparent; /* transparent color (-1 = none) */ - int disposal; /* disposal method */ + int disposal; /* disposal method (-1 = unspecified) */ long delay; /* delay in ms (-1 = unused) */ unsigned char *p; /* bitmap */ unsigned char *pal; /* palette */ @@ -82,6 +82,7 @@ public: // constructor, destructor, etc. wxGIFDecoder(wxInputStream *s, bool anim = FALSE); ~wxGIFDecoder(); + bool CanRead(); int ReadGIF(); void Destroy(); diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index 047189cc51..32a89223c3 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.02 +// Last rev: 1999/08/18 // Copyright: (c) Guillermo Rodriguez Garcia // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -85,6 +85,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 +439,20 @@ 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]; + + m_f->SeekI(0, wxFromStart); + m_f->Read(buf, 3); + + 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 +472,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;