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