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
);
57 inline void SetName(const wxString
& name
) { m_name
= name
; }
58 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
59 inline void SetType(long type
) { m_type
= type
; }
60 inline void SetMimeType(const wxString
& type
) { m_mime
= type
; }
61 inline wxString
GetName() const { return m_name
; }
62 inline wxString
GetExtension() const { return m_extension
; }
63 inline long GetType() const { return m_type
; }
64 inline wxString
GetMimeType() const { return m_mime
; }
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
79 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
81 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
89 m_type
= wxBITMAP_TYPE_PNG
;
94 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
95 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
100 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
105 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
107 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
111 inline wxJPEGHandler()
113 m_name
= "JPEG file";
115 m_type
= wxBITMAP_TYPE_JPEG
;
116 m_mime
= "image/jpeg";
120 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
121 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
126 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
130 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
132 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
136 inline wxBMPHandler()
140 m_type
= wxBITMAP_TYPE_BMP
;
141 m_mime
= "image/bmp";
145 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
149 //-----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
153 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
155 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
159 inline wxGIFHandler()
163 m_type
= wxBITMAP_TYPE_GIF
;
164 m_mime
= "image/gif";
168 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
169 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
173 //-----------------------------------------------------------------------------
175 //-----------------------------------------------------------------------------
177 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
179 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
183 inline wxPNMHandler()
187 m_type
= wxBITMAP_TYPE_PNM
;
188 m_mime
= "image/pnm";
192 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
193 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
197 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
201 class WXDLLEXPORT wxImage
: public wxObject
203 DECLARE_DYNAMIC_CLASS(wxImage
)
205 friend class WXDLLEXPORT wxImageHandler
;
210 wxImage( int width
, int height
);
211 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
212 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
213 wxImage( const wxString
& name
, const wxString
& mimetype
);
214 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
216 wxImage( const wxImage
& image
);
217 wxImage( const wxImage
* image
);
219 // these functions get implemented in /src/(platform)/bitmap.cpp
220 wxImage( const wxBitmap
&bitmap
);
221 operator wxBitmap() const { return ConvertToBitmap(); }
222 wxBitmap
ConvertToBitmap() const;
224 void Create( int width
, int height
);
227 // return the new image with size width*height
228 wxImage
GetSubImage( const wxRect
& ) const;
230 // return the new image with size width*height
231 wxImage
Scale( int width
, int height
) const;
233 // rescales the image in place
234 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
236 // these routines are slow but safe
237 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
238 unsigned char GetRed( int x
, int y
);
239 unsigned char GetGreen( int x
, int y
);
240 unsigned char GetBlue( int x
, int y
);
242 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
243 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
246 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
247 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
250 virtual bool SaveFile( const wxString
& name
, int type
);
251 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
254 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
255 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
259 int GetWidth() const;
260 int GetHeight() const;
262 char unsigned *GetData() const;
263 void SetData( char unsigned *data
);
265 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
266 unsigned char GetMaskRed() const;
267 unsigned char GetMaskGreen() const;
268 unsigned char GetMaskBlue() const;
269 void SetMask( bool mask
= TRUE
);
270 bool HasMask() const;
272 wxImage
& operator = (const wxImage
& image
)
274 if ( (*this) != image
)
279 bool operator == (const wxImage
& image
)
280 { return m_refData
== image
.m_refData
; }
281 bool operator != (const wxImage
& image
)
282 { return m_refData
!= image
.m_refData
; }
284 static wxList
& GetHandlers() { return sm_handlers
; }
285 static void AddHandler( wxImageHandler
*handler
);
286 static void InsertHandler( wxImageHandler
*handler
);
287 static bool RemoveHandler( const wxString
& name
);
288 static wxImageHandler
*FindHandler( const wxString
& name
);
289 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
290 static wxImageHandler
*FindHandler( long imageType
);
291 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
293 static void CleanUpHandlers();
294 static void InitStandardHandlers();
298 static wxList sm_handlers
;