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"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class WXDLLEXPORT wxImageHandler
;
27 class WXDLLEXPORT wxPNGHandler
;
28 class WXDLLEXPORT wxBMPHandler
;
29 class WXDLLEXPORT wxImage
;
31 class WXDLLEXPORT wxBitmap
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 class WXDLLEXPORT wxImageHandler
: public wxObject
39 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
42 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
44 virtual bool LoadFile( wxImage
*image
, const wxString
& name
);
45 virtual bool SaveFile( wxImage
*image
, const wxString
& name
);
47 inline void SetName(const wxString
& name
) { m_name
= name
; }
48 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
49 inline void SetType(long type
) { m_type
= type
; }
50 inline wxString
GetName() const { return m_name
; }
51 inline wxString
GetExtension() const { return m_extension
; }
52 inline long GetType() const { return m_type
; }
61 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
65 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
67 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
75 m_type
= wxBITMAP_TYPE_PNG
;
78 virtual bool LoadFile( wxImage
*image
, const wxString
& name
);
79 virtual bool SaveFile( wxImage
*image
, const wxString
& name
);
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
88 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
96 m_type
= wxBITMAP_TYPE_BMP
;
99 virtual bool LoadFile( wxImage
*image
, const wxString
& name
);
102 //-----------------------------------------------------------------------------
104 //-----------------------------------------------------------------------------
106 class WXDLLEXPORT wxImage
: public wxObject
108 DECLARE_DYNAMIC_CLASS(wxImage
)
110 friend class WXDLLEXPORT wxImageHandler
;
115 wxImage( int width
, int height
);
116 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
118 wxImage( const wxImage
& image
);
119 wxImage( const wxImage
* image
);
121 // these functions get implemented in /src/(platform)/bitmap.cpp
122 wxImage( const wxBitmap
&bitmap
);
123 wxBitmap
ConvertToBitmap() const;
125 void Create( int width
, int height
);
128 wxImage
Scale( int width
, int height
);
130 // these routines are slow but safe
131 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
132 unsigned char GetRed( int x
, int y
);
133 unsigned char GetGreen( int x
, int y
);
134 unsigned char GetBlue( int x
, int y
);
136 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
137 virtual bool SaveFile( const wxString
& name
, int type
);
140 int GetWidth() const;
141 int GetHeight() const;
143 char unsigned *GetData() const;
144 void SetData( char unsigned *data
);
146 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
147 unsigned char GetMaskRed() const;
148 unsigned char GetMaskGreen() const;
149 unsigned char GetMaskBlue() const;
150 void SetMask( bool mask
= TRUE
);
151 bool HasMask() const;
153 inline wxImage
& operator = (const wxImage
& image
)
154 { if (*this == image
) return (*this); Ref(image
); return *this; }
155 inline bool operator == (const wxImage
& image
)
156 { return m_refData
== image
.m_refData
; }
157 inline bool operator != (const wxImage
& image
)
158 { return m_refData
!= image
.m_refData
; }
160 static inline wxList
& GetHandlers() { return sm_handlers
; }
161 static void AddHandler( wxImageHandler
*handler
);
162 static void InsertHandler( wxImageHandler
*handler
);
163 static bool RemoveHandler( const wxString
& name
);
164 static wxImageHandler
*FindHandler( const wxString
& name
);
165 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
166 static wxImageHandler
*FindHandler( long imageType
);
168 static void CleanUpHandlers();
169 static void InitStandardHandlers();
173 static wxList sm_handlers
;