1999-08-18 02:28:59 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: gifdecod.h
|
|
|
|
// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
|
|
|
|
// Author: Guillermo Rodriguez Garcia <guille@iies.es>
|
1999-08-24 18:13:26 -04:00
|
|
|
// Version: 3.02
|
1999-09-09 18:12:08 -04:00
|
|
|
// CVS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 Guillermo Rodriguez Garcia
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1999-08-18 02:28:59 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_GIFDECOD_H
|
|
|
|
#define _WX_GIFDECOD_H
|
|
|
|
|
2005-03-16 11:18:31 -05:00
|
|
|
#include "wx/defs.h"
|
1999-08-18 02:28:59 -04:00
|
|
|
|
1999-09-09 18:12:08 -04:00
|
|
|
#if wxUSE_STREAMS && wxUSE_GIF
|
|
|
|
|
1999-08-18 02:28:59 -04:00
|
|
|
#include "wx/stream.h"
|
|
|
|
#include "wx/image.h"
|
2006-10-09 13:51:07 -04:00
|
|
|
#include "wx/animdecod.h"
|
|
|
|
|
|
|
|
// internal utility used to store a frame in 8bit-per-pixel format
|
|
|
|
class /*WXDLLEXPORT*/ GIFImage;
|
1999-08-18 02:28:59 -04:00
|
|
|
|
|
|
|
|
1999-12-10 15:16:01 -05:00
|
|
|
// --------------------------------------------------------------------------
|
2000-02-17 18:39:35 -05:00
|
|
|
// Constants
|
1999-12-10 15:16:01 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2000-02-17 18:39:35 -05:00
|
|
|
// Error codes:
|
|
|
|
// Note that the error code wxGIF_TRUNCATED means that the image itself
|
|
|
|
// is most probably OK, but the decoder didn't reach the end of the data
|
|
|
|
// stream; this means that if it was not reading directly from file,
|
|
|
|
// the stream will not be correctly positioned. the
|
|
|
|
//
|
2006-10-09 13:51:07 -04:00
|
|
|
enum wxGIFErrorCode
|
2000-02-17 18:39:35 -05:00
|
|
|
{
|
|
|
|
wxGIF_OK = 0, /* everything was OK */
|
|
|
|
wxGIF_INVFORMAT, /* error in gif header */
|
|
|
|
wxGIF_MEMERR, /* error allocating memory */
|
|
|
|
wxGIF_TRUNCATED /* file appears to be truncated */
|
|
|
|
};
|
|
|
|
|
1999-12-10 15:16:01 -05:00
|
|
|
#define MAX_BLOCK_SIZE 256 /* max. block size */
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxGIFDecoder class
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2006-10-09 13:51:07 -04:00
|
|
|
class WXDLLEXPORT wxGIFDecoder : public wxAnimationDecoder
|
1999-08-18 02:28:59 -04:00
|
|
|
{
|
|
|
|
private:
|
2006-10-09 13:51:07 -04:00
|
|
|
// a wxArray provides a constant access time rather than a linear time
|
|
|
|
// like for linked lists.
|
|
|
|
wxArrayPtrVoid m_frames;
|
1999-08-18 02:28:59 -04:00
|
|
|
|
1999-12-10 15:16:01 -05:00
|
|
|
// decoder state vars
|
1999-08-18 02:28:59 -04:00
|
|
|
int m_restbits; /* remaining valid bits */
|
|
|
|
unsigned int m_restbyte; /* remaining bytes in this block */
|
|
|
|
unsigned int m_lastbyte; /* last byte read */
|
1999-12-08 09:39:28 -05:00
|
|
|
unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
|
|
|
|
unsigned char *m_bufp; /* pointer to next byte in buffer */
|
1999-08-18 02:28:59 -04:00
|
|
|
|
|
|
|
private:
|
2006-10-09 13:51:07 -04:00
|
|
|
int getcode(wxInputStream& stream, int bits, int abfin);
|
|
|
|
wxGIFErrorCode dgif(wxInputStream& stream, GIFImage *img, int interl, int bits);
|
1999-08-18 02:28:59 -04:00
|
|
|
|
2001-07-02 06:06:51 -04:00
|
|
|
public:
|
1999-08-18 02:28:59 -04:00
|
|
|
// get data of current frame
|
2006-10-09 13:51:07 -04:00
|
|
|
unsigned char* GetData(size_t frame) const;
|
|
|
|
unsigned char* GetPalette(size_t frame) const;
|
|
|
|
unsigned int GetNcolours(size_t frame) const;
|
|
|
|
int GetTransparentColour(size_t frame) const;
|
|
|
|
|
|
|
|
virtual wxSize GetFrameSize(size_t frame) const;
|
|
|
|
virtual wxPoint GetFramePosition(size_t frame) const;
|
|
|
|
virtual wxAnimationDisposal GetDisposalMethod(size_t frame) const;
|
|
|
|
virtual long GetDelay(size_t frame) const;
|
|
|
|
|
|
|
|
// GIFs can contain both static images and animations
|
|
|
|
bool IsAnimation() const
|
|
|
|
{ return m_nFrames > 1; }
|
1999-12-10 15:16:01 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor, destructor, etc.
|
2006-10-09 13:51:07 -04:00
|
|
|
wxGIFDecoder();
|
1999-12-10 15:16:01 -05:00
|
|
|
~wxGIFDecoder();
|
2006-10-09 13:51:07 -04:00
|
|
|
|
|
|
|
// load function which returns more info than just Load():
|
|
|
|
wxGIFErrorCode LoadGIF( wxInputStream& stream );
|
|
|
|
|
|
|
|
// free all internal frames
|
1999-12-10 15:16:01 -05:00
|
|
|
void Destroy();
|
|
|
|
|
2006-10-09 13:51:07 -04:00
|
|
|
public: // implementation of wxAnimationDecoder's pure virtuals
|
|
|
|
|
|
|
|
virtual bool CanRead( wxInputStream& stream ) const;
|
|
|
|
virtual bool Load( wxInputStream& stream )
|
|
|
|
{ return LoadGIF(stream) == wxGIF_OK; }
|
|
|
|
|
|
|
|
bool ConvertToImage(size_t frame, wxImage *image) const;
|
2003-01-02 18:38:11 -05:00
|
|
|
|
2006-10-09 13:51:07 -04:00
|
|
|
wxAnimationDecoder *Clone() const
|
|
|
|
{ return new wxGIFDecoder; }
|
|
|
|
wxAnimationType GetType() const
|
|
|
|
{ return wxANIMATION_TYPE_GIF; }
|
|
|
|
|
|
|
|
private:
|
2003-01-02 18:38:11 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(wxGIFDecoder)
|
1999-08-18 02:28:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-09-09 18:12:08 -04:00
|
|
|
#endif // wxUSE_STREAM && wxUSE_GIF
|
1999-08-18 02:28:59 -04:00
|
|
|
#endif // _WX_GIFDECOD_H
|
|
|
|
|