X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf..835165d576b66441987b78519e6ef1fe74ea795a:/include/wx/gifdecod.h diff --git a/include/wx/gifdecod.h b/include/wx/gifdecod.h index 2fdcdd39f9..908f470ece 100644 --- a/include/wx/gifdecod.h +++ b/include/wx/gifdecod.h @@ -8,8 +8,8 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_GIFDECOD_H -#define _WX_GIFDECOD_H +#ifndef _WX_GIFDECOD_H_ +#define _WX_GIFDECOD_H_ #include "wx/defs.h" @@ -18,9 +18,10 @@ #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 /*WXDLLEXPORT*/ GIFImage; +class GIFImage; // -------------------------------------------------------------------------- @@ -31,76 +32,54 @@ class /*WXDLLEXPORT*/ GIFImage; // 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 +// the stream will not be correctly positioned. // enum wxGIFErrorCode { - wxGIF_OK = 0, /* everything was OK */ - wxGIF_INVFORMAT, /* error in gif header */ - wxGIF_MEMERR, /* error allocating memory */ - wxGIF_TRUNCATED /* file appears to be truncated */ + wxGIF_OK = 0, // everything was OK + wxGIF_INVFORMAT, // error in GIF header + wxGIF_MEMERR, // error allocating memory + wxGIF_TRUNCATED // file appears to be truncated }; -#define MAX_BLOCK_SIZE 256 /* max. block size */ - - // -------------------------------------------------------------------------- // wxGIFDecoder class // -------------------------------------------------------------------------- -class WXDLLEXPORT wxGIFDecoder : public wxAnimationDecoder +class WXDLLIMPEXP_CORE wxGIFDecoder : public wxAnimationDecoder { -private: - // a wxArray provides a constant access time rather than a linear time - // like for linked lists. - 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[MAX_BLOCK_SIZE]; /* buffer for reading */ - unsigned char *m_bufp; /* pointer to next byte in buffer */ - -private: - int getcode(wxInputStream& stream, int bits, int abfin); - wxGIFErrorCode dgif(wxInputStream& stream, GIFImage *img, int interl, int bits); - public: + // constructor, destructor, etc. + wxGIFDecoder(); + ~wxGIFDecoder(); + // get data of current frame - unsigned char* GetData(size_t frame) const; - unsigned char* GetPalette(size_t frame) const; - unsigned int GetNcolours(size_t frame) const; - int GetTransparentColourIndex(size_t frame) const; - wxColour GetTransparentColour(size_t frame) const; + 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(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; + 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; } -public: - // constructor, destructor, etc. - wxGIFDecoder(); - ~wxGIFDecoder(); - // load function which returns more info than just Load(): wxGIFErrorCode LoadGIF( wxInputStream& stream ); // free all internal frames void Destroy(); -public: // implementation of wxAnimationDecoder's pure virtuals - - virtual bool CanRead( wxInputStream& stream ) const; + // implementation of wxAnimationDecoder's pure virtuals virtual bool Load( wxInputStream& stream ) { return LoadGIF(stream) == wxGIF_OK; } - bool ConvertToImage(size_t frame, wxImage *image) const; + bool ConvertToImage(unsigned int frame, wxImage *image) const; wxAnimationDecoder *Clone() const { return new wxGIFDecoder; } @@ -108,9 +87,28 @@ public: // implementation of wxAnimationDecoder's pure virtuals { return wxANIMATION_TYPE_GIF; } private: - DECLARE_NO_COPY_CLASS(wxGIFDecoder) + // 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); + + + // 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 + + wxDECLARE_NO_COPY_CLASS(wxGIFDecoder); }; +#endif // wxUSE_STREAMS && wxUSE_GIF -#endif // wxUSE_STREAM && wxUSE_GIF -#endif // _WX_GIFDECOD_H +#endif // _WX_GIFDECOD_H_