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 wxString
GetName() const { return m_name
; }
62 inline wxString
GetExtension() const { return m_extension
; }
63 inline long GetType() const { return m_type
; }
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
77 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
79 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
87 m_type
= wxBITMAP_TYPE_PNG
;
91 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
92 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
98 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
103 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
105 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
109 inline wxJPEGHandler()
111 m_name
= "JPEG file";
113 m_type
= wxBITMAP_TYPE_JPEG
;
116 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
117 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
121 //-----------------------------------------------------------------------------
123 //-----------------------------------------------------------------------------
125 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
127 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
131 inline wxBMPHandler()
135 m_type
= wxBITMAP_TYPE_BMP
;
139 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
143 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
147 class WXDLLEXPORT wxImage
: public wxObject
149 DECLARE_DYNAMIC_CLASS(wxImage
)
151 friend class WXDLLEXPORT wxImageHandler
;
156 wxImage( int width
, int height
);
157 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
158 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
160 wxImage( const wxImage
& image
);
161 wxImage( const wxImage
* image
);
163 // these functions get implemented in /src/(platform)/bitmap.cpp
164 wxImage( const wxBitmap
&bitmap
);
165 wxBitmap
ConvertToBitmap() const;
167 void Create( int width
, int height
);
170 wxImage
Scale( int width
, int height
);
172 // these routines are slow but safe
173 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
174 unsigned char GetRed( int x
, int y
);
175 unsigned char GetGreen( int x
, int y
);
176 unsigned char GetBlue( int x
, int y
);
178 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
181 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
184 virtual bool SaveFile( const wxString
& name
, int type
);
187 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
191 int GetWidth() const;
192 int GetHeight() const;
194 char unsigned *GetData() const;
195 void SetData( char unsigned *data
);
197 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
198 unsigned char GetMaskRed() const;
199 unsigned char GetMaskGreen() const;
200 unsigned char GetMaskBlue() const;
201 void SetMask( bool mask
= TRUE
);
202 bool HasMask() const;
204 inline wxImage
& operator = (const wxImage
& image
)
205 { if ((*this) == image
)
210 inline bool operator == (const wxImage
& image
)
211 { return m_refData
== image
.m_refData
; }
212 inline bool operator != (const wxImage
& image
)
213 { return m_refData
!= image
.m_refData
; }
215 static inline wxList
& GetHandlers() { return sm_handlers
; }
216 static void AddHandler( wxImageHandler
*handler
);
217 static void InsertHandler( wxImageHandler
*handler
);
218 static bool RemoveHandler( const wxString
& name
);
219 static wxImageHandler
*FindHandler( const wxString
& name
);
220 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
221 static wxImageHandler
*FindHandler( long imageType
);
223 static void CleanUpHandlers();
224 static void InitStandardHandlers();
228 static wxList sm_handlers
;