]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Removed LastError() from wxFilterStream
[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 #include "wx/bitmap.h"
22
23 #if wxUSE_STREAMS
24 # include "wx/stream.h"
25 #endif
26
27 //-----------------------------------------------------------------------------
28 // classes
29 //-----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxImageHandler;
32 #if wxUSE_LIBPNG
33 class WXDLLEXPORT wxPNGHandler;
34 #endif
35 #if wxUSE_LIBJPEG
36 class WXDLLEXPORT wxJPEGHandler;
37 #endif
38 class WXDLLEXPORT wxBMPHandler;
39 class WXDLLEXPORT wxGIFHandler;
40 class WXDLLEXPORT wxPNMHandler;
41 class WXDLLEXPORT wxPCXHandler;
42 class WXDLLEXPORT wxImage;
43
44 //-----------------------------------------------------------------------------
45 // wxImageHandler
46 //-----------------------------------------------------------------------------
47
48 class WXDLLEXPORT wxImageHandler: public wxObject
49 {
50 DECLARE_DYNAMIC_CLASS(wxImageHandler)
51
52 public:
53 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
54
55 #if wxUSE_STREAMS
56 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
57 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
58
59 virtual bool CanRead( wxInputStream& stream );
60 virtual bool CanRead( const wxString& name );
61 #endif
62
63 inline void SetName(const wxString& name) { m_name = name; }
64 inline void SetExtension(const wxString& ext) { m_extension = ext; }
65 inline void SetType(long type) { m_type = type; }
66 inline void SetMimeType(const wxString& type) { m_mime = type; }
67 inline wxString GetName() const { return m_name; }
68 inline wxString GetExtension() const { return m_extension; }
69 inline long GetType() const { return m_type; }
70 inline wxString GetMimeType() const { return m_mime; }
71
72 protected:
73 wxString m_name;
74 wxString m_extension;
75 wxString m_mime;
76 long m_type;
77
78 };
79
80 //-----------------------------------------------------------------------------
81 // wxPNGHandler
82 //-----------------------------------------------------------------------------
83
84 #if wxUSE_LIBPNG
85 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
86 {
87 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
88
89 public:
90
91 inline wxPNGHandler()
92 {
93 m_name = "PNG file";
94 m_extension = "png";
95 m_type = wxBITMAP_TYPE_PNG;
96 m_mime = "image/png";
97 };
98
99 #if wxUSE_STREAMS
100 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
101 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
102 virtual bool CanRead( wxInputStream& stream );
103 #endif
104 };
105 #endif
106
107 //-----------------------------------------------------------------------------
108 // wxJPEGHandler
109 //-----------------------------------------------------------------------------
110
111 #if wxUSE_LIBJPEG
112 class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
113 {
114 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
115
116 public:
117
118 inline wxJPEGHandler()
119 {
120 m_name = "JPEG file";
121 m_extension = "jpg";
122 m_type = wxBITMAP_TYPE_JPEG;
123 m_mime = "image/jpeg";
124 };
125
126 #if wxUSE_STREAMS
127 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
128 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
129 virtual bool CanRead( wxInputStream& stream );
130 #endif
131 };
132 #endif
133
134 //-----------------------------------------------------------------------------
135 // wxBMPHandler
136 //-----------------------------------------------------------------------------
137
138 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
139 {
140 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
141
142 public:
143
144 inline wxBMPHandler()
145 {
146 m_name = "BMP file";
147 m_extension = "bmp";
148 m_type = wxBITMAP_TYPE_BMP;
149 m_mime = "image/bmp";
150 };
151
152 #if wxUSE_STREAMS
153 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
154 virtual bool CanRead( wxInputStream& stream );
155 #endif
156 };
157
158 //-----------------------------------------------------------------------------
159 // wxGIFHandler
160 //-----------------------------------------------------------------------------
161
162 class WXDLLEXPORT wxGIFHandler : public wxImageHandler
163 {
164 DECLARE_DYNAMIC_CLASS(wxGIFHandler)
165
166 public:
167
168 inline wxGIFHandler()
169 {
170 m_name = "GIF file";
171 m_extension = "gif";
172 m_type = wxBITMAP_TYPE_GIF;
173 m_mime = "image/gif";
174 };
175
176 #if wxUSE_STREAMS
177 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
178 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
179 virtual bool CanRead( wxInputStream& stream );
180 #endif
181 };
182
183 //-----------------------------------------------------------------------------
184 // wxPNMHandler
185 //-----------------------------------------------------------------------------
186
187 class WXDLLEXPORT wxPNMHandler : public wxImageHandler
188 {
189 DECLARE_DYNAMIC_CLASS(wxPNMHandler)
190
191 public:
192
193 inline wxPNMHandler()
194 {
195 m_name = "PNM file";
196 m_extension = "pnm";
197 m_type = wxBITMAP_TYPE_PNM;
198 m_mime = "image/pnm";
199 };
200
201 #if wxUSE_STREAMS
202 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
203 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
204 virtual bool CanRead( wxInputStream& stream );
205 #endif
206 };
207
208 //-----------------------------------------------------------------------------
209 // wxPCXHandler
210 //-----------------------------------------------------------------------------
211
212 class WXDLLEXPORT wxPCXHandler : public wxImageHandler
213 {
214 DECLARE_DYNAMIC_CLASS(wxPCXHandler)
215
216 public:
217
218 inline wxPCXHandler()
219 {
220 m_name = "PCX file";
221 m_extension = "pcx";
222 m_type = wxBITMAP_TYPE_PCX;
223 m_mime = "image/pcx";
224 };
225
226 #if wxUSE_STREAMS
227 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
228 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
229 virtual bool CanRead( wxInputStream& stream );
230 #endif
231 };
232
233 //-----------------------------------------------------------------------------
234 // wxImage
235 //-----------------------------------------------------------------------------
236
237 class WXDLLEXPORT wxImage: public wxObject
238 {
239 DECLARE_DYNAMIC_CLASS(wxImage)
240
241 friend class WXDLLEXPORT wxImageHandler;
242
243 public:
244
245 wxImage();
246 wxImage( int width, int height );
247 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
248 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
249 wxImage( const wxString& name, const wxString& mimetype );
250 wxImage( wxInputStream& stream, const wxString& mimetype );
251
252 wxImage( const wxImage& image );
253 wxImage( const wxImage* image );
254
255 // these functions get implemented in /src/(platform)/bitmap.cpp
256 wxImage( const wxBitmap &bitmap );
257 operator wxBitmap() const { return ConvertToBitmap(); }
258 wxBitmap ConvertToBitmap() const;
259
260 void Create( int width, int height );
261 void Destroy();
262
263 // return the new image with size width*height
264 wxImage GetSubImage( const wxRect& ) const;
265
266 // return the new image with size width*height
267 wxImage Scale( int width, int height ) const;
268
269 // rescales the image in place
270 void Rescale( int width, int height ) { *this = Scale(width, height); }
271
272 // these routines are slow but safe
273 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
274 unsigned char GetRed( int x, int y );
275 unsigned char GetGreen( int x, int y );
276 unsigned char GetBlue( int x, int y );
277
278 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
279 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
280
281 #if wxUSE_STREAMS
282 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
283 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
284 #endif
285
286 virtual bool SaveFile( const wxString& name, int type );
287 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
288
289 #if wxUSE_STREAMS
290 virtual bool SaveFile( wxOutputStream& stream, int type );
291 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
292 #endif
293
294 bool Ok() const;
295 int GetWidth() const;
296 int GetHeight() const;
297
298 char unsigned *GetData() const;
299 void SetData( char unsigned *data );
300
301 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
302 unsigned char GetMaskRed() const;
303 unsigned char GetMaskGreen() const;
304 unsigned char GetMaskBlue() const;
305 void SetMask( bool mask = TRUE );
306 bool HasMask() const;
307
308 wxImage& operator = (const wxImage& image)
309 {
310 if ( (*this) != image )
311 Ref(image);
312 return *this;
313 }
314
315 bool operator == (const wxImage& image)
316 { return m_refData == image.m_refData; }
317 bool operator != (const wxImage& image)
318 { return m_refData != image.m_refData; }
319
320 static wxList& GetHandlers() { return sm_handlers; }
321 static void AddHandler( wxImageHandler *handler );
322 static void InsertHandler( wxImageHandler *handler );
323 static bool RemoveHandler( const wxString& name );
324 static wxImageHandler *FindHandler( const wxString& name );
325 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
326 static wxImageHandler *FindHandler( long imageType );
327 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
328
329 static void CleanUpHandlers();
330 static void InitStandardHandlers();
331
332 protected:
333
334 static wxList sm_handlers;
335
336 };
337
338 #endif
339 // _WX_IMAGE_H_
340