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 virtual bool CanRead( wxInputStream
& stream
);
66 virtual bool CanRead( const wxString
& name
);
69 inline void SetName(const wxString
& name
) { m_name
= name
; }
70 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
71 inline void SetType(long type
) { m_type
= type
; }
72 inline void SetMimeType(const wxString
& type
) { m_mime
= type
; }
73 inline wxString
GetName() const { return m_name
; }
74 inline wxString
GetExtension() const { return m_extension
; }
75 inline long GetType() const { return m_type
; }
76 inline wxString
GetMimeType() const { return m_mime
; }
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
91 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
93 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
101 m_type
= wxBITMAP_TYPE_PNG
;
102 m_mime
= "image/png";
106 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
107 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
108 virtual bool CanRead( wxInputStream
& stream
);
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
118 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
120 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
124 inline wxJPEGHandler()
126 m_name
= "JPEG file";
128 m_type
= wxBITMAP_TYPE_JPEG
;
129 m_mime
= "image/jpeg";
133 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
134 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
135 virtual bool CanRead( wxInputStream
& stream
);
140 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
144 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
146 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
150 inline wxBMPHandler()
154 m_type
= wxBITMAP_TYPE_BMP
;
155 m_mime
= "image/bmp";
159 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
160 virtual bool CanRead( wxInputStream
& stream
);
164 //-----------------------------------------------------------------------------
166 //-----------------------------------------------------------------------------
170 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
172 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
176 inline wxGIFHandler()
180 m_type
= wxBITMAP_TYPE_GIF
;
181 m_mime
= "image/gif";
185 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
186 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
187 virtual bool CanRead( wxInputStream
& stream
);
192 //-----------------------------------------------------------------------------
194 //-----------------------------------------------------------------------------
197 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
199 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
203 inline wxPNMHandler()
207 m_type
= wxBITMAP_TYPE_PNM
;
208 m_mime
= "image/pnm";
212 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
213 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
214 virtual bool CanRead( wxInputStream
& stream
);
219 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
224 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
226 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
230 inline wxPCXHandler()
234 m_type
= wxBITMAP_TYPE_PCX
;
235 m_mime
= "image/pcx";
239 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
240 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
241 virtual bool CanRead( wxInputStream
& stream
);
246 //-----------------------------------------------------------------------------
248 //-----------------------------------------------------------------------------
250 class WXDLLEXPORT wxImage
: public wxObject
252 DECLARE_DYNAMIC_CLASS(wxImage
)
254 friend class WXDLLEXPORT wxImageHandler
;
259 wxImage( int width
, int height
);
260 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
261 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
262 wxImage( const wxString
& name
, const wxString
& mimetype
);
263 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
265 wxImage( const wxImage
& image
);
266 wxImage( const wxImage
* image
);
268 // these functions get implemented in /src/(platform)/bitmap.cpp
269 wxImage( const wxBitmap
&bitmap
);
270 operator wxBitmap() const { return ConvertToBitmap(); }
271 wxBitmap
ConvertToBitmap() const;
273 void Create( int width
, int height
);
276 // return the new image with size width*height
277 wxImage
GetSubImage( const wxRect
& ) const;
279 // return the new image with size width*height
280 wxImage
Scale( int width
, int height
) const;
282 // rescales the image in place
283 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
285 // these routines are slow but safe
286 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
287 unsigned char GetRed( int x
, int y
);
288 unsigned char GetGreen( int x
, int y
);
289 unsigned char GetBlue( int x
, int y
);
291 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
292 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
295 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
296 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
299 virtual bool SaveFile( const wxString
& name
, int type
);
300 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
303 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
304 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
308 int GetWidth() const;
309 int GetHeight() const;
311 char unsigned *GetData() const;
312 void SetData( char unsigned *data
);
314 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
315 unsigned char GetMaskRed() const;
316 unsigned char GetMaskGreen() const;
317 unsigned char GetMaskBlue() const;
318 void SetMask( bool mask
= TRUE
);
319 bool HasMask() const;
321 wxImage
& operator = (const wxImage
& image
)
323 if ( (*this) != image
)
328 bool operator == (const wxImage
& image
)
329 { return m_refData
== image
.m_refData
; }
330 bool operator != (const wxImage
& image
)
331 { return m_refData
!= image
.m_refData
; }
333 static wxList
& GetHandlers() { return sm_handlers
; }
334 static void AddHandler( wxImageHandler
*handler
);
335 static void InsertHandler( wxImageHandler
*handler
);
336 static bool RemoveHandler( const wxString
& name
);
337 static wxImageHandler
*FindHandler( const wxString
& name
);
338 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
339 static wxImageHandler
*FindHandler( long imageType
);
340 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
342 static void CleanUpHandlers();
343 static void InitStandardHandlers();
347 static wxList sm_handlers
;