]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: image.h | |
3 | // Purpose: wxImage class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_IMAGE_H_ | |
11 | #define _WX_IMAGE_H_ | |
12 | ||
13 | #ifdef __GNUG__ | |
14 | #pragma interface "image.h" | |
15 | #endif | |
16 | ||
17 | #include "wx/setup.h" | |
18 | #include "wx/object.h" | |
19 | #include "wx/string.h" | |
20 | #include "wx/gdicmn.h" | |
21 | #include "wx/bitmap.h" | |
22 | ||
23 | #if wxUSE_STREAMS | |
24 | # include "wx/stream.h" | |
25 | #endif | |
26 | ||
27 | #if wxUSE_IMAGE | |
28 | ||
29 | //----------------------------------------------------------------------------- | |
30 | // classes | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | class WXDLLEXPORT wxImageHandler; | |
34 | class WXDLLEXPORT wxImage; | |
35 | ||
36 | //----------------------------------------------------------------------------- | |
37 | // wxImageHandler | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
40 | class WXDLLEXPORT wxImageHandler: public wxObject | |
41 | { | |
42 | public: | |
43 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } | |
44 | ||
45 | #if wxUSE_STREAMS | |
46 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); | |
47 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
48 | ||
49 | virtual int GetImageCount( wxInputStream& stream ); | |
50 | ||
51 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } | |
52 | bool CanRead( const wxString& name ); | |
53 | #endif // wxUSE_STREAMS | |
54 | ||
55 | void SetName(const wxString& name) { m_name = name; } | |
56 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
57 | void SetType(long type) { m_type = type; } | |
58 | void SetMimeType(const wxString& type) { m_mime = type; } | |
59 | wxString GetName() const { return m_name; } | |
60 | wxString GetExtension() const { return m_extension; } | |
61 | long GetType() const { return m_type; } | |
62 | wxString GetMimeType() const { return m_mime; } | |
63 | ||
64 | protected: | |
65 | #if wxUSE_STREAMS | |
66 | virtual bool DoCanRead( wxInputStream& stream ) = 0; | |
67 | #endif // wxUSE_STREAMS | |
68 | ||
69 | wxString m_name; | |
70 | wxString m_extension; | |
71 | wxString m_mime; | |
72 | long m_type; | |
73 | ||
74 | private: | |
75 | DECLARE_CLASS(wxImageHandler) | |
76 | }; | |
77 | ||
78 | //----------------------------------------------------------------------------- | |
79 | // wxImage | |
80 | //----------------------------------------------------------------------------- | |
81 | ||
82 | class WXDLLEXPORT wxHNode | |
83 | { | |
84 | public: | |
85 | unsigned long index; | |
86 | unsigned long value; | |
87 | }; | |
88 | ||
89 | class WXDLLEXPORT wxImage: public wxObject | |
90 | { | |
91 | public: | |
92 | wxImage(); | |
93 | wxImage( int width, int height ); | |
94 | wxImage( int width, int height, unsigned char* data, bool static_data = FALSE ); | |
95 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
96 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
97 | wxImage( const wxString& name, const wxString& mimetype ); | |
98 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
99 | ||
100 | wxImage( const wxImage& image ); | |
101 | wxImage( const wxImage* image ); | |
102 | ||
103 | #if wxUSE_GUI | |
104 | // convertion to/from wxBitmap (deprecated, use wxBitmap's methods instead): | |
105 | wxImage( const wxBitmap &bitmap ); | |
106 | wxBitmap ConvertToBitmap() const; | |
107 | #ifdef __WXGTK__ | |
108 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; | |
109 | #endif | |
110 | #endif | |
111 | ||
112 | void Create( int width, int height ); | |
113 | void Create( int width, int height, unsigned char* data, bool static_data = FALSE ); | |
114 | void Destroy(); | |
115 | ||
116 | // creates an identical copy of the image (the = operator | |
117 | // just raises the ref count) | |
118 | wxImage Copy() const; | |
119 | ||
120 | // return the new image with size width*height | |
121 | wxImage GetSubImage( const wxRect& ) const; | |
122 | ||
123 | // pastes image into this instance and takes care of | |
124 | // the mask colour and out of bounds problems | |
125 | void Paste( const wxImage &image, int x, int y ); | |
126 | ||
127 | // return the new image with size width*height | |
128 | wxImage Scale( int width, int height ) const; | |
129 | ||
130 | // rescales the image in place | |
131 | wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); } | |
132 | ||
133 | // Rotates the image about the given point, 'angle' radians. | |
134 | // Returns the rotated image, leaving this image intact. | |
135 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
136 | bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const; | |
137 | ||
138 | wxImage Rotate90( bool clockwise = TRUE ) const; | |
139 | wxImage Mirror( bool horizontally = TRUE ) const; | |
140 | ||
141 | // replace one colour with another | |
142 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
143 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
144 | ||
145 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) | |
146 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; | |
147 | ||
148 | // these routines are slow but safe | |
149 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
150 | unsigned char GetRed( int x, int y ) const; | |
151 | unsigned char GetGreen( int x, int y ) const; | |
152 | unsigned char GetBlue( int x, int y ) const; | |
153 | ||
154 | static bool CanRead( const wxString& name ); | |
155 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
156 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); | |
157 | ||
158 | #if wxUSE_STREAMS | |
159 | static bool CanRead( wxInputStream& stream ); | |
160 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
161 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); | |
162 | #endif | |
163 | ||
164 | virtual bool SaveFile( const wxString& name, int type ); | |
165 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); | |
166 | ||
167 | #if wxUSE_STREAMS | |
168 | virtual bool SaveFile( wxOutputStream& stream, int type ); | |
169 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); | |
170 | #endif | |
171 | ||
172 | bool Ok() const; | |
173 | int GetWidth() const; | |
174 | int GetHeight() const; | |
175 | ||
176 | char unsigned *GetData() const; | |
177 | void SetData( char unsigned *data ); | |
178 | void SetData( char unsigned *data, int new_width, int new_height ); | |
179 | ||
180 | // Mask functions | |
181 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
182 | unsigned char GetMaskRed() const; | |
183 | unsigned char GetMaskGreen() const; | |
184 | unsigned char GetMaskBlue() const; | |
185 | void SetMask( bool mask = TRUE ); | |
186 | bool HasMask() const; | |
187 | ||
188 | #if wxUSE_PALETTE | |
189 | // Palette functions | |
190 | bool HasPalette() const; | |
191 | const wxPalette& GetPalette() const; | |
192 | void SetPalette(const wxPalette& palette); | |
193 | #endif // wxUSE_PALETTE | |
194 | ||
195 | // Option functions (arbitrary name/value mapping) | |
196 | void SetOption(const wxString& name, const wxString& value); | |
197 | void SetOption(const wxString& name, int value); | |
198 | wxString GetOption(const wxString& name) const; | |
199 | int GetOptionInt(const wxString& name) const; | |
200 | bool HasOption(const wxString& name) const; | |
201 | ||
202 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); | |
203 | unsigned long ComputeHistogram( wxHashTable &h ); | |
204 | ||
205 | wxImage& operator = (const wxImage& image) | |
206 | { | |
207 | if ( (*this) != image ) | |
208 | Ref(image); | |
209 | return *this; | |
210 | } | |
211 | ||
212 | bool operator == (const wxImage& image) | |
213 | { return m_refData == image.m_refData; } | |
214 | bool operator != (const wxImage& image) | |
215 | { return m_refData != image.m_refData; } | |
216 | ||
217 | static wxList& GetHandlers() { return sm_handlers; } | |
218 | static void AddHandler( wxImageHandler *handler ); | |
219 | static void InsertHandler( wxImageHandler *handler ); | |
220 | static bool RemoveHandler( const wxString& name ); | |
221 | static wxImageHandler *FindHandler( const wxString& name ); | |
222 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
223 | static wxImageHandler *FindHandler( long imageType ); | |
224 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); | |
225 | ||
226 | static void CleanUpHandlers(); | |
227 | static void InitStandardHandlers(); | |
228 | ||
229 | protected: | |
230 | static wxList sm_handlers; | |
231 | ||
232 | private: | |
233 | friend class WXDLLEXPORT wxImageHandler; | |
234 | ||
235 | DECLARE_DYNAMIC_CLASS(wxImage) | |
236 | }; | |
237 | ||
238 | ||
239 | extern void WXDLLEXPORT wxInitAllImageHandlers(); | |
240 | ||
241 | WXDLLEXPORT_DATA(extern wxImage) wxNullImage; | |
242 | ||
243 | //----------------------------------------------------------------------------- | |
244 | // wxImage handlers | |
245 | //----------------------------------------------------------------------------- | |
246 | ||
247 | #include "wx/imagbmp.h" | |
248 | #include "wx/imagpng.h" | |
249 | #include "wx/imaggif.h" | |
250 | #include "wx/imagpcx.h" | |
251 | #include "wx/imagjpeg.h" | |
252 | #include "wx/imagtiff.h" | |
253 | #include "wx/imagpnm.h" | |
254 | #include "wx/imagxpm.h" | |
255 | ||
256 | #endif // wxUSE_IMAGE | |
257 | ||
258 | #endif | |
259 | // _WX_IMAGE_H_ | |
260 |