]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gifdecod.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
4 // Author: Guillermo Rodriguez Garcia <guille@iies.es>
7 // Copyright: (c) 1999 Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GIFDECOD_H
12 #define _WX_GIFDECOD_H
16 #if wxUSE_STREAMS && wxUSE_GIF
18 #include "wx/stream.h"
20 #include "wx/animdecod.h"
22 // internal utility used to store a frame in 8bit-per-pixel format
23 class /*WXDLLEXPORT*/ GIFImage
;
26 // --------------------------------------------------------------------------
28 // --------------------------------------------------------------------------
31 // Note that the error code wxGIF_TRUNCATED means that the image itself
32 // is most probably OK, but the decoder didn't reach the end of the data
33 // stream; this means that if it was not reading directly from file,
34 // the stream will not be correctly positioned. the
38 wxGIF_OK
= 0, /* everything was OK */
39 wxGIF_INVFORMAT
, /* error in gif header */
40 wxGIF_MEMERR
, /* error allocating memory */
41 wxGIF_TRUNCATED
/* file appears to be truncated */
44 #define MAX_BLOCK_SIZE 256 /* max. block size */
47 // --------------------------------------------------------------------------
49 // --------------------------------------------------------------------------
51 class WXDLLEXPORT wxGIFDecoder
: public wxAnimationDecoder
54 // a wxArray provides a constant access time rather than a linear time
55 // like for linked lists.
56 wxArrayPtrVoid m_frames
;
59 int m_restbits
; /* remaining valid bits */
60 unsigned int m_restbyte
; /* remaining bytes in this block */
61 unsigned int m_lastbyte
; /* last byte read */
62 unsigned char m_buffer
[MAX_BLOCK_SIZE
]; /* buffer for reading */
63 unsigned char *m_bufp
; /* pointer to next byte in buffer */
66 int getcode(wxInputStream
& stream
, int bits
, int abfin
);
67 wxGIFErrorCode
dgif(wxInputStream
& stream
, GIFImage
*img
, int interl
, int bits
);
70 // get data of current frame
71 unsigned char* GetData(size_t frame
) const;
72 unsigned char* GetPalette(size_t frame
) const;
73 unsigned int GetNcolours(size_t frame
) const;
74 int GetTransparentColour(size_t frame
) const;
76 virtual wxSize
GetFrameSize(size_t frame
) const;
77 virtual wxPoint
GetFramePosition(size_t frame
) const;
78 virtual wxAnimationDisposal
GetDisposalMethod(size_t frame
) const;
79 virtual long GetDelay(size_t frame
) const;
81 // GIFs can contain both static images and animations
82 bool IsAnimation() const
83 { return m_nFrames
> 1; }
86 // constructor, destructor, etc.
90 // load function which returns more info than just Load():
91 wxGIFErrorCode
LoadGIF( wxInputStream
& stream
);
93 // free all internal frames
96 public: // implementation of wxAnimationDecoder's pure virtuals
98 virtual bool CanRead( wxInputStream
& stream
) const;
99 virtual bool Load( wxInputStream
& stream
)
100 { return LoadGIF(stream
) == wxGIF_OK
; }
102 bool ConvertToImage(size_t frame
, wxImage
*image
) const;
104 wxAnimationDecoder
*Clone() const
105 { return new wxGIFDecoder
; }
106 wxAnimationType
GetType() const
107 { return wxANIMATION_TYPE_GIF
; }
110 DECLARE_NO_COPY_CLASS(wxGIFDecoder
)
114 #endif // wxUSE_STREAM && wxUSE_GIF
115 #endif // _WX_GIFDECOD_H