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
;
28 class WXDLLEXPORT wxPNGHandler
;
30 class WXDLLEXPORT wxBMPHandler
;
31 class WXDLLEXPORT wxImage
;
33 class WXDLLEXPORT wxBitmap
;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 class WXDLLEXPORT wxImageHandler
: public wxObject
41 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
44 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
46 virtual bool LoadFile( wxImage
*image
, const wxString
& name
);
47 virtual bool SaveFile( wxImage
*image
, const wxString
& name
);
49 inline void SetName(const wxString
& name
) { m_name
= name
; }
50 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
51 inline void SetType(long type
) { m_type
= type
; }
52 inline wxString
GetName() const { return m_name
; }
53 inline wxString
GetExtension() const { return m_extension
; }
54 inline long GetType() const { return m_type
; }
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
68 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
70 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
78 m_type
= wxBITMAP_TYPE_PNG
;
81 virtual bool LoadFile( wxImage
*image
, const wxString
& name
);
82 virtual bool SaveFile( wxImage
*image
, const wxString
& name
);
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
90 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
92 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
100 m_type
= wxBITMAP_TYPE_BMP
;
103 virtual bool LoadFile( wxImage
*image
, const wxString
& name
);
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
110 class WXDLLEXPORT wxImage
: public wxObject
112 DECLARE_DYNAMIC_CLASS(wxImage
)
114 friend class WXDLLEXPORT wxImageHandler
;
119 wxImage( int width
, int height
);
120 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
122 wxImage( const wxImage
& image
);
123 wxImage( const wxImage
* image
);
125 // these functions get implemented in /src/(platform)/bitmap.cpp
126 wxImage( const wxBitmap
&bitmap
);
127 wxBitmap
ConvertToBitmap() const;
129 void Create( int width
, int height
);
132 wxImage
Scale( int width
, int height
);
134 // these routines are slow but safe
135 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
136 unsigned char GetRed( int x
, int y
);
137 unsigned char GetGreen( int x
, int y
);
138 unsigned char GetBlue( int x
, int y
);
140 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_PNG
);
141 virtual bool SaveFile( const wxString
& name
, int type
);
144 int GetWidth() const;
145 int GetHeight() const;
147 char unsigned *GetData() const;
148 void SetData( char unsigned *data
);
150 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
151 unsigned char GetMaskRed() const;
152 unsigned char GetMaskGreen() const;
153 unsigned char GetMaskBlue() const;
154 void SetMask( bool mask
= TRUE
);
155 bool HasMask() const;
157 inline wxImage
& operator = (const wxImage
& image
)
158 { if (*this == image
) return (*this); Ref(image
); return *this; }
159 inline bool operator == (const wxImage
& image
)
160 { return m_refData
== image
.m_refData
; }
161 inline bool operator != (const wxImage
& image
)
162 { return m_refData
!= image
.m_refData
; }
164 static inline wxList
& GetHandlers() { return sm_handlers
; }
165 static void AddHandler( wxImageHandler
*handler
);
166 static void InsertHandler( wxImageHandler
*handler
);
167 static bool RemoveHandler( const wxString
& name
);
168 static wxImageHandler
*FindHandler( const wxString
& name
);
169 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
170 static wxImageHandler
*FindHandler( long imageType
);
172 static void CleanUpHandlers();
173 static void InitStandardHandlers();
177 static wxList sm_handlers
;