]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Before/After => BeforeFirst/AfterFirst (corrects some minor bugs)
[wxWidgets.git] / include / wx / image.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: image.h
3 // Purpose: wxImage class
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_IMAGE_H_
11 #define _WX_IMAGE_H_
12
13 #ifdef __GNUG__
14 #pragma interface "image.h"
15 #endif
16
17 #include "wx/setup.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/gdicmn.h"
21
22 #if wxUSE_STREAMS
23 #include "wx/stream.h"
24 #endif
25
26 //-----------------------------------------------------------------------------
27 // classes
28 //-----------------------------------------------------------------------------
29
30 class WXDLLEXPORT wxImageHandler;
31 #if wxUSE_LIBPNG
32 class WXDLLEXPORT wxPNGHandler;
33 #endif
34 #if wxUSE_LIBJPEG
35 class WXDLLEXPORT wxJPEGHandler;
36 #endif
37 class WXDLLEXPORT wxBMPHandler;
38 class WXDLLEXPORT wxImage;
39
40 class WXDLLEXPORT wxBitmap;
41
42 //-----------------------------------------------------------------------------
43 // wxImageHandler
44 //-----------------------------------------------------------------------------
45
46 class WXDLLEXPORT wxImageHandler: public wxObject
47 {
48 DECLARE_DYNAMIC_CLASS(wxImageHandler)
49
50 public:
51 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
52
53 #if wxUSE_STREAMS
54 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
55 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
56 #endif
57
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; }
64
65 protected:
66 wxString m_name;
67 wxString m_extension;
68 long m_type;
69
70 };
71
72 //-----------------------------------------------------------------------------
73 // wxPNGHandler
74 //-----------------------------------------------------------------------------
75
76 #if wxUSE_LIBPNG
77 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
78 {
79 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
80
81 public:
82
83 inline wxPNGHandler()
84 {
85 m_name = "PNG file";
86 m_extension = "png";
87 m_type = wxBITMAP_TYPE_PNG;
88 };
89
90 #if wxUSE_STREAMS
91 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
92 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
93 #endif
94
95 };
96 #endif
97
98 //-----------------------------------------------------------------------------
99 // wxJPEGHandler
100 //-----------------------------------------------------------------------------
101
102 #ifdef wxUSE_LIBJPEG
103 class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
104 {
105 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
106
107 public:
108
109 inline wxJPEGHandler()
110 {
111 m_name = "JPEG file";
112 m_extension = "jpg";
113 m_type = wxBITMAP_TYPE_JPEG;
114 };
115
116 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
117 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
118 };
119 #endif
120
121 //-----------------------------------------------------------------------------
122 // wxBMPHandler
123 //-----------------------------------------------------------------------------
124
125 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
126 {
127 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
128
129 public:
130
131 inline wxBMPHandler()
132 {
133 m_name = "BMP file";
134 m_extension = "bmp";
135 m_type = wxBITMAP_TYPE_BMP;
136 };
137
138 #if wxUSE_STREAMS
139 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
140 #endif
141 };
142
143 //-----------------------------------------------------------------------------
144 // wxImage
145 //-----------------------------------------------------------------------------
146
147 class WXDLLEXPORT wxImage: public wxObject
148 {
149 DECLARE_DYNAMIC_CLASS(wxImage)
150
151 friend class WXDLLEXPORT wxImageHandler;
152
153 public:
154
155 wxImage();
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 );
159
160 wxImage( const wxImage& image );
161 wxImage( const wxImage* image );
162
163 // these functions get implemented in /src/(platform)/bitmap.cpp
164 wxImage( const wxBitmap &bitmap );
165 wxBitmap ConvertToBitmap() const;
166
167 void Create( int width, int height );
168 void Destroy();
169
170 wxImage Scale( int width, int height );
171
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 );
177
178 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
179
180 #if wxUSE_STREAMS
181 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
182 #endif
183
184 virtual bool SaveFile( const wxString& name, int type );
185
186 #if wxUSE_STREAMS
187 virtual bool SaveFile( wxOutputStream& stream, int type );
188 #endif
189
190 bool Ok() const;
191 int GetWidth() const;
192 int GetHeight() const;
193
194 char unsigned *GetData() const;
195 void SetData( char unsigned *data );
196
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;
203
204 inline wxImage& operator = (const wxImage& image)
205 { if ((*this) == image)
206 return (*this);
207 Ref(image);
208 return *this; }
209
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; }
214
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 );
222
223 static void CleanUpHandlers();
224 static void InitStandardHandlers();
225
226 protected:
227
228 static wxList sm_handlers;
229
230 };
231
232 #endif
233 // _WX_IMAGE_H_