1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxImage class
4 // Author: Robert Roebling
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
14 #pragma interface "image.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/gdicmn.h"
21 #include "wx/bitmap.h"
24 # include "wx/stream.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 class WXDLLEXPORT wxImageHandler
;
33 class WXDLLEXPORT wxPNGHandler
;
36 class WXDLLEXPORT wxJPEGHandler
;
38 class WXDLLEXPORT wxBMPHandler
;
40 class WXDLLEXPORT wxGIFHandler
;
43 class WXDLLEXPORT wxPNMHandler
;
46 class WXDLLEXPORT wxPCXHandler
;
48 class WXDLLEXPORT wxImage
;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 class WXDLLEXPORT wxImageHandler
: public wxObject
56 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
59 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
62 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
63 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
65 bool CanRead( wxInputStream
& stream
) { return DoCanRead(stream
); }
66 bool CanRead( const wxString
& name
);
69 void SetName(const wxString
& name
) { m_name
= name
; }
70 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
71 void SetType(long type
) { m_type
= type
; }
72 void SetMimeType(const wxString
& type
) { m_mime
= type
; }
73 wxString
GetName() const { return m_name
; }
74 wxString
GetExtension() const { return m_extension
; }
75 long GetType() const { return m_type
; }
76 wxString
GetMimeType() const { return m_mime
; }
79 virtual bool DoCanRead( wxInputStream
& stream
) = 0;
88 //-----------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
93 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
95 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
103 m_type
= wxBITMAP_TYPE_PNG
;
104 m_mime
= "image/png";
108 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
109 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
110 virtual bool DoCanRead( wxInputStream
& stream
);
115 //-----------------------------------------------------------------------------
117 //-----------------------------------------------------------------------------
120 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
122 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
126 inline wxJPEGHandler()
128 m_name
= "JPEG file";
130 m_type
= wxBITMAP_TYPE_JPEG
;
131 m_mime
= "image/jpeg";
135 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
136 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
137 virtual bool DoCanRead( wxInputStream
& stream
);
142 //-----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
146 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
148 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
152 inline wxBMPHandler()
156 m_type
= wxBITMAP_TYPE_BMP
;
157 m_mime
= "image/bmp";
161 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
162 virtual bool DoCanRead( wxInputStream
& stream
);
166 //-----------------------------------------------------------------------------
168 //-----------------------------------------------------------------------------
172 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
174 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
178 inline wxGIFHandler()
182 m_type
= wxBITMAP_TYPE_GIF
;
183 m_mime
= "image/gif";
187 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
188 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
189 virtual bool DoCanRead( wxInputStream
& stream
);
194 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
199 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
201 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
205 inline wxPNMHandler()
209 m_type
= wxBITMAP_TYPE_PNM
;
210 m_mime
= "image/pnm";
214 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
215 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
216 virtual bool DoCanRead( wxInputStream
& stream
);
221 //-----------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
226 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
228 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
232 inline wxPCXHandler()
236 m_type
= wxBITMAP_TYPE_PCX
;
237 m_mime
= "image/pcx";
241 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
242 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
243 virtual bool DoCanRead( wxInputStream
& stream
);
244 #endif // wxUSE_STREAMS
248 //-----------------------------------------------------------------------------
250 //-----------------------------------------------------------------------------
252 class WXDLLEXPORT wxImage
: public wxObject
254 DECLARE_DYNAMIC_CLASS(wxImage
)
256 friend class WXDLLEXPORT wxImageHandler
;
261 wxImage( int width
, int height
);
262 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
263 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
264 wxImage( const wxString
& name
, const wxString
& mimetype
);
265 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
267 wxImage( const wxImage
& image
);
268 wxImage( const wxImage
* image
);
270 // these functions get implemented in /src/(platform)/bitmap.cpp
271 wxImage( const wxBitmap
&bitmap
);
272 operator wxBitmap() const { return ConvertToBitmap(); }
273 wxBitmap
ConvertToBitmap() const;
275 void Create( int width
, int height
);
278 // return the new image with size width*height
279 wxImage
GetSubImage( const wxRect
& ) const;
281 // return the new image with size width*height
282 wxImage
Scale( int width
, int height
) const;
284 // rescales the image in place
285 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
287 // these routines are slow but safe
288 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
289 unsigned char GetRed( int x
, int y
);
290 unsigned char GetGreen( int x
, int y
);
291 unsigned char GetBlue( int x
, int y
);
293 static bool CanRead( const wxString
& name
);
294 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
295 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
298 static bool CanRead( wxInputStream
& stream
);
299 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
300 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
303 virtual bool SaveFile( const wxString
& name
, int type
);
304 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
307 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
308 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
312 int GetWidth() const;
313 int GetHeight() const;
315 char unsigned *GetData() const;
316 void SetData( char unsigned *data
);
318 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
319 unsigned char GetMaskRed() const;
320 unsigned char GetMaskGreen() const;
321 unsigned char GetMaskBlue() const;
322 void SetMask( bool mask
= TRUE
);
323 bool HasMask() const;
325 wxImage
& operator = (const wxImage
& image
)
327 if ( (*this) != image
)
332 bool operator == (const wxImage
& image
)
333 { return m_refData
== image
.m_refData
; }
334 bool operator != (const wxImage
& image
)
335 { return m_refData
!= image
.m_refData
; }
337 static wxList
& GetHandlers() { return sm_handlers
; }
338 static void AddHandler( wxImageHandler
*handler
);
339 static void InsertHandler( wxImageHandler
*handler
);
340 static bool RemoveHandler( const wxString
& name
);
341 static wxImageHandler
*FindHandler( const wxString
& name
);
342 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
343 static wxImageHandler
*FindHandler( long imageType
);
344 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
346 static void CleanUpHandlers();
347 static void InitStandardHandlers();
351 static wxList sm_handlers
;
355 extern void WXDLLEXPORT
wxInitAllImageHandlers();