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/stream.h"
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 class WXDLLEXPORT wxImageHandler
;
29 class WXDLLEXPORT wxPNGHandler
;
31 class WXDLLEXPORT wxBMPHandler
;
32 class WXDLLEXPORT wxImage
;
34 class WXDLLEXPORT wxBitmap
;
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 class WXDLLEXPORT wxImageHandler
: public wxObject
42 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
45 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
47 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
48 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
50 inline void SetName(const wxString
& name
) { m_name
= name
; }
51 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
52 inline void SetType(long type
) { m_type
= type
; }
53 inline wxString
GetName() const { return m_name
; }
54 inline wxString
GetExtension() const { return m_extension
; }
55 inline long GetType() const { return m_type
; }
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
69 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
71 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
79 m_type
= wxBITMAP_TYPE_PNG
;
82 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
83 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
);
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
91 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
93 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
101 m_type
= wxBITMAP_TYPE_BMP
;
104 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
);
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
111 class WXDLLEXPORT wxImage
: public wxObject
113 DECLARE_DYNAMIC_CLASS(wxImage
)
115 friend class WXDLLEXPORT wxImageHandler
;
120 wxImage( int width
, int height
);
121 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
122 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
124 wxImage( const wxImage
& image
);
125 wxImage( const wxImage
* image
);
127 // these functions get implemented in /src/(platform)/bitmap.cpp
128 wxImage( const wxBitmap
&bitmap
);
129 wxBitmap
ConvertToBitmap() const;
131 void Create( int width
, int height
);
134 wxImage
Scale( int width
, int height
);
136 // these routines are slow but safe
137 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
138 unsigned char GetRed( int x
, int y
);
139 unsigned char GetGreen( int x
, int y
);
140 unsigned char GetBlue( int x
, int y
);
142 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
143 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_PNG
);
144 virtual bool SaveFile( const wxString
& name
, int type
);
145 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
148 int GetWidth() const;
149 int GetHeight() const;
151 char unsigned *GetData() const;
152 void SetData( char unsigned *data
);
154 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
155 unsigned char GetMaskRed() const;
156 unsigned char GetMaskGreen() const;
157 unsigned char GetMaskBlue() const;
158 void SetMask( bool mask
= TRUE
);
159 bool HasMask() const;
161 inline wxImage
& operator = (const wxImage
& image
)
162 { if ((*this) == image
)
167 inline bool operator == (const wxImage
& image
)
168 { return m_refData
== image
.m_refData
; }
169 inline bool operator != (const wxImage
& image
)
170 { return m_refData
!= image
.m_refData
; }
172 static inline wxList
& GetHandlers() { return sm_handlers
; }
173 static void AddHandler( wxImageHandler
*handler
);
174 static void InsertHandler( wxImageHandler
*handler
);
175 static bool RemoveHandler( const wxString
& name
);
176 static wxImageHandler
*FindHandler( const wxString
& name
);
177 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
178 static wxImageHandler
*FindHandler( long imageType
);
180 static void CleanUpHandlers();
181 static void InitStandardHandlers();
185 static wxList sm_handlers
;