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"
21 #include "wx/dynarray.h"
23 // internal utility used to store a frame in 8bit-per-pixel format
27 // --------------------------------------------------------------------------
29 // --------------------------------------------------------------------------
32 // Note that the error code wxGIF_TRUNCATED means that the image itself
33 // is most probably OK, but the decoder didn't reach the end of the data
34 // stream; this means that if it was not reading directly from file,
35 // the stream will not be correctly positioned.
39 wxGIF_OK
= 0, // everything was OK
40 wxGIF_INVFORMAT
, // error in GIF header
41 wxGIF_MEMERR
, // error allocating memory
42 wxGIF_TRUNCATED
// file appears to be truncated
45 // --------------------------------------------------------------------------
47 // --------------------------------------------------------------------------
49 class WXDLLIMPEXP_CORE wxGIFDecoder
: public wxAnimationDecoder
52 // constructor, destructor, etc.
56 // get data of current frame
57 unsigned char* GetData(unsigned int frame
) const;
58 unsigned char* GetPalette(unsigned int frame
) const;
59 unsigned int GetNcolours(unsigned int frame
) const;
60 int GetTransparentColourIndex(unsigned int frame
) const;
61 wxColour
GetTransparentColour(unsigned int frame
) const;
63 virtual wxSize
GetFrameSize(unsigned int frame
) const;
64 virtual wxPoint
GetFramePosition(unsigned int frame
) const;
65 virtual wxAnimationDisposal
GetDisposalMethod(unsigned int frame
) const;
66 virtual long GetDelay(unsigned int frame
) const;
68 // GIFs can contain both static images and animations
69 bool IsAnimation() const
70 { return m_nFrames
> 1; }
72 // load function which returns more info than just Load():
73 wxGIFErrorCode
LoadGIF( wxInputStream
& stream
);
75 // free all internal frames
78 // implementation of wxAnimationDecoder's pure virtuals
79 virtual bool CanRead( wxInputStream
& stream
) const;
80 virtual bool Load( wxInputStream
& stream
)
81 { return LoadGIF(stream
) == wxGIF_OK
; }
83 bool ConvertToImage(unsigned int frame
, wxImage
*image
) const;
85 wxAnimationDecoder
*Clone() const
86 { return new wxGIFDecoder
; }
87 wxAnimationType
GetType() const
88 { return wxANIMATION_TYPE_GIF
; }
91 // array of all frames
92 wxArrayPtrVoid m_frames
;
95 int m_restbits
; // remaining valid bits
96 unsigned int m_restbyte
; // remaining bytes in this block
97 unsigned int m_lastbyte
; // last byte read
98 unsigned char m_buffer
[256]; // buffer for reading
99 unsigned char *m_bufp
; // pointer to next byte in buffer
101 int getcode(wxInputStream
& stream
, int bits
, int abfin
);
102 wxGIFErrorCode
dgif(wxInputStream
& stream
,
103 GIFImage
*img
, int interl
, int bits
);
105 DECLARE_NO_COPY_CLASS(wxGIFDecoder
)
108 #endif // wxUSE_STREAMS && wxUSE_GIF
110 #endif // _WX_GIFDECOD_H_