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
;
34 class WXDLLEXPORT wxBMPHandler
;
35 class WXDLLEXPORT wxImage
;
37 class WXDLLEXPORT wxBitmap
;
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 class WXDLLEXPORT wxImageHandler
: public wxObject
45 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
48 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
51 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
52 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
55 inline void SetName(const wxString
& name
) { m_name
= name
; }
56 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
57 inline void SetType(long type
) { m_type
= type
; }
58 inline wxString
GetName() const { return m_name
; }
59 inline wxString
GetExtension() const { return m_extension
; }
60 inline long GetType() const { return m_type
; }
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
74 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
76 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
84 m_type
= wxBITMAP_TYPE_PNG
;
88 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
89 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
101 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
105 inline wxBMPHandler()
109 m_type
= wxBITMAP_TYPE_BMP
;
113 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
117 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
121 class WXDLLEXPORT wxImage
: public wxObject
123 DECLARE_DYNAMIC_CLASS(wxImage
)
125 friend class WXDLLEXPORT wxImageHandler
;
130 wxImage( int width
, int height
);
131 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
132 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
134 wxImage( const wxImage
& image
);
135 wxImage( const wxImage
* image
);
137 // these functions get implemented in /src/(platform)/bitmap.cpp
138 wxImage( const wxBitmap
&bitmap
);
139 wxBitmap
ConvertToBitmap() const;
141 void Create( int width
, int height
);
144 wxImage
Scale( int width
, int height
);
146 // these routines are slow but safe
147 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
148 unsigned char GetRed( int x
, int y
);
149 unsigned char GetGreen( int x
, int y
);
150 unsigned char GetBlue( int x
, int y
);
152 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
155 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
158 virtual bool SaveFile( const wxString
& name
, int type
);
161 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
165 int GetWidth() const;
166 int GetHeight() const;
168 char unsigned *GetData() const;
169 void SetData( char unsigned *data
);
171 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
172 unsigned char GetMaskRed() const;
173 unsigned char GetMaskGreen() const;
174 unsigned char GetMaskBlue() const;
175 void SetMask( bool mask
= TRUE
);
176 bool HasMask() const;
178 inline wxImage
& operator = (const wxImage
& image
)
179 { if ((*this) == image
)
184 inline bool operator == (const wxImage
& image
)
185 { return m_refData
== image
.m_refData
; }
186 inline bool operator != (const wxImage
& image
)
187 { return m_refData
!= image
.m_refData
; }
189 static inline wxList
& GetHandlers() { return sm_handlers
; }
190 static void AddHandler( wxImageHandler
*handler
);
191 static void InsertHandler( wxImageHandler
*handler
);
192 static bool RemoveHandler( const wxString
& name
);
193 static wxImageHandler
*FindHandler( const wxString
& name
);
194 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
195 static wxImageHandler
*FindHandler( long imageType
);
197 static void CleanUpHandlers();
198 static void InitStandardHandlers();
202 static wxList sm_handlers
;