X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c87527e89228b537800d06e1c32a62900417beb..9398120d298d745763f253d87d774be3b134b43f:/include/wx/gifdecod.h?ds=sidebyside diff --git a/include/wx/gifdecod.h b/include/wx/gifdecod.h index 35e073fdc8..e40152cfa1 100644 --- a/include/wx/gifdecod.h +++ b/include/wx/gifdecod.h @@ -3,8 +3,8 @@ // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation // Author: Guillermo Rodriguez Garcia // Version: 3.02 -// Last rev: 1999/08/18 -// Copyright: (c) Guillermo Rodriguez Garcia +// CVS-ID: $Id$ +// Copyright: (c) 1999 Guillermo Rodriguez Garcia // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -17,13 +17,56 @@ #include "wx/setup.h" -#if wxUSE_STREAMS +#if wxUSE_STREAMS && wxUSE_GIF + #include "wx/stream.h" #include "wx/image.h" -typedef struct _IMAGEN +// -------------------------------------------------------------------------- +// 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. the +// +enum +{ + wxGIF_OK = 0, /* everything was OK */ + wxGIF_INVFORMAT, /* error in gif header */ + wxGIF_MEMERR, /* error allocating memory */ + wxGIF_TRUNCATED /* file appears to be truncated */ +}; + +// Disposal method +// Experimental; subject to change. +// +enum +{ + wxGIF_D_UNSPECIFIED = -1, /* not specified */ + wxGIF_D_DONOTDISPOSE = 0, /* do not dispose */ + wxGIF_D_TOBACKGROUND = 1, /* restore to background colour */ + wxGIF_D_TOPREVIOUS = 2 /* restore to previous image */ +}; + + +#define MAX_BLOCK_SIZE 256 /* max. block size */ + + +// -------------------------------------------------------------------------- +// wxGIFDecoder class +// -------------------------------------------------------------------------- + +// internal class for storing GIF image data +class GIFImage { +public: + // def ctor + GIFImage(); + unsigned int w; /* width */ unsigned int h; /* height */ unsigned int left; /* x coord (in logical screen) */ @@ -33,62 +76,42 @@ typedef struct _IMAGEN 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 */ + GIFImage *next; /* next image */ + GIFImage *prev; /* prev image */ +}; -class wxGIFDecoder +class WXDLLEXPORT wxGIFDecoder { private: - /* logical screen */ + // 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 */ + // 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 */ + GIFImage *m_pimage; /* pointer to current image */ + GIFImage *m_pfirst; /* pointer to first image */ + GIFImage *m_plast; /* pointer to last image */ - /* decoder state vars */ + // 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[MAX_BLOCK_SIZE]; /* buffer for reading */ + unsigned char *m_bufp; /* pointer to next byte in buffer */ - wxInputStream *m_f; /* input file */ + // input stream + wxInputStream *m_f; /* input stream */ private: int getcode(int bits, int abfin); - int dgif(IMAGEN *img, int interl, int bits); + int dgif(GIFImage *img, int interl, int bits); public: - // constructor, destructor, etc. - wxGIFDecoder(wxInputStream *s, bool anim = FALSE); - ~wxGIFDecoder(); - bool CanRead(); - int ReadGIF(); - void Destroy(); - - // convert current frame to wxImage - bool ConvertToImage(wxImage *image) const; - // get data of current frame int GetFrameIndex() const; unsigned char* GetData() const; @@ -114,9 +137,20 @@ public: bool GoNextFrame(bool cyclic = FALSE); bool GoPrevFrame(bool cyclic = FALSE); bool GoFrame(int which); + +public: + // constructor, destructor, etc. + wxGIFDecoder(wxInputStream *s, bool anim = FALSE); + ~wxGIFDecoder(); + bool CanRead(); + int ReadGIF(); + void Destroy(); + + // convert current frame to wxImage + bool ConvertToImage(wxImage *image) const; }; -#endif // wxUSE_STREAM +#endif // wxUSE_STREAM && wxUSE_GIF #endif // _WX_GIFDECOD_H