X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/661dc384df649f673d06fa1038e343cf263932af..bd44dee6986e5c9f706e842b9e969798e130099f:/include/wx/gifdecod.h diff --git a/include/wx/gifdecod.h b/include/wx/gifdecod.h index 30fa11cfed..86abb16cd6 100644 --- a/include/wx/gifdecod.h +++ b/include/wx/gifdecod.h @@ -1,121 +1,110 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: gifdecod.h +// Name: wx/gifdecod.h // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation // Author: Guillermo Rodriguez Garcia -// Version: 3.0 -// Last rev: 1999/08/10 -// Copyright: (c) Guillermo Rodriguez Garcia +// Version: 3.02 +// CVS-ID: $Id$ +// Copyright: (c) 1999 Guillermo Rodriguez Garcia // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_GIFDECOD_H -#define _WX_GIFDECOD_H +#ifndef _WX_GIFDECOD_H_ +#define _WX_GIFDECOD_H_ -#ifdef __GNUG__ -#pragma interface "gifdecod.h" -#endif +#include "wx/defs.h" -#include "wx/setup.h" +#if wxUSE_STREAMS && wxUSE_GIF -#if wxUSE_STREAMS #include "wx/stream.h" #include "wx/image.h" +#include "wx/animdecod.h" +#include "wx/dynarray.h" +// internal utility used to store a frame in 8bit-per-pixel format +class GIFImage; -typedef struct _IMAGEN -{ - unsigned int w; /* width */ - unsigned int h; /* height */ - unsigned int left; /* x coord (in logical screen) */ - unsigned int top; /* y coord (in logical screen) */ - int transparent; /* transparent color (-1 = none) */ - int disposal; /* disposal method */ - long delay; /* delay in ms (-1 = unused) */ - unsigned char *p; /* bitmap */ - unsigned char *pal; /* palette */ - struct _IMAGEN *next; /* next image */ - struct _IMAGEN *prev; /* prev image */ -} IMAGEN; - - -/* disposal method */ -#define D_UNSPECIFIED -1 /* not specified */ -#define D_DONOTDISPOSE 0 /* do not dispose */ -#define D_TOBACKGROUND 1 /* restore to background colour */ -#define D_TOPREVIOUS 2 /* restore to previous image */ - -/* error codes */ -#define E_OK 0 /* everything was OK */ -#define E_ARCHIVO -1 /* error opening file */ -#define E_FORMATO -2 /* error in gif header */ -#define E_MEMORIA -3 /* error allocating memory */ - - -class wxGIFDecoder + +// -------------------------------------------------------------------------- +// Constants +// -------------------------------------------------------------------------- + +// 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. +// +enum wxGIFErrorCode { -private: - /* logical screen */ - unsigned int m_screenw; /* logical screen width */ - unsigned int m_screenh; /* logical screen height */ - int m_background; /* background color (-1 = none) */ - - /* image data */ - bool m_anim; /* animated GIF */ - int m_nimages; /* number of images */ - int m_image; /* current image */ - IMAGEN *m_pimage; /* pointer to current image */ - IMAGEN *m_pfirst; /* pointer to first image */ - IMAGEN *m_plast; /* pointer to last image */ - - /* 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 */ - - wxInputStream *m_f; /* input file */ + wxGIF_OK = 0, // everything was OK + wxGIF_INVFORMAT, // error in GIF header + wxGIF_MEMERR, // error allocating memory + wxGIF_TRUNCATED // file appears to be truncated +}; -private: - int getcode(int bits, int abfin); - int dgif(IMAGEN *img, int interl, int bits); +// -------------------------------------------------------------------------- +// wxGIFDecoder class +// -------------------------------------------------------------------------- +class WXDLLIMPEXP_CORE wxGIFDecoder : public wxAnimationDecoder +{ public: // constructor, destructor, etc. - wxGIFDecoder(wxInputStream *s, bool anim = FALSE); + wxGIFDecoder(); ~wxGIFDecoder(); - int ReadGIF(); + + // get data of current frame + 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; + + 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; + + // GIFs can contain both static images and animations + bool IsAnimation() const + { return m_nFrames > 1; } + + // load function which returns more info than just Load(): + wxGIFErrorCode LoadGIF( wxInputStream& stream ); + + // free all internal frames void Destroy(); - // convert current frame to wxImage - bool ConvertToImage(wxImage *image) const; + // implementation of wxAnimationDecoder's pure virtuals + virtual bool CanRead( wxInputStream& stream ) const; + virtual bool Load( wxInputStream& stream ) + { return LoadGIF(stream) == wxGIF_OK; } - // get data of current frame - int GetFrameIndex() const; - unsigned char* GetData() const; - unsigned char* GetPalette() const; - unsigned int GetWidth() const; - unsigned int GetHeight() const; - unsigned int GetLeft() const; - unsigned int GetTop() const; - int GetDisposalMethod() const; - int GetTransparentColour() const; - long GetDelay() const; - - // get global data - unsigned int GetLogicalScreenWidth() const; - unsigned int GetLogicalScreenHeight() const; - int GetBackgroundColour() const; - int GetNumberOfFrames() const; - bool IsAnimation() const; - - // move through the animation - bool GoFirstFrame(); - bool GoLastFrame(); - bool GoNextFrame(bool cyclic = FALSE); - bool GoPrevFrame(bool cyclic = FALSE); - bool GoFrame(int which); -}; + bool ConvertToImage(unsigned int frame, wxImage *image) const; + + wxAnimationDecoder *Clone() const + { return new wxGIFDecoder; } + wxAnimationType GetType() const + { return wxANIMATION_TYPE_GIF; } +private: + // 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); + + DECLARE_NO_COPY_CLASS(wxGIFDecoder) +}; -#endif // wxUSE_STREAM -#endif // _WX_GIFDECOD_H +#endif // wxUSE_STREAMS && wxUSE_GIF +#endif // _WX_GIFDECOD_H_