1999-08-18 02:28:59 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-30 06:56:12 -05:00
|
|
|
// Name: wx/gifdecod.h
|
1999-08-18 02:28:59 -04:00
|
|
|
// 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
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-12-10 09:18:37 -05:00
|
|
|
#ifndef _WX_GIFDECOD_H_
|
|
|
|
#define _WX_GIFDECOD_H_
|
1999-08-18 02:28:59 -04:00
|
|
|
|
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"
|
2007-04-21 14:13:48 -04:00
|
|
|
#include "wx/dynarray.h"
|
2006-10-09 13:51:07 -04:00
|
|
|
|
|
|
|
// internal utility used to store a frame in 8bit-per-pixel format
|
2006-12-10 09:18:37 -05:00
|
|
|
class 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,
|
2006-12-10 09:18:37 -05:00
|
|
|
// the stream will not be correctly positioned.
|
2000-02-17 18:39:35 -05:00
|
|
|
//
|
2006-10-09 13:51:07 -04:00
|
|
|
enum wxGIFErrorCode
|
2000-02-17 18:39:35 -05:00
|
|
|
{
|
2006-12-10 09:18:37 -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
|
2000-02-17 18:39:35 -05:00
|
|
|
};
|
|
|
|
|
1999-12-10 15:16:01 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxGIFDecoder class
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxGIFDecoder : public wxAnimationDecoder
|
1999-08-18 02:28:59 -04:00
|
|
|
{
|
2001-07-02 06:06:51 -04:00
|
|
|
public:
|
2006-12-10 09:18:37 -05:00
|
|
|
// constructor, destructor, etc.
|
|
|
|
wxGIFDecoder();
|
|
|
|
~wxGIFDecoder();
|
|
|
|
|
1999-08-18 02:28:59 -04:00
|
|
|
// get data of current frame
|
2006-12-10 09:18:37 -05:00
|
|
|
unsigned char* GetData(unsigned int frame) const;
|
|
|
|
unsigned char* GetPalette(unsigned int frame) const;
|
|
|
|
unsigned int GetNcolours(unsigned int frame) const;
|
|
|
|
int GetTransparentColourIndex(unsigned int frame) const;
|
|
|
|
wxColour GetTransparentColour(unsigned int frame) const;
|
2006-10-09 13:51:07 -04:00
|
|
|
|
2006-12-10 09:18:37 -05:00
|
|
|
virtual wxSize GetFrameSize(unsigned int frame) const;
|
|
|
|
virtual wxPoint GetFramePosition(unsigned int frame) const;
|
|
|
|
virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
|
|
|
|
virtual long GetDelay(unsigned int frame) const;
|
2006-10-09 13:51:07 -04:00
|
|
|
|
|
|
|
// GIFs can contain both static images and animations
|
|
|
|
bool IsAnimation() const
|
|
|
|
{ return m_nFrames > 1; }
|
1999-12-10 15:16:01 -05:00
|
|
|
|
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-12-10 09:18:37 -05:00
|
|
|
// implementation of wxAnimationDecoder's pure virtuals
|
2006-10-09 13:51:07 -04:00
|
|
|
virtual bool Load( wxInputStream& stream )
|
|
|
|
{ return LoadGIF(stream) == wxGIF_OK; }
|
|
|
|
|
2006-12-10 09:18:37 -05:00
|
|
|
bool ConvertToImage(unsigned int 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:
|
2009-06-01 07:43:36 -04:00
|
|
|
// wxAnimationDecoder pure virtual
|
|
|
|
virtual bool DoCanRead( wxInputStream& stream ) const;
|
|
|
|
// modifies current stream position (see wxAnimationDecoder::CanRead)
|
|
|
|
|
|
|
|
int getcode(wxInputStream& stream, int bits, int abfin);
|
|
|
|
wxGIFErrorCode dgif(wxInputStream& stream,
|
|
|
|
GIFImage *img, int interl, int bits);
|
|
|
|
|
|
|
|
|
2006-12-10 09:18:37 -05:00
|
|
|
// array of all frames
|
|
|
|
wxArrayPtrVoid m_frames;
|
|
|
|
|
|
|
|
// decoder state vars
|
|
|
|
int m_restbits; // remaining valid bits
|
|
|
|
unsigned int m_restbyte; // remaining bytes in this block
|
|
|
|
unsigned int m_lastbyte; // last byte read
|
|
|
|
unsigned char m_buffer[256]; // buffer for reading
|
|
|
|
unsigned char *m_bufp; // pointer to next byte in buffer
|
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxGIFDecoder);
|
1999-08-18 02:28:59 -04:00
|
|
|
};
|
|
|
|
|
2007-07-21 19:54:55 -04:00
|
|
|
#endif // wxUSE_STREAMS && wxUSE_GIF
|
1999-08-18 02:28:59 -04:00
|
|
|
|
2006-12-10 09:18:37 -05:00
|
|
|
#endif // _WX_GIFDECOD_H_
|