]>
Commit | Line | Data |
---|---|---|
01111366 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: image.h | |
3 | // Purpose: wxImage class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert Roebling | |
23280650 | 7 | // Licence: wxWindows licence |
01111366 RR |
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" | |
23280650 | 21 | #include "wx/bitmap.h" |
bf38cbff JS |
22 | |
23 | #if wxUSE_STREAMS | |
b9943f8e | 24 | # include "wx/stream.h" |
bf38cbff | 25 | #endif |
01111366 RR |
26 | |
27 | //----------------------------------------------------------------------------- | |
28 | // classes | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | class WXDLLEXPORT wxImageHandler; | |
9838df2c | 32 | #if wxUSE_LIBPNG |
01111366 | 33 | class WXDLLEXPORT wxPNGHandler; |
ac57418f | 34 | #endif |
56b9c741 VS |
35 | #if wxUSE_LIBJPEG |
36 | class WXDLLEXPORT wxJPEGHandler; | |
37 | #endif | |
01111366 | 38 | class WXDLLEXPORT wxBMPHandler; |
b9943f8e GRG |
39 | class WXDLLEXPORT wxGIFHandler; |
40 | class WXDLLEXPORT wxPNMHandler; | |
41 | class WXDLLEXPORT wxPCXHandler; | |
01111366 RR |
42 | class WXDLLEXPORT wxImage; |
43 | ||
44 | //----------------------------------------------------------------------------- | |
45 | // wxImageHandler | |
46 | //----------------------------------------------------------------------------- | |
47 | ||
48 | class WXDLLEXPORT wxImageHandler: public wxObject | |
49 | { | |
50 | DECLARE_DYNAMIC_CLASS(wxImageHandler) | |
23280650 | 51 | |
01111366 RR |
52 | public: |
53 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } | |
54 | ||
bf38cbff | 55 | #if wxUSE_STREAMS |
deb2fec0 SB |
56 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
57 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
0828c087 VS |
58 | |
59 | virtual bool CanRead( wxInputStream& stream ); | |
60 | virtual bool CanRead( const wxString& name ); | |
bf38cbff | 61 | #endif |
01111366 RR |
62 | |
63 | inline void SetName(const wxString& name) { m_name = name; } | |
64 | inline void SetExtension(const wxString& ext) { m_extension = ext; } | |
65 | inline void SetType(long type) { m_type = type; } | |
9e9ee68e | 66 | inline void SetMimeType(const wxString& type) { m_mime = type; } |
01111366 RR |
67 | inline wxString GetName() const { return m_name; } |
68 | inline wxString GetExtension() const { return m_extension; } | |
69 | inline long GetType() const { return m_type; } | |
9e9ee68e VS |
70 | inline wxString GetMimeType() const { return m_mime; } |
71 | ||
01111366 RR |
72 | protected: |
73 | wxString m_name; | |
74 | wxString m_extension; | |
9e9ee68e | 75 | wxString m_mime; |
01111366 | 76 | long m_type; |
23280650 | 77 | |
01111366 RR |
78 | }; |
79 | ||
80 | //----------------------------------------------------------------------------- | |
81 | // wxPNGHandler | |
82 | //----------------------------------------------------------------------------- | |
83 | ||
9838df2c | 84 | #if wxUSE_LIBPNG |
01111366 RR |
85 | class WXDLLEXPORT wxPNGHandler: public wxImageHandler |
86 | { | |
87 | DECLARE_DYNAMIC_CLASS(wxPNGHandler) | |
23280650 | 88 | |
01111366 RR |
89 | public: |
90 | ||
fd0eed64 RR |
91 | inline wxPNGHandler() |
92 | { | |
93 | m_name = "PNG file"; | |
94 | m_extension = "png"; | |
95 | m_type = wxBITMAP_TYPE_PNG; | |
9e9ee68e | 96 | m_mime = "image/png"; |
fd0eed64 RR |
97 | }; |
98 | ||
bf38cbff | 99 | #if wxUSE_STREAMS |
deb2fec0 SB |
100 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
101 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
0828c087 | 102 | virtual bool CanRead( wxInputStream& stream ); |
bf38cbff | 103 | #endif |
01111366 | 104 | }; |
ac57418f | 105 | #endif |
01111366 | 106 | |
56b9c741 VS |
107 | //----------------------------------------------------------------------------- |
108 | // wxJPEGHandler | |
109 | //----------------------------------------------------------------------------- | |
110 | ||
9ef4a31e | 111 | #if wxUSE_LIBJPEG |
56b9c741 VS |
112 | class WXDLLEXPORT wxJPEGHandler: public wxImageHandler |
113 | { | |
114 | DECLARE_DYNAMIC_CLASS(wxJPEGHandler) | |
115 | ||
116 | public: | |
117 | ||
118 | inline wxJPEGHandler() | |
119 | { | |
120 | m_name = "JPEG file"; | |
121 | m_extension = "jpg"; | |
122 | m_type = wxBITMAP_TYPE_JPEG; | |
9e9ee68e | 123 | m_mime = "image/jpeg"; |
56b9c741 VS |
124 | }; |
125 | ||
ce4169a4 | 126 | #if wxUSE_STREAMS |
deb2fec0 SB |
127 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
128 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
0828c087 | 129 | virtual bool CanRead( wxInputStream& stream ); |
ce4169a4 | 130 | #endif |
56b9c741 VS |
131 | }; |
132 | #endif | |
133 | ||
01111366 RR |
134 | //----------------------------------------------------------------------------- |
135 | // wxBMPHandler | |
136 | //----------------------------------------------------------------------------- | |
137 | ||
138 | class WXDLLEXPORT wxBMPHandler: public wxImageHandler | |
139 | { | |
140 | DECLARE_DYNAMIC_CLASS(wxBMPHandler) | |
23280650 | 141 | |
01111366 RR |
142 | public: |
143 | ||
fd0eed64 RR |
144 | inline wxBMPHandler() |
145 | { | |
146 | m_name = "BMP file"; | |
147 | m_extension = "bmp"; | |
148 | m_type = wxBITMAP_TYPE_BMP; | |
9e9ee68e | 149 | m_mime = "image/bmp"; |
fd0eed64 | 150 | }; |
01111366 | 151 | |
bf38cbff | 152 | #if wxUSE_STREAMS |
deb2fec0 | 153 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
0828c087 | 154 | virtual bool CanRead( wxInputStream& stream ); |
bf38cbff | 155 | #endif |
01111366 | 156 | }; |
fd0eed64 | 157 | |
e1929140 RR |
158 | //----------------------------------------------------------------------------- |
159 | // wxGIFHandler | |
160 | //----------------------------------------------------------------------------- | |
161 | ||
aa6d9706 GL |
162 | #if wxUSE_LIBGIF |
163 | ||
ce4169a4 RR |
164 | class WXDLLEXPORT wxGIFHandler : public wxImageHandler |
165 | { | |
166 | DECLARE_DYNAMIC_CLASS(wxGIFHandler) | |
167 | ||
168 | public: | |
169 | ||
170 | inline wxGIFHandler() | |
171 | { | |
172 | m_name = "GIF file"; | |
173 | m_extension = "gif"; | |
174 | m_type = wxBITMAP_TYPE_GIF; | |
175 | m_mime = "image/gif"; | |
176 | }; | |
e1929140 | 177 | |
ce4169a4 | 178 | #if wxUSE_STREAMS |
deb2fec0 SB |
179 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
180 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
0828c087 | 181 | virtual bool CanRead( wxInputStream& stream ); |
ce4169a4 RR |
182 | #endif |
183 | }; | |
e1929140 | 184 | |
aa6d9706 GL |
185 | #endif |
186 | ||
7b2471a0 SB |
187 | //----------------------------------------------------------------------------- |
188 | // wxPNMHandler | |
189 | //----------------------------------------------------------------------------- | |
190 | ||
191 | class WXDLLEXPORT wxPNMHandler : public wxImageHandler | |
192 | { | |
193 | DECLARE_DYNAMIC_CLASS(wxPNMHandler) | |
194 | ||
195 | public: | |
196 | ||
197 | inline wxPNMHandler() | |
198 | { | |
199 | m_name = "PNM file"; | |
200 | m_extension = "pnm"; | |
201 | m_type = wxBITMAP_TYPE_PNM; | |
202 | m_mime = "image/pnm"; | |
203 | }; | |
204 | ||
205 | #if wxUSE_STREAMS | |
206 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); | |
207 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
0828c087 | 208 | virtual bool CanRead( wxInputStream& stream ); |
7b2471a0 SB |
209 | #endif |
210 | }; | |
211 | ||
b9943f8e GRG |
212 | //----------------------------------------------------------------------------- |
213 | // wxPCXHandler | |
214 | //----------------------------------------------------------------------------- | |
215 | ||
216 | class WXDLLEXPORT wxPCXHandler : public wxImageHandler | |
217 | { | |
218 | DECLARE_DYNAMIC_CLASS(wxPCXHandler) | |
219 | ||
220 | public: | |
221 | ||
222 | inline wxPCXHandler() | |
223 | { | |
224 | m_name = "PCX file"; | |
225 | m_extension = "pcx"; | |
226 | m_type = wxBITMAP_TYPE_PCX; | |
227 | m_mime = "image/pcx"; | |
228 | }; | |
229 | ||
230 | #if wxUSE_STREAMS | |
231 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); | |
232 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
233 | virtual bool CanRead( wxInputStream& stream ); | |
234 | #endif | |
235 | }; | |
236 | ||
01111366 RR |
237 | //----------------------------------------------------------------------------- |
238 | // wxImage | |
239 | //----------------------------------------------------------------------------- | |
240 | ||
241 | class WXDLLEXPORT wxImage: public wxObject | |
242 | { | |
243 | DECLARE_DYNAMIC_CLASS(wxImage) | |
244 | ||
245 | friend class WXDLLEXPORT wxImageHandler; | |
246 | ||
247 | public: | |
248 | ||
249 | wxImage(); | |
250 | wxImage( int width, int height ); | |
deb2fec0 SB |
251 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
252 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
9e9ee68e VS |
253 | wxImage( const wxString& name, const wxString& mimetype ); |
254 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
255 | ||
01111366 RR |
256 | wxImage( const wxImage& image ); |
257 | wxImage( const wxImage* image ); | |
23280650 VZ |
258 | |
259 | // these functions get implemented in /src/(platform)/bitmap.cpp | |
4bc67cc5 | 260 | wxImage( const wxBitmap &bitmap ); |
ce9a75d2 | 261 | operator wxBitmap() const { return ConvertToBitmap(); } |
4bc67cc5 | 262 | wxBitmap ConvertToBitmap() const; |
01111366 RR |
263 | |
264 | void Create( int width, int height ); | |
265 | void Destroy(); | |
23280650 | 266 | |
7b2471a0 SB |
267 | // return the new image with size width*height |
268 | wxImage GetSubImage( const wxRect& ) const; | |
269 | ||
ce9a75d2 VZ |
270 | // return the new image with size width*height |
271 | wxImage Scale( int width, int height ) const; | |
272 | ||
273 | // rescales the image in place | |
23280650 | 274 | void Rescale( int width, int height ) { *this = Scale(width, height); } |
ce9a75d2 | 275 | |
23280650 | 276 | // these routines are slow but safe |
ef539066 RR |
277 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); |
278 | unsigned char GetRed( int x, int y ); | |
279 | unsigned char GetGreen( int x, int y ); | |
280 | unsigned char GetBlue( int x, int y ); | |
23280650 | 281 | |
deb2fec0 | 282 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
9e9ee68e | 283 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
284 | |
285 | #if wxUSE_STREAMS | |
deb2fec0 | 286 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); |
9e9ee68e | 287 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); |
bf38cbff JS |
288 | #endif |
289 | ||
01111366 | 290 | virtual bool SaveFile( const wxString& name, int type ); |
9e9ee68e | 291 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
292 | |
293 | #if wxUSE_STREAMS | |
3d05544e | 294 | virtual bool SaveFile( wxOutputStream& stream, int type ); |
9e9ee68e | 295 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); |
bf38cbff | 296 | #endif |
01111366 RR |
297 | |
298 | bool Ok() const; | |
299 | int GetWidth() const; | |
300 | int GetHeight() const; | |
301 | ||
302 | char unsigned *GetData() const; | |
303 | void SetData( char unsigned *data ); | |
23280650 | 304 | |
01111366 RR |
305 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); |
306 | unsigned char GetMaskRed() const; | |
307 | unsigned char GetMaskGreen() const; | |
308 | unsigned char GetMaskBlue() const; | |
309 | void SetMask( bool mask = TRUE ); | |
310 | bool HasMask() const; | |
311 | ||
ce9a75d2 VZ |
312 | wxImage& operator = (const wxImage& image) |
313 | { | |
314 | if ( (*this) != image ) | |
ce3ed50d | 315 | Ref(image); |
ce9a75d2 VZ |
316 | return *this; |
317 | } | |
ce3ed50d | 318 | |
ce9a75d2 | 319 | bool operator == (const wxImage& image) |
01111366 | 320 | { return m_refData == image.m_refData; } |
23280650 | 321 | bool operator != (const wxImage& image) |
01111366 RR |
322 | { return m_refData != image.m_refData; } |
323 | ||
ce9a75d2 | 324 | static wxList& GetHandlers() { return sm_handlers; } |
01111366 RR |
325 | static void AddHandler( wxImageHandler *handler ); |
326 | static void InsertHandler( wxImageHandler *handler ); | |
327 | static bool RemoveHandler( const wxString& name ); | |
328 | static wxImageHandler *FindHandler( const wxString& name ); | |
329 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
330 | static wxImageHandler *FindHandler( long imageType ); | |
9e9ee68e VS |
331 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); |
332 | ||
01111366 | 333 | static void CleanUpHandlers(); |
fd0eed64 | 334 | static void InitStandardHandlers(); |
01111366 RR |
335 | |
336 | protected: | |
337 | ||
338 | static wxList sm_handlers; | |
23280650 | 339 | |
01111366 RR |
340 | }; |
341 | ||
342 | #endif | |
343 | // _WX_IMAGE_H_ | |
9e9ee68e | 344 |