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"
23 #include "wx/stream.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class WXDLLEXPORT wxImageHandler
;
32 class WXDLLEXPORT wxPNGHandler
;
35 class WXDLLEXPORT wxJPEGHandler
;
37 class WXDLLEXPORT wxBMPHandler
;
38 class WXDLLEXPORT wxImage
;
40 class WXDLLEXPORT wxBitmap
;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 class WXDLLEXPORT wxImageHandler
: public wxObject
48 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
51 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
54 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
55 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
58 inline void SetName(const wxString
& name
) { m_name
= name
; }
59 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
60 inline void SetType(long type
) { m_type
= type
; }
61 inline void SetMimeType(const wxString
& type
) { m_mime
= type
; }
62 inline wxString
GetName() const { return m_name
; }
63 inline wxString
GetExtension() const { return m_extension
; }
64 inline long GetType() const { return m_type
; }
65 inline wxString
GetMimeType() const { return m_mime
; }
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
80 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
82 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
90 m_type
= wxBITMAP_TYPE_PNG
;
95 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
96 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
101 //-----------------------------------------------------------------------------
103 //-----------------------------------------------------------------------------
106 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
108 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
112 inline wxJPEGHandler()
114 m_name
= "JPEG file";
116 m_type
= wxBITMAP_TYPE_JPEG
;
117 m_mime
= "image/jpeg";
121 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
122 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
127 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
131 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
133 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
137 inline wxBMPHandler()
141 m_type
= wxBITMAP_TYPE_BMP
;
142 m_mime
= "image/bmp";
146 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
150 //-----------------------------------------------------------------------------
152 //-----------------------------------------------------------------------------
154 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
156 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
160 inline wxGIFHandler()
164 m_type
= wxBITMAP_TYPE_GIF
;
165 m_mime
= "image/gif";
169 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
170 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
174 //-----------------------------------------------------------------------------
176 //-----------------------------------------------------------------------------
178 class WXDLLEXPORT wxImage
: public wxObject
180 DECLARE_DYNAMIC_CLASS(wxImage
)
182 friend class WXDLLEXPORT wxImageHandler
;
187 wxImage( int width
, int height
);
188 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
189 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
190 wxImage( const wxString
& name
, const wxString
& mimetype
);
191 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
193 wxImage( const wxImage
& image
);
194 wxImage( const wxImage
* image
);
196 // these functions get implemented in /src/(platform)/bitmap.cpp
197 wxImage( const wxBitmap
&bitmap
);
198 operator wxBitmap() const { return ConvertToBitmap(); }
199 wxBitmap
ConvertToBitmap() const;
201 void Create( int width
, int height
);
204 // return the new image with size width*height
205 wxImage
Scale( int width
, int height
) const;
207 // rescales the image in place
208 wxImage
Rescale( int width
, int height
) { *this = Scale(width
, height
); }
210 // these routines are slow but safe
211 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
212 unsigned char GetRed( int x
, int y
);
213 unsigned char GetGreen( int x
, int y
);
214 unsigned char GetBlue( int x
, int y
);
216 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
217 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
220 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
221 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
224 virtual bool SaveFile( const wxString
& name
, int type
);
225 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
228 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
229 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
233 int GetWidth() const;
234 int GetHeight() const;
236 char unsigned *GetData() const;
237 void SetData( char unsigned *data
);
239 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
240 unsigned char GetMaskRed() const;
241 unsigned char GetMaskGreen() const;
242 unsigned char GetMaskBlue() const;
243 void SetMask( bool mask
= TRUE
);
244 bool HasMask() const;
246 wxImage
& operator = (const wxImage
& image
)
248 if ( (*this) != image
)
253 bool operator == (const wxImage
& image
)
254 { return m_refData
== image
.m_refData
; }
255 bool operator != (const wxImage
& image
)
256 { return m_refData
!= image
.m_refData
; }
258 static wxList
& GetHandlers() { return sm_handlers
; }
259 static void AddHandler( wxImageHandler
*handler
);
260 static void InsertHandler( wxImageHandler
*handler
);
261 static bool RemoveHandler( const wxString
& name
);
262 static wxImageHandler
*FindHandler( const wxString
& name
);
263 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
264 static wxImageHandler
*FindHandler( long imageType
);
265 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
267 static void CleanUpHandlers();
268 static void InitStandardHandlers();
272 static wxList sm_handlers
;