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 wxImage
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 class WXDLLEXPORT wxImageHandler
: public wxObject
47 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
50 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
53 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
54 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
56 virtual bool CanRead( wxInputStream
& stream
);
57 virtual bool CanRead( const wxString
& name
);
60 inline void SetName(const wxString
& name
) { m_name
= name
; }
61 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
62 inline void SetType(long type
) { m_type
= type
; }
63 inline void SetMimeType(const wxString
& type
) { m_mime
= type
; }
64 inline wxString
GetName() const { return m_name
; }
65 inline wxString
GetExtension() const { return m_extension
; }
66 inline long GetType() const { return m_type
; }
67 inline wxString
GetMimeType() const { return m_mime
; }
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
82 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
84 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
92 m_type
= wxBITMAP_TYPE_PNG
;
97 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
98 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
99 virtual bool CanRead( wxInputStream
& stream
);
104 //-----------------------------------------------------------------------------
106 //-----------------------------------------------------------------------------
109 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
111 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
115 inline wxJPEGHandler()
117 m_name
= "JPEG file";
119 m_type
= wxBITMAP_TYPE_JPEG
;
120 m_mime
= "image/jpeg";
124 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
125 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
126 virtual bool CanRead( wxInputStream
& stream
);
131 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
135 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
137 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
141 inline wxBMPHandler()
145 m_type
= wxBITMAP_TYPE_BMP
;
146 m_mime
= "image/bmp";
150 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
151 virtual bool CanRead( wxInputStream
& stream
);
155 //-----------------------------------------------------------------------------
157 //-----------------------------------------------------------------------------
159 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
161 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
165 inline wxGIFHandler()
169 m_type
= wxBITMAP_TYPE_GIF
;
170 m_mime
= "image/gif";
174 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
175 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
176 virtual bool CanRead( wxInputStream
& stream
);
180 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
184 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
186 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
190 inline wxPNMHandler()
194 m_type
= wxBITMAP_TYPE_PNM
;
195 m_mime
= "image/pnm";
199 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
200 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
201 virtual bool CanRead( wxInputStream
& stream
);
205 //-----------------------------------------------------------------------------
207 //-----------------------------------------------------------------------------
209 class WXDLLEXPORT wxImage
: public wxObject
211 DECLARE_DYNAMIC_CLASS(wxImage
)
213 friend class WXDLLEXPORT wxImageHandler
;
218 wxImage( int width
, int height
);
219 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
220 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
221 wxImage( const wxString
& name
, const wxString
& mimetype
);
222 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
224 wxImage( const wxImage
& image
);
225 wxImage( const wxImage
* image
);
227 // these functions get implemented in /src/(platform)/bitmap.cpp
228 wxImage( const wxBitmap
&bitmap
);
229 operator wxBitmap() const { return ConvertToBitmap(); }
230 wxBitmap
ConvertToBitmap() const;
232 void Create( int width
, int height
);
235 // return the new image with size width*height
236 wxImage
GetSubImage( const wxRect
& ) const;
238 // return the new image with size width*height
239 wxImage
Scale( int width
, int height
) const;
241 // rescales the image in place
242 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
244 // these routines are slow but safe
245 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
246 unsigned char GetRed( int x
, int y
);
247 unsigned char GetGreen( int x
, int y
);
248 unsigned char GetBlue( int x
, int y
);
250 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
251 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
254 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
255 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
258 virtual bool SaveFile( const wxString
& name
, int type
);
259 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
262 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
263 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
267 int GetWidth() const;
268 int GetHeight() const;
270 char unsigned *GetData() const;
271 void SetData( char unsigned *data
);
273 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
274 unsigned char GetMaskRed() const;
275 unsigned char GetMaskGreen() const;
276 unsigned char GetMaskBlue() const;
277 void SetMask( bool mask
= TRUE
);
278 bool HasMask() const;
280 wxImage
& operator = (const wxImage
& image
)
282 if ( (*this) != image
)
287 bool operator == (const wxImage
& image
)
288 { return m_refData
== image
.m_refData
; }
289 bool operator != (const wxImage
& image
)
290 { return m_refData
!= image
.m_refData
; }
292 static wxList
& GetHandlers() { return sm_handlers
; }
293 static void AddHandler( wxImageHandler
*handler
);
294 static void InsertHandler( wxImageHandler
*handler
);
295 static bool RemoveHandler( const wxString
& name
);
296 static wxImageHandler
*FindHandler( const wxString
& name
);
297 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
298 static wxImageHandler
*FindHandler( long imageType
);
299 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
301 static void CleanUpHandlers();
302 static void InitStandardHandlers();
306 static wxList sm_handlers
;