]>
Commit | Line | Data |
---|---|---|
72045d57 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/animdecod.h | |
3 | // Purpose: wxAnimationDecoder | |
4 | // Author: Francesco Montorsi | |
5 | // CVS-ID: $Id$ | |
6 | // Copyright: (c) 2006 Francesco Montorsi | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_ANIMDECOD_H | |
11 | #define _WX_ANIMDECOD_H | |
12 | ||
13 | #include "wx/defs.h" | |
14 | ||
68623832 | 15 | #if wxUSE_STREAMS |
72045d57 | 16 | |
ff1dadae | 17 | #include "wx/colour.h" |
c2f12218 | 18 | #include "wx/gdicmn.h" |
53c2cdb0 | 19 | #include "wx/log.h" |
e6bfb8a1 | 20 | #include "wx/stream.h" |
c2f12218 | 21 | |
b5dbe15d VS |
22 | class WXDLLIMPEXP_FWD_BASE wxInputStream; |
23 | class WXDLLIMPEXP_FWD_CORE wxImage; | |
72045d57 VZ |
24 | |
25 | /* | |
26 | ||
27 | Differences between a wxAnimationDecoder and a wxImageHandler: | |
28 | ||
29 | 1) wxImageHandlers always load an input stream directly into a given wxImage | |
30 | object converting from the format-specific data representation to the | |
31 | wxImage native format (RGB24). | |
32 | wxAnimationDecoders always load an input stream using some optimized format | |
33 | to store it which is format-depedent. This allows to store a (possibly big) | |
34 | animation using a format which is a good compromise between required memory | |
d8359d3c | 35 | and time required to blit it on the screen. |
72045d57 | 36 | |
d8359d3c | 37 | 2) wxAnimationDecoders contain the animation data in some internal variable. |
72045d57 VZ |
38 | That's why they derive from wxObjectRefData: they are data which can be shared. |
39 | ||
40 | 3) wxAnimationDecoders can be used by a wxImageHandler to retrieve a frame | |
41 | in wxImage format; the viceversa cannot be done. | |
42 | ||
d8359d3c | 43 | 4) wxAnimationDecoders are decoders only, thus they do not support save features. |
72045d57 VZ |
44 | |
45 | 5) wxAnimationDecoders are directly used by wxAnimation (generic implementation) | |
46 | as wxObjectRefData while they need to be 'wrapped' by a wxImageHandler for | |
47 | wxImage uses. | |
48 | ||
49 | */ | |
50 | ||
51 | ||
52 | // -------------------------------------------------------------------------- | |
53 | // Constants | |
54 | // -------------------------------------------------------------------------- | |
55 | ||
56 | // NB: the values of these enum items are not casual but coincide with the | |
57 | // GIF disposal codes. Do not change them !! | |
58 | enum wxAnimationDisposal | |
59 | { | |
60 | // No disposal specified. The decoder is not required to take any action. | |
61 | wxANIM_UNSPECIFIED = -1, | |
62 | ||
63 | // Do not dispose. The graphic is to be left in place. | |
64 | wxANIM_DONOTREMOVE = 0, | |
65 | ||
d8359d3c | 66 | // Restore to background color. The area used by the graphic must be |
72045d57 VZ |
67 | // restored to the background color. |
68 | wxANIM_TOBACKGROUND = 1, | |
69 | ||
d8359d3c | 70 | // Restore to previous. The decoder is required to restore the area |
72045d57 VZ |
71 | // overwritten by the graphic with what was there prior to rendering the graphic. |
72 | wxANIM_TOPREVIOUS = 2 | |
73 | }; | |
74 | ||
75 | enum wxAnimationType | |
76 | { | |
77 | wxANIMATION_TYPE_INVALID, | |
78 | wxANIMATION_TYPE_GIF, | |
79 | wxANIMATION_TYPE_ANI, | |
80 | ||
81 | wxANIMATION_TYPE_ANY | |
82 | }; | |
83 | ||
84 | ||
85 | // -------------------------------------------------------------------------- | |
86 | // wxAnimationDecoder class | |
87 | // -------------------------------------------------------------------------- | |
88 | ||
7776d70e | 89 | class WXDLLIMPEXP_CORE wxAnimationDecoder : public wxObjectRefData |
72045d57 | 90 | { |
870cf35c VZ |
91 | public: |
92 | wxAnimationDecoder() | |
93 | { | |
870cf35c VZ |
94 | m_nFrames = 0; |
95 | } | |
870cf35c VZ |
96 | |
97 | virtual bool Load( wxInputStream& stream ) = 0; | |
03647350 | 98 | |
8faef7cc FM |
99 | bool CanRead( wxInputStream& stream ) const |
100 | { | |
101 | // NOTE: this code is the same of wxImageHandler::CallDoCanRead | |
03647350 | 102 | |
8faef7cc FM |
103 | if ( !stream.IsSeekable() ) |
104 | return false; // can't test unseekable stream | |
105 | ||
106 | wxFileOffset posOld = stream.TellI(); | |
107 | bool ok = DoCanRead(stream); | |
108 | ||
109 | // restore the old position to be able to test other formats and so on | |
110 | if ( stream.SeekI(posOld) == wxInvalidOffset ) | |
111 | { | |
9a83f860 | 112 | wxLogDebug(wxT("Failed to rewind the stream in wxAnimationDecoder!")); |
8faef7cc FM |
113 | |
114 | // reading would fail anyhow as we're not at the right position | |
115 | return false; | |
116 | } | |
117 | ||
118 | return ok; | |
119 | } | |
870cf35c VZ |
120 | |
121 | virtual wxAnimationDecoder *Clone() const = 0; | |
122 | virtual wxAnimationType GetType() const = 0; | |
123 | ||
124 | // convert given frame to wxImage | |
125 | virtual bool ConvertToImage(unsigned int frame, wxImage *image) const = 0; | |
72045d57 | 126 | |
72045d57 | 127 | |
870cf35c | 128 | // frame specific data getters |
72045d57 VZ |
129 | |
130 | // not all frames may be of the same size; e.g. GIF allows to | |
131 | // specify that between two frames only a smaller portion of the | |
132 | // entire animation has changed. | |
870cf35c | 133 | virtual wxSize GetFrameSize(unsigned int frame) const = 0; |
72045d57 VZ |
134 | |
135 | // the position of this frame in case it's not as big as m_szAnimation | |
136 | // or wxPoint(0,0) otherwise. | |
870cf35c | 137 | virtual wxPoint GetFramePosition(unsigned int frame) const = 0; |
72045d57 VZ |
138 | |
139 | // what should be done after displaying this frame. | |
870cf35c | 140 | virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const = 0; |
72045d57 VZ |
141 | |
142 | // the number of milliseconds this frame should be displayed. | |
143 | // if returns -1 then the frame must be displayed forever. | |
870cf35c | 144 | virtual long GetDelay(unsigned int frame) const = 0; |
72045d57 | 145 | |
05a98b6d | 146 | // the transparent colour for this frame if any or wxNullColour. |
870cf35c | 147 | virtual wxColour GetTransparentColour(unsigned int frame) const = 0; |
05a98b6d | 148 | |
72045d57 VZ |
149 | // get global data |
150 | wxSize GetAnimationSize() const { return m_szAnimation; } | |
151 | wxColour GetBackgroundColour() const { return m_background; } | |
870cf35c | 152 | unsigned int GetFrameCount() const { return m_nFrames; } |
72045d57 | 153 | |
870cf35c | 154 | protected: |
8faef7cc FM |
155 | // checks the signature of the data in the given stream and returns true if it |
156 | // appears to be a valid animation format recognized by the animation decoder; | |
157 | // this function should modify the stream current position without taking care | |
158 | // of restoring it since CanRead() will do it. | |
159 | virtual bool DoCanRead(wxInputStream& stream) const = 0; | |
03647350 | 160 | |
870cf35c VZ |
161 | wxSize m_szAnimation; |
162 | unsigned int m_nFrames; | |
72045d57 | 163 | |
870cf35c VZ |
164 | // this is the colour to use for the wxANIM_TOBACKGROUND disposal. |
165 | // if not specified by the animation, it's set to wxNullColour | |
166 | wxColour m_background; | |
72045d57 VZ |
167 | }; |
168 | ||
b0f76951 | 169 | #endif // wxUSE_STREAMS |
7776d70e | 170 | |
72045d57 VZ |
171 | #endif // _WX_ANIMDECOD_H |
172 |