1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/animdecod.h
3 // Purpose: wxAnimationDecoder
4 // Author: Francesco Montorsi
6 // Copyright: (c) 2006 Francesco Montorsi
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_ANIMDECOD_H
11 #define _WX_ANIMDECOD_H
17 #include "wx/colour.h"
18 #include "wx/gdicmn.h"
20 class WXDLLIMPEXP_FWD_BASE wxInputStream
;
21 class WXDLLIMPEXP_FWD_CORE wxImage
;
25 Differences between a wxAnimationDecoder and a wxImageHandler:
27 1) wxImageHandlers always load an input stream directly into a given wxImage
28 object converting from the format-specific data representation to the
29 wxImage native format (RGB24).
30 wxAnimationDecoders always load an input stream using some optimized format
31 to store it which is format-depedent. This allows to store a (possibly big)
32 animation using a format which is a good compromise between required memory
33 and time required to blit in on the screen.
35 2) wxAnimationDecoders contain the animation data in some internal var.
36 That's why they derive from wxObjectRefData: they are data which can be shared.
38 3) wxAnimationDecoders can be used by a wxImageHandler to retrieve a frame
39 in wxImage format; the viceversa cannot be done.
41 4) wxAnimationDecoders are decoders only, thus do not support save features.
43 5) wxAnimationDecoders are directly used by wxAnimation (generic implementation)
44 as wxObjectRefData while they need to be 'wrapped' by a wxImageHandler for
50 // --------------------------------------------------------------------------
52 // --------------------------------------------------------------------------
54 // NB: the values of these enum items are not casual but coincide with the
55 // GIF disposal codes. Do not change them !!
56 enum wxAnimationDisposal
58 // No disposal specified. The decoder is not required to take any action.
59 wxANIM_UNSPECIFIED
= -1,
61 // Do not dispose. The graphic is to be left in place.
62 wxANIM_DONOTREMOVE
= 0,
64 // Restore to background color. The area used by the graphic must be
65 // restored to the background color.
66 wxANIM_TOBACKGROUND
= 1,
68 // Restore to previous. The decoder is required to restore the area
69 // overwritten by the graphic with what was there prior to rendering the graphic.
75 wxANIMATION_TYPE_INVALID
,
83 // --------------------------------------------------------------------------
84 // wxAnimationDecoder class
85 // --------------------------------------------------------------------------
87 class WXDLLEXPORT wxAnimationDecoder
: public wxObjectRefData
92 m_background
= wxNullColour
;
95 virtual ~wxAnimationDecoder() { }
98 virtual bool Load( wxInputStream
& stream
) = 0;
99 virtual bool CanRead( wxInputStream
& stream
) const = 0;
101 virtual wxAnimationDecoder
*Clone() const = 0;
102 virtual wxAnimationType
GetType() const = 0;
104 // convert given frame to wxImage
105 virtual bool ConvertToImage(unsigned int frame
, wxImage
*image
) const = 0;
108 // frame specific data getters
110 // not all frames may be of the same size; e.g. GIF allows to
111 // specify that between two frames only a smaller portion of the
112 // entire animation has changed.
113 virtual wxSize
GetFrameSize(unsigned int frame
) const = 0;
115 // the position of this frame in case it's not as big as m_szAnimation
116 // or wxPoint(0,0) otherwise.
117 virtual wxPoint
GetFramePosition(unsigned int frame
) const = 0;
119 // what should be done after displaying this frame.
120 virtual wxAnimationDisposal
GetDisposalMethod(unsigned int frame
) const = 0;
122 // the number of milliseconds this frame should be displayed.
123 // if returns -1 then the frame must be displayed forever.
124 virtual long GetDelay(unsigned int frame
) const = 0;
126 // the transparent colour for this frame if any or wxNullColour.
127 virtual wxColour
GetTransparentColour(unsigned int frame
) const = 0;
130 wxSize
GetAnimationSize() const { return m_szAnimation
; }
131 wxColour
GetBackgroundColour() const { return m_background
; }
132 unsigned int GetFrameCount() const { return m_nFrames
; }
135 wxSize m_szAnimation
;
136 unsigned int m_nFrames
;
138 // this is the colour to use for the wxANIM_TOBACKGROUND disposal.
139 // if not specified by the animation, it's set to wxNullColour
140 wxColour m_background
;
144 #endif // wxUSE_STREAMS
145 #endif // _WX_ANIMDECOD_H