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
15 #if wxUSE_STREAMS && wxUSE_GIF
17 #include "wx/stream.h"
22 Differences between a wxAnimationDecoder and a wxImageHandler:
24 1) wxImageHandlers always load an input stream directly into a given wxImage
25 object converting from the format-specific data representation to the
26 wxImage native format (RGB24).
27 wxAnimationDecoders always load an input stream using some optimized format
28 to store it which is format-depedent. This allows to store a (possibly big)
29 animation using a format which is a good compromise between required memory
30 and time required to blit in on the screen.
32 2) wxAnimationDecoders contain the animation data in some internal var.
33 That's why they derive from wxObjectRefData: they are data which can be shared.
35 3) wxAnimationDecoders can be used by a wxImageHandler to retrieve a frame
36 in wxImage format; the viceversa cannot be done.
38 4) wxAnimationDecoders are decoders only, thus do not support save features.
40 5) wxAnimationDecoders are directly used by wxAnimation (generic implementation)
41 as wxObjectRefData while they need to be 'wrapped' by a wxImageHandler for
47 // --------------------------------------------------------------------------
49 // --------------------------------------------------------------------------
51 // NB: the values of these enum items are not casual but coincide with the
52 // GIF disposal codes. Do not change them !!
53 enum wxAnimationDisposal
55 // No disposal specified. The decoder is not required to take any action.
56 wxANIM_UNSPECIFIED
= -1,
58 // Do not dispose. The graphic is to be left in place.
59 wxANIM_DONOTREMOVE
= 0,
61 // Restore to background color. The area used by the graphic must be
62 // restored to the background color.
63 wxANIM_TOBACKGROUND
= 1,
65 // Restore to previous. The decoder is required to restore the area
66 // overwritten by the graphic with what was there prior to rendering the graphic.
72 wxANIMATION_TYPE_INVALID
,
80 // --------------------------------------------------------------------------
81 // wxAnimationDecoder class
82 // --------------------------------------------------------------------------
84 class WXDLLEXPORT wxAnimationDecoder
: public wxObjectRefData
90 // this is the colour to use for the wxANIM_TOBACKGROUND disposal.
91 // if not specified by the animation, it's set to wxNullColour
92 wxColour m_background
;
94 public: // frame specific data getters
96 // not all frames may be of the same size; e.g. GIF allows to
97 // specify that between two frames only a smaller portion of the
98 // entire animation has changed.
99 virtual wxSize
GetFrameSize(size_t frame
) const = 0;
101 // the position of this frame in case it's not as big as m_szAnimation
102 // or wxPoint(0,0) otherwise.
103 virtual wxPoint
GetFramePosition(size_t frame
) const = 0;
105 // what should be done after displaying this frame.
106 virtual wxAnimationDisposal
GetDisposalMethod(size_t frame
) const = 0;
108 // the number of milliseconds this frame should be displayed.
109 // if returns -1 then the frame must be displayed forever.
110 virtual long GetDelay(size_t frame
) const = 0;
113 wxSize
GetAnimationSize() const { return m_szAnimation
; }
114 wxColour
GetBackgroundColour() const { return m_background
; }
115 size_t GetFrameCount() const { return m_nFrames
; }
120 m_background
= wxNullColour
;
123 ~wxAnimationDecoder() {}
126 virtual bool Load( wxInputStream
& stream
) = 0;
127 virtual bool CanRead( wxInputStream
& stream
) const = 0;
129 virtual wxAnimationDecoder
*Clone() const = 0;
130 virtual wxAnimationType
GetType() const = 0;
132 // convert given frame to wxImage
133 virtual bool ConvertToImage(size_t frame
, wxImage
*image
) const = 0;
137 #endif // wxUSE_STREAM && wxUSE_GIF
138 #endif // _WX_ANIMDECOD_H