]>
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
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.
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 // --------------------------------------------------------------------------
46 // --------------------------------------------------------------------------
48 class WXDLLEXPORT wxGIFDecoder
: public wxAnimationDecoder
51 // constructor, destructor, etc.
55 // get data of current frame
56 unsigned char* GetData(unsigned int frame
) const;
57 unsigned char* GetPalette(unsigned int frame
) const;
58 unsigned int GetNcolours(unsigned int frame
) const;
59 int GetTransparentColourIndex(unsigned int frame
) const;
60 wxColour
GetTransparentColour(unsigned int frame
) const;
62 virtual wxSize
GetFrameSize(unsigned int frame
) const;
63 virtual wxPoint
GetFramePosition(unsigned int frame
) const;
64 virtual wxAnimationDisposal
GetDisposalMethod(unsigned int frame
) const;
65 virtual long GetDelay(unsigned int frame
) const;
67 // GIFs can contain both static images and animations
68 bool IsAnimation() const
69 { return m_nFrames
> 1; }
71 // load function which returns more info than just Load():
72 wxGIFErrorCode
LoadGIF( wxInputStream
& stream
);
74 // free all internal frames
77 // implementation of wxAnimationDecoder's pure virtuals
78 virtual bool CanRead( wxInputStream
& stream
) const;
79 virtual bool Load( wxInputStream
& stream
)
80 { return LoadGIF(stream
) == wxGIF_OK
; }
82 bool ConvertToImage(unsigned int frame
, wxImage
*image
) const;
84 wxAnimationDecoder
*Clone() const
85 { return new wxGIFDecoder
; }
86 wxAnimationType
GetType() const
87 { return wxANIMATION_TYPE_GIF
; }
90 // array of all frames
91 wxArrayPtrVoid m_frames
;
94 int m_restbits
; // remaining valid bits
95 unsigned int m_restbyte
; // remaining bytes in this block
96 unsigned int m_lastbyte
; // last byte read
97 unsigned char m_buffer
[256]; // buffer for reading
98 unsigned char *m_bufp
; // pointer to next byte in buffer
100 int getcode(wxInputStream
& stream
, int bits
, int abfin
);
101 wxGIFErrorCode
dgif(wxInputStream
& stream
,
102 GIFImage
*img
, int interl
, int bits
);
104 DECLARE_NO_COPY_CLASS(wxGIFDecoder
)
107 #endif // wxUSE_STREAM && wxUSE_GIF
109 #endif // _WX_GIFDECOD_H_