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