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