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
);
54 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
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
);
95 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
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
);
121 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
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
);
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
);
169 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
173 //-----------------------------------------------------------------------------
175 //-----------------------------------------------------------------------------
177 class WXDLLEXPORT wxImage
: public wxObject
179 DECLARE_DYNAMIC_CLASS(wxImage
)
181 friend class WXDLLEXPORT wxImageHandler
;
186 wxImage( int width
, int height
);
187 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
188 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
189 wxImage( const wxString
& name
, const wxString
& mimetype
);
190 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
192 wxImage( const wxImage
& image
);
193 wxImage( const wxImage
* image
);
195 // these functions get implemented in /src/(platform)/bitmap.cpp
196 wxImage( const wxBitmap
&bitmap
);
197 operator wxBitmap() const { return ConvertToBitmap(); }
198 wxBitmap
ConvertToBitmap() const;
200 void Create( int width
, int height
);
203 // return the new image with size width*height
204 wxImage
Scale( int width
, int height
) const;
206 // rescales the image in place
207 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
209 // these routines are slow but safe
210 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
211 unsigned char GetRed( int x
, int y
);
212 unsigned char GetGreen( int x
, int y
);
213 unsigned char GetBlue( int x
, int y
);
215 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
216 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
219 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
220 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
223 virtual bool SaveFile( const wxString
& name
, int type
);
224 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
227 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
228 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
232 int GetWidth() const;
233 int GetHeight() const;
235 char unsigned *GetData() const;
236 void SetData( char unsigned *data
);
238 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
239 unsigned char GetMaskRed() const;
240 unsigned char GetMaskGreen() const;
241 unsigned char GetMaskBlue() const;
242 void SetMask( bool mask
= TRUE
);
243 bool HasMask() const;
245 wxImage
& operator = (const wxImage
& image
)
247 if ( (*this) != image
)
252 bool operator == (const wxImage
& image
)
253 { return m_refData
== image
.m_refData
; }
254 bool operator != (const wxImage
& image
)
255 { return m_refData
!= image
.m_refData
; }
257 static wxList
& GetHandlers() { return sm_handlers
; }
258 static void AddHandler( wxImageHandler
*handler
);
259 static void InsertHandler( wxImageHandler
*handler
);
260 static bool RemoveHandler( const wxString
& name
);
261 static wxImageHandler
*FindHandler( const wxString
& name
);
262 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
263 static wxImageHandler
*FindHandler( long imageType
);
264 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
266 static void CleanUpHandlers();
267 static void InitStandardHandlers();
271 static wxList sm_handlers
;