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
;
39 class WXDLLEXPORT wxGIFHandler
;
40 class WXDLLEXPORT wxPNMHandler
;
41 class WXDLLEXPORT wxPCXHandler
;
42 class WXDLLEXPORT wxImage
;
44 //-----------------------------------------------------------------------------
46 //-----------------------------------------------------------------------------
48 class WXDLLEXPORT wxImageHandler
: public wxObject
50 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
53 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
56 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
57 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
59 virtual bool CanRead( wxInputStream
& stream
);
60 virtual bool CanRead( const wxString
& name
);
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
; }
66 inline void SetMimeType(const wxString
& type
) { m_mime
= type
; }
67 inline wxString
GetName() const { return m_name
; }
68 inline wxString
GetExtension() const { return m_extension
; }
69 inline long GetType() const { return m_type
; }
70 inline wxString
GetMimeType() const { return m_mime
; }
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
85 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
87 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
95 m_type
= wxBITMAP_TYPE_PNG
;
100 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
101 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
102 virtual bool CanRead( wxInputStream
& stream
);
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
112 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
114 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
118 inline wxJPEGHandler()
120 m_name
= "JPEG file";
122 m_type
= wxBITMAP_TYPE_JPEG
;
123 m_mime
= "image/jpeg";
127 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
128 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
129 virtual bool CanRead( wxInputStream
& stream
);
134 //-----------------------------------------------------------------------------
136 //-----------------------------------------------------------------------------
138 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
140 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
144 inline wxBMPHandler()
148 m_type
= wxBITMAP_TYPE_BMP
;
149 m_mime
= "image/bmp";
153 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
154 virtual bool CanRead( wxInputStream
& stream
);
158 //-----------------------------------------------------------------------------
160 //-----------------------------------------------------------------------------
162 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
164 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
168 inline wxGIFHandler()
172 m_type
= wxBITMAP_TYPE_GIF
;
173 m_mime
= "image/gif";
177 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
178 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
179 virtual bool CanRead( wxInputStream
& stream
);
183 //-----------------------------------------------------------------------------
185 //-----------------------------------------------------------------------------
187 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
189 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
193 inline wxPNMHandler()
197 m_type
= wxBITMAP_TYPE_PNM
;
198 m_mime
= "image/pnm";
202 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
203 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
204 virtual bool CanRead( wxInputStream
& stream
);
208 //-----------------------------------------------------------------------------
210 //-----------------------------------------------------------------------------
212 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
214 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
218 inline wxPCXHandler()
222 m_type
= wxBITMAP_TYPE_PCX
;
223 m_mime
= "image/pcx";
227 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
228 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
229 virtual bool CanRead( wxInputStream
& stream
);
233 //-----------------------------------------------------------------------------
235 //-----------------------------------------------------------------------------
237 class WXDLLEXPORT wxImage
: public wxObject
239 DECLARE_DYNAMIC_CLASS(wxImage
)
241 friend class WXDLLEXPORT wxImageHandler
;
246 wxImage( int width
, int height
);
247 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
248 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
249 wxImage( const wxString
& name
, const wxString
& mimetype
);
250 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
252 wxImage( const wxImage
& image
);
253 wxImage( const wxImage
* image
);
255 // these functions get implemented in /src/(platform)/bitmap.cpp
256 wxImage( const wxBitmap
&bitmap
);
257 operator wxBitmap() const { return ConvertToBitmap(); }
258 wxBitmap
ConvertToBitmap() const;
260 void Create( int width
, int height
);
263 // return the new image with size width*height
264 wxImage
GetSubImage( const wxRect
& ) const;
266 // return the new image with size width*height
267 wxImage
Scale( int width
, int height
) const;
269 // rescales the image in place
270 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
272 // these routines are slow but safe
273 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
274 unsigned char GetRed( int x
, int y
);
275 unsigned char GetGreen( int x
, int y
);
276 unsigned char GetBlue( int x
, int y
);
278 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
279 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
282 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
283 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
286 virtual bool SaveFile( const wxString
& name
, int type
);
287 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
290 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
291 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
295 int GetWidth() const;
296 int GetHeight() const;
298 char unsigned *GetData() const;
299 void SetData( char unsigned *data
);
301 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
302 unsigned char GetMaskRed() const;
303 unsigned char GetMaskGreen() const;
304 unsigned char GetMaskBlue() const;
305 void SetMask( bool mask
= TRUE
);
306 bool HasMask() const;
308 wxImage
& operator = (const wxImage
& image
)
310 if ( (*this) != image
)
315 bool operator == (const wxImage
& image
)
316 { return m_refData
== image
.m_refData
; }
317 bool operator != (const wxImage
& image
)
318 { return m_refData
!= image
.m_refData
; }
320 static wxList
& GetHandlers() { return sm_handlers
; }
321 static void AddHandler( wxImageHandler
*handler
);
322 static void InsertHandler( wxImageHandler
*handler
);
323 static bool RemoveHandler( const wxString
& name
);
324 static wxImageHandler
*FindHandler( const wxString
& name
);
325 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
326 static wxImageHandler
*FindHandler( long imageType
);
327 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
329 static void CleanUpHandlers();
330 static void InitStandardHandlers();
334 static wxList sm_handlers
;