1999-08-18 06:28:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-10-30 11:56:12 +00:00
|
|
|
// Name: wx/gifdecod.h
|
1999-08-18 06:28:59 +00:00
|
|
|
// 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
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-12-10 14:18:37 +00:00
|
|
|
#ifndef _WX_GIFDECOD_H_
|
|
|
|
#define _WX_GIFDECOD_H_
|
1999-08-18 06:28:59 +00:00
|
|
|
|
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"
|
2007-04-21 18:13:48 +00:00
|
|
|
#include "wx/dynarray.h"
|
2006-10-09 17:51:07 +00:00
|
|
|
|
|
|
|
// internal utility used to store a frame in 8bit-per-pixel format
|
2006-12-10 14:18:37 +00:00
|
|
|
class 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,
|
2006-12-10 14:18:37 +00:00
|
|
|
// the stream will not be correctly positioned.
|
2000-02-17 23:39:35 +00:00
|
|
|
//
|
2006-10-09 17:51:07 +00:00
|
|
|
enum wxGIFErrorCode
|
2000-02-17 23:39:35 +00:00
|
|
|
{
|
2006-12-10 14:18:37 +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
|
2000-02-17 23:39:35 +00:00
|
|
|
};
|
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxGIFDecoder class
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2006-10-09 17:51:07 +00:00
|
|
|
class WXDLLEXPORT wxGIFDecoder : public wxAnimationDecoder
|
1999-08-18 06:28:59 +00:00
|
|
|
{
|
2001-07-02 10:06:51 +00:00
|
|
|
public:
|
2006-12-10 14:18:37 +00:00
|
|
|
// constructor, destructor, etc.
|
|
|
|
wxGIFDecoder();
|
|
|
|
~wxGIFDecoder();
|
|
|
|
|
1999-08-18 06:28:59 +00:00
|
|
|
// get data of current frame
|
2006-12-10 14:18:37 +00: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 17:51:07 +00:00
|
|
|
|
2006-12-10 14:18:37 +00: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 17:51:07 +00:00
|
|
|
|
|
|
|
// GIFs can contain both static images and animations
|
|
|
|
bool IsAnimation() const
|
|
|
|
{ return m_nFrames > 1; }
|
1999-12-10 20:16:01 +00:00
|
|
|
|
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-12-10 14:18:37 +00:00
|
|
|
// implementation of wxAnimationDecoder's pure virtuals
|
2006-10-09 17:51:07 +00:00
|
|
|
virtual bool CanRead( wxInputStream& stream ) const;
|
|
|
|
virtual bool Load( wxInputStream& stream )
|
|
|
|
{ return LoadGIF(stream) == wxGIF_OK; }
|
|
|
|
|
2006-12-10 14:18:37 +00:00
|
|
|
bool ConvertToImage(unsigned int 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:
|
2006-12-10 14:18:37 +00: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
|
|
|
|
|
|
|
|
int getcode(wxInputStream& stream, int bits, int abfin);
|
|
|
|
wxGIFErrorCode dgif(wxInputStream& stream,
|
|
|
|
GIFImage *img, int interl, int bits);
|
|
|
|
|
2003-01-02 23:38:11 +00:00
|
|
|
DECLARE_NO_COPY_CLASS(wxGIFDecoder)
|
1999-08-18 06:28:59 +00:00
|
|
|
};
|
|
|
|
|
2007-07-21 23:54:55 +00:00
|
|
|
#endif // wxUSE_STREAMS && wxUSE_GIF
|
1999-08-18 06:28:59 +00:00
|
|
|
|
2006-12-10 14:18:37 +00:00
|
|
|
#endif // _WX_GIFDECOD_H_
|