]>
Commit | Line | Data |
---|---|---|
661dc384 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: gifdecod.h | |
3 | // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation | |
4 | // Author: Guillermo Rodriguez Garcia <guille@iies.es> | |
3c87527e | 5 | // Version: 3.02 |
83413d6d GRG |
6 | // CVS-ID: $Id$ |
7 | // Copyright: (c) 1999 Guillermo Rodriguez Garcia | |
65571936 | 8 | // Licence: wxWindows licence |
661dc384 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_GIFDECOD_H | |
12 | #define _WX_GIFDECOD_H | |
13 | ||
2ecf902b | 14 | #include "wx/defs.h" |
661dc384 | 15 | |
83413d6d GRG |
16 | #if wxUSE_STREAMS && wxUSE_GIF |
17 | ||
661dc384 JS |
18 | #include "wx/stream.h" |
19 | #include "wx/image.h" | |
72045d57 VZ |
20 | #include "wx/animdecod.h" |
21 | ||
22 | // internal utility used to store a frame in 8bit-per-pixel format | |
23 | class /*WXDLLEXPORT*/ GIFImage; | |
661dc384 JS |
24 | |
25 | ||
e4b8154a | 26 | // -------------------------------------------------------------------------- |
8141573c | 27 | // Constants |
e4b8154a GRG |
28 | // -------------------------------------------------------------------------- |
29 | ||
8141573c GRG |
30 | // Error codes: |
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 | |
35 | // | |
72045d57 | 36 | enum wxGIFErrorCode |
8141573c GRG |
37 | { |
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 */ | |
42 | }; | |
43 | ||
e4b8154a GRG |
44 | #define MAX_BLOCK_SIZE 256 /* max. block size */ |
45 | ||
46 | ||
47 | // -------------------------------------------------------------------------- | |
48 | // wxGIFDecoder class | |
49 | // -------------------------------------------------------------------------- | |
50 | ||
72045d57 | 51 | class WXDLLEXPORT wxGIFDecoder : public wxAnimationDecoder |
661dc384 JS |
52 | { |
53 | private: | |
72045d57 VZ |
54 | // a wxArray provides a constant access time rather than a linear time |
55 | // like for linked lists. | |
56 | wxArrayPtrVoid m_frames; | |
661dc384 | 57 | |
e4b8154a | 58 | // decoder state vars |
661dc384 JS |
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 */ | |
76443e70 GRG |
62 | unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */ |
63 | unsigned char *m_bufp; /* pointer to next byte in buffer */ | |
661dc384 | 64 | |
661dc384 | 65 | private: |
72045d57 VZ |
66 | int getcode(wxInputStream& stream, int bits, int abfin); |
67 | wxGIFErrorCode dgif(wxInputStream& stream, GIFImage *img, int interl, int bits); | |
661dc384 | 68 | |
809e8e44 | 69 | public: |
661dc384 | 70 | // get data of current frame |
72045d57 VZ |
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; | |
75 | ||
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; | |
80 | ||
81 | // GIFs can contain both static images and animations | |
82 | bool IsAnimation() const | |
83 | { return m_nFrames > 1; } | |
e4b8154a GRG |
84 | |
85 | public: | |
86 | // constructor, destructor, etc. | |
72045d57 | 87 | wxGIFDecoder(); |
e4b8154a | 88 | ~wxGIFDecoder(); |
72045d57 VZ |
89 | |
90 | // load function which returns more info than just Load(): | |
91 | wxGIFErrorCode LoadGIF( wxInputStream& stream ); | |
92 | ||
93 | // free all internal frames | |
e4b8154a GRG |
94 | void Destroy(); |
95 | ||
72045d57 VZ |
96 | public: // implementation of wxAnimationDecoder's pure virtuals |
97 | ||
98 | virtual bool CanRead( wxInputStream& stream ) const; | |
99 | virtual bool Load( wxInputStream& stream ) | |
100 | { return LoadGIF(stream) == wxGIF_OK; } | |
101 | ||
102 | bool ConvertToImage(size_t frame, wxImage *image) const; | |
22f3361e | 103 | |
72045d57 VZ |
104 | wxAnimationDecoder *Clone() const |
105 | { return new wxGIFDecoder; } | |
106 | wxAnimationType GetType() const | |
107 | { return wxANIMATION_TYPE_GIF; } | |
108 | ||
109 | private: | |
22f3361e | 110 | DECLARE_NO_COPY_CLASS(wxGIFDecoder) |
661dc384 JS |
111 | }; |
112 | ||
113 | ||
83413d6d | 114 | #endif // wxUSE_STREAM && wxUSE_GIF |
661dc384 JS |
115 | #endif // _WX_GIFDECOD_H |
116 |