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