// Name: gifdecod.cpp
// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
// Author: Guillermo Rodriguez Garcia <guille@iies.es>
-// Version: 3.01
-// Last rev: 1999/08/14
+// Version: 3.04
+// RCS-ID: $Id$
// Copyright: (c) Guillermo Rodriguez Garcia
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#endif
#ifndef WX_PRECOMP
-# include "wx/setup.h"
+# include "wx/defs.h"
#endif
-#if wxUSE_STREAMS
+#if wxUSE_STREAMS && wxUSE_GIF
#include <stdlib.h>
#include <string.h>
-#include "wx/defs.h"
#include "wx/gifdecod.h"
-
+
//---------------------------------------------------------------------------
// wxGIFDecoder constructor and destructor
unsigned long i;
int transparent;
+ /* just in case... */
+ image->Destroy();
+
/* create the image */
image->Create(GetWidth(), GetHeight());
return TRUE;
}
-
+
//---------------------------------------------------------------------------
// Data accessors
//---------------------------------------------------------------------------
}
else
return FALSE;
-}
+}
bool wxGIFDecoder::GoPrevFrame(bool cyclic)
{
/* adjust total number of bits extracted from the buffer */
m_restbits = m_restbits + 8;
}
-
+
/* find number of bits remaining for next code */
m_restbits = (m_restbits - bits);
}
+// CanRead:
+// Returns TRUE if the file looks like a valid GIF, FALSE otherwise.
+//
+bool wxGIFDecoder::CanRead()
+{
+ unsigned char buf[3];
+
+ m_f->Read(buf, 3);
+ m_f->SeekI(-3, wxFromCurrent);
+
+ 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
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->Read(buf, 6);
- if (memcmp(buf, "GIF", 3) != 0)
- return E_FORMATO;
-
if (memcmp(buf + 3, "89a", 3) < 0)
m_anim = FALSE;
pprev = NULL;
pimg = NULL;
+#if defined(__VISAGECPP__)
+// VA just can't stand while(1)
+ bool bOs2var = TRUE;
+ while(bOs2var)
+#else
while (1)
+#endif
{
type = (unsigned char)m_f->GetC();
}
else
/* other extension, skip */
- {
+ {
while ((i = (unsigned char)m_f->GetC()) != 0)
{
/* 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);
}
}
return E_OK;
}
-#endif // wxUSE_STREAM
+#endif // wxUSE_STREAMS && wxUSE_GIF