1999-08-18 06:28:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: gifdecod.h
|
|
|
|
// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
|
|
|
|
// Author: Guillermo Rodriguez Garcia <guille@iies.es>
|
1999-08-24 22:13:26 +00:00
|
|
|
// Version: 3.02
|
1999-09-09 22:12:08 +00:00
|
|
|
// CVS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 Guillermo Rodriguez Garcia
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-08-18 06:28:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_GIFDECOD_H
|
|
|
|
#define _WX_GIFDECOD_H
|
|
|
|
|
2005-03-16 16:18:31 +00:00
|
|
|
#include "wx/defs.h"
|
1999-08-18 06:28:59 +00:00
|
|
|
|
1999-09-09 22:12:08 +00:00
|
|
|
#if wxUSE_STREAMS && wxUSE_GIF
|
|
|
|
|
1999-08-18 06:28:59 +00:00
|
|
|
#include "wx/stream.h"
|
|
|
|
#include "wx/image.h"
|
2006-10-09 17:51:07 +00:00
|
|
|
#include "wx/animdecod.h"
|
|
|
|
|
|
|
|
// internal utility used to store a frame in 8bit-per-pixel format
|
|
|
|
class /*WXDLLEXPORT*/ GIFImage;
|
1999-08-18 06:28:59 +00:00
|
|
|
|
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// --------------------------------------------------------------------------
|
2000-02-17 23:39:35 +00:00
|
|
|
// Constants
|
1999-12-10 20:16:01 +00:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2000-02-17 23:39:35 +00: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 17:51:07 +00:00
|
|
|
enum wxGIFErrorCode
|
2000-02-17 23:39:35 +00: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 20:16:01 +00:00
|
|
|
#define MAX_BLOCK_SIZE 256 /* max. block size */
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxGIFDecoder class
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2006-10-09 17:51:07 +00:00
|
|
|
class WXDLLEXPORT wxGIFDecoder : public wxAnimationDecoder
|
1999-08-18 06:28:59 +00:00
|
|
|
{
|
|
|
|
private:
|
2006-10-09 17:51:07 +00:00
|
|
|
// a wxArray provides a constant access time rather than a linear time
|
|
|
|
// like for linked lists.
|
|
|
|
wxArrayPtrVoid m_frames;
|
1999-08-18 06:28:59 +00:00
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// decoder state vars
|
1999-08-18 06:28:59 +00: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 14:39:28 +00:00
|
|
|
unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
|
|
|
|
unsigned char *m_bufp; /* pointer to next byte in buffer */
|
1999-08-18 06:28:59 +00:00
|
|
|
|
|
|
|
private:
|
2006-10-09 17:51:07 +00:00
|
|
|
int getcode(wxInputStream& stream, int bits, int abfin);
|
|
|
|
wxGIFErrorCode dgif(wxInputStream& stream, GIFImage *img, int interl, int bits);
|
1999-08-18 06:28:59 +00:00
|
|
|
|
2001-07-02 10:06:51 +00:00
|
|
|
public:
|
1999-08-18 06:28:59 +00:00
|
|
|
// get data of current frame
|
2006-10-09 17:51:07 +00:00
|
|
|
unsigned char* GetData(size_t frame) const;
|
|
|
|
unsigned char* GetPalette(size_t frame) const;
|
|
|
|
unsigned int GetNcolours(size_t frame) const;
|
2006-10-11 16:09:39 +00:00
|
|
|
int GetTransparentColourIndex(size_t frame) const;
|
|
|
|
wxColour GetTransparentColour(size_t frame) const;
|
2006-10-09 17:51:07 +00:00
|
|
|
|
|
|
|
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 20:16:01 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor, destructor, etc.
|
2006-10-09 17:51:07 +00:00
|
|
|
wxGIFDecoder();
|
1999-12-10 20:16:01 +00:00
|
|
|
~wxGIFDecoder();
|
2006-10-09 17:51:07 +00:00
|
|
|
|
|
|
|
// load function which returns more info than just Load():
|
|
|
|
wxGIFErrorCode LoadGIF( wxInputStream& stream );
|
|
|
|
|
|
|
|
// free all internal frames
|
1999-12-10 20:16:01 +00:00
|
|
|
void Destroy();
|
|
|
|
|
2006-10-09 17:51:07 +00: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 23:38:11 +00:00
|
|
|
|
2006-10-09 17:51:07 +00:00
|
|
|
wxAnimationDecoder *Clone() const
|
|
|
|
{ return new wxGIFDecoder; }
|
|
|
|
wxAnimationType GetType() const
|
|
|
|
{ return wxANIMATION_TYPE_GIF; }
|
|
|
|
|
|
|
|
private:
|
2003-01-02 23:38:11 +00:00
|
|
|
DECLARE_NO_COPY_CLASS(wxGIFDecoder)
|
1999-08-18 06:28:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-09-09 22:12:08 +00:00
|
|
|
#endif // wxUSE_STREAM && wxUSE_GIF
|
1999-08-18 06:28:59 +00:00
|
|
|
#endif // _WX_GIFDECOD_H
|
|
|
|
|