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 //-----------------------------------------------------------------------------
164 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
166 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
170 inline wxGIFHandler()
174 m_type
= wxBITMAP_TYPE_GIF
;
175 m_mime
= "image/gif";
179 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
180 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
181 virtual bool CanRead( wxInputStream
& stream
);
187 //-----------------------------------------------------------------------------
189 //-----------------------------------------------------------------------------
191 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
193 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
197 inline wxPNMHandler()
201 m_type
= wxBITMAP_TYPE_PNM
;
202 m_mime
= "image/pnm";
206 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
207 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
208 virtual bool CanRead( wxInputStream
& stream
);
212 //-----------------------------------------------------------------------------
214 //-----------------------------------------------------------------------------
216 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
218 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
222 inline wxPCXHandler()
226 m_type
= wxBITMAP_TYPE_PCX
;
227 m_mime
= "image/pcx";
231 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
232 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
233 virtual bool CanRead( wxInputStream
& stream
);
237 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
241 class WXDLLEXPORT wxImage
: public wxObject
243 DECLARE_DYNAMIC_CLASS(wxImage
)
245 friend class WXDLLEXPORT wxImageHandler
;
250 wxImage( int width
, int height
);
251 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
252 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
253 wxImage( const wxString
& name
, const wxString
& mimetype
);
254 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
256 wxImage( const wxImage
& image
);
257 wxImage( const wxImage
* image
);
259 // these functions get implemented in /src/(platform)/bitmap.cpp
260 wxImage( const wxBitmap
&bitmap
);
261 operator wxBitmap() const { return ConvertToBitmap(); }
262 wxBitmap
ConvertToBitmap() const;
264 void Create( int width
, int height
);
267 // return the new image with size width*height
268 wxImage
GetSubImage( const wxRect
& ) const;
270 // return the new image with size width*height
271 wxImage
Scale( int width
, int height
) const;
273 // rescales the image in place
274 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
276 // these routines are slow but safe
277 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
278 unsigned char GetRed( int x
, int y
);
279 unsigned char GetGreen( int x
, int y
);
280 unsigned char GetBlue( int x
, int y
);
282 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
283 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
286 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
287 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
290 virtual bool SaveFile( const wxString
& name
, int type
);
291 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
294 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
295 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
299 int GetWidth() const;
300 int GetHeight() const;
302 char unsigned *GetData() const;
303 void SetData( char unsigned *data
);
305 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
306 unsigned char GetMaskRed() const;
307 unsigned char GetMaskGreen() const;
308 unsigned char GetMaskBlue() const;
309 void SetMask( bool mask
= TRUE
);
310 bool HasMask() const;
312 wxImage
& operator = (const wxImage
& image
)
314 if ( (*this) != image
)
319 bool operator == (const wxImage
& image
)
320 { return m_refData
== image
.m_refData
; }
321 bool operator != (const wxImage
& image
)
322 { return m_refData
!= image
.m_refData
; }
324 static wxList
& GetHandlers() { return sm_handlers
; }
325 static void AddHandler( wxImageHandler
*handler
);
326 static void InsertHandler( wxImageHandler
*handler
);
327 static bool RemoveHandler( const wxString
& name
);
328 static wxImageHandler
*FindHandler( const wxString
& name
);
329 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
330 static wxImageHandler
*FindHandler( long imageType
);
331 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
333 static void CleanUpHandlers();
334 static void InitStandardHandlers();
338 static wxList sm_handlers
;