]> git.saurik.com Git - wxWidgets.git/blame - include/wx/image.h
Removed LastError() from wxFilterStream
[wxWidgets.git] / include / wx / image.h
CommitLineData
01111366
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: image.h
3// Purpose: wxImage class
4// Author: Robert Roebling
5// RCS-ID: $Id$
6// Copyright: (c) Robert Roebling
23280650 7// Licence: wxWindows licence
01111366
RR
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"
23280650 21#include "wx/bitmap.h"
bf38cbff
JS
22
23#if wxUSE_STREAMS
b9943f8e 24# include "wx/stream.h"
bf38cbff 25#endif
01111366
RR
26
27//-----------------------------------------------------------------------------
28// classes
29//-----------------------------------------------------------------------------
30
31class WXDLLEXPORT wxImageHandler;
9838df2c 32#if wxUSE_LIBPNG
01111366 33class WXDLLEXPORT wxPNGHandler;
ac57418f 34#endif
56b9c741
VS
35#if wxUSE_LIBJPEG
36class WXDLLEXPORT wxJPEGHandler;
37#endif
01111366 38class WXDLLEXPORT wxBMPHandler;
b9943f8e
GRG
39class WXDLLEXPORT wxGIFHandler;
40class WXDLLEXPORT wxPNMHandler;
41class WXDLLEXPORT wxPCXHandler;
01111366
RR
42class WXDLLEXPORT wxImage;
43
44//-----------------------------------------------------------------------------
45// wxImageHandler
46//-----------------------------------------------------------------------------
47
48class WXDLLEXPORT wxImageHandler: public wxObject
49{
50 DECLARE_DYNAMIC_CLASS(wxImageHandler)
23280650 51
01111366
RR
52public:
53 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
54
bf38cbff 55#if wxUSE_STREAMS
deb2fec0
SB
56 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
57 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
0828c087
VS
58
59 virtual bool CanRead( wxInputStream& stream );
60 virtual bool CanRead( const wxString& name );
bf38cbff 61#endif
01111366
RR
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; }
9e9ee68e 66 inline void SetMimeType(const wxString& type) { m_mime = type; }
01111366
RR
67 inline wxString GetName() const { return m_name; }
68 inline wxString GetExtension() const { return m_extension; }
69 inline long GetType() const { return m_type; }
9e9ee68e
VS
70 inline wxString GetMimeType() const { return m_mime; }
71
01111366
RR
72protected:
73 wxString m_name;
74 wxString m_extension;
9e9ee68e 75 wxString m_mime;
01111366 76 long m_type;
23280650 77
01111366
RR
78};
79
80//-----------------------------------------------------------------------------
81// wxPNGHandler
82//-----------------------------------------------------------------------------
83
9838df2c 84#if wxUSE_LIBPNG
01111366
RR
85class WXDLLEXPORT wxPNGHandler: public wxImageHandler
86{
87 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
23280650 88
01111366
RR
89public:
90
fd0eed64
RR
91 inline wxPNGHandler()
92 {
93 m_name = "PNG file";
94 m_extension = "png";
95 m_type = wxBITMAP_TYPE_PNG;
9e9ee68e 96 m_mime = "image/png";
fd0eed64
RR
97 };
98
bf38cbff 99#if wxUSE_STREAMS
deb2fec0
SB
100 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
101 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
0828c087 102 virtual bool CanRead( wxInputStream& stream );
bf38cbff 103#endif
01111366 104};
ac57418f 105#endif
01111366 106
56b9c741
VS
107//-----------------------------------------------------------------------------
108// wxJPEGHandler
109//-----------------------------------------------------------------------------
110
9ef4a31e 111#if wxUSE_LIBJPEG
56b9c741
VS
112class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
113{
114 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
115
116public:
117
118 inline wxJPEGHandler()
119 {
120 m_name = "JPEG file";
121 m_extension = "jpg";
122 m_type = wxBITMAP_TYPE_JPEG;
9e9ee68e 123 m_mime = "image/jpeg";
56b9c741
VS
124 };
125
ce4169a4 126#if wxUSE_STREAMS
deb2fec0
SB
127 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
128 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
0828c087 129 virtual bool CanRead( wxInputStream& stream );
ce4169a4 130#endif
56b9c741
VS
131};
132#endif
133
01111366
RR
134//-----------------------------------------------------------------------------
135// wxBMPHandler
136//-----------------------------------------------------------------------------
137
138class WXDLLEXPORT wxBMPHandler: public wxImageHandler
139{
140 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
23280650 141
01111366
RR
142public:
143
fd0eed64
RR
144 inline wxBMPHandler()
145 {
146 m_name = "BMP file";
147 m_extension = "bmp";
148 m_type = wxBITMAP_TYPE_BMP;
9e9ee68e 149 m_mime = "image/bmp";
fd0eed64 150 };
01111366 151
bf38cbff 152#if wxUSE_STREAMS
deb2fec0 153 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
0828c087 154 virtual bool CanRead( wxInputStream& stream );
bf38cbff 155#endif
01111366 156};
fd0eed64 157
e1929140
RR
158//-----------------------------------------------------------------------------
159// wxGIFHandler
160//-----------------------------------------------------------------------------
161
ce4169a4
RR
162class WXDLLEXPORT wxGIFHandler : public wxImageHandler
163{
164 DECLARE_DYNAMIC_CLASS(wxGIFHandler)
165
166public:
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 };
e1929140 175
ce4169a4 176#if wxUSE_STREAMS
deb2fec0
SB
177 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
178 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
0828c087 179 virtual bool CanRead( wxInputStream& stream );
ce4169a4
RR
180#endif
181};
e1929140 182
7b2471a0
SB
183//-----------------------------------------------------------------------------
184// wxPNMHandler
185//-----------------------------------------------------------------------------
186
187class WXDLLEXPORT wxPNMHandler : public wxImageHandler
188{
189 DECLARE_DYNAMIC_CLASS(wxPNMHandler)
190
191public:
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 );
0828c087 204 virtual bool CanRead( wxInputStream& stream );
7b2471a0
SB
205#endif
206};
207
b9943f8e
GRG
208//-----------------------------------------------------------------------------
209// wxPCXHandler
210//-----------------------------------------------------------------------------
211
212class WXDLLEXPORT wxPCXHandler : public wxImageHandler
213{
214 DECLARE_DYNAMIC_CLASS(wxPCXHandler)
215
216public:
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
01111366
RR
233//-----------------------------------------------------------------------------
234// wxImage
235//-----------------------------------------------------------------------------
236
237class WXDLLEXPORT wxImage: public wxObject
238{
239 DECLARE_DYNAMIC_CLASS(wxImage)
240
241 friend class WXDLLEXPORT wxImageHandler;
242
243public:
244
245 wxImage();
246 wxImage( int width, int height );
deb2fec0
SB
247 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
248 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
9e9ee68e
VS
249 wxImage( const wxString& name, const wxString& mimetype );
250 wxImage( wxInputStream& stream, const wxString& mimetype );
251
01111366
RR
252 wxImage( const wxImage& image );
253 wxImage( const wxImage* image );
23280650
VZ
254
255 // these functions get implemented in /src/(platform)/bitmap.cpp
4bc67cc5 256 wxImage( const wxBitmap &bitmap );
ce9a75d2 257 operator wxBitmap() const { return ConvertToBitmap(); }
4bc67cc5 258 wxBitmap ConvertToBitmap() const;
01111366
RR
259
260 void Create( int width, int height );
261 void Destroy();
23280650 262
7b2471a0
SB
263 // return the new image with size width*height
264 wxImage GetSubImage( const wxRect& ) const;
265
ce9a75d2
VZ
266 // return the new image with size width*height
267 wxImage Scale( int width, int height ) const;
268
269 // rescales the image in place
23280650 270 void Rescale( int width, int height ) { *this = Scale(width, height); }
ce9a75d2 271
23280650 272 // these routines are slow but safe
ef539066
RR
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 );
23280650 277
deb2fec0 278 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
9e9ee68e 279 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
bf38cbff
JS
280
281#if wxUSE_STREAMS
deb2fec0 282 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
9e9ee68e 283 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
bf38cbff
JS
284#endif
285
01111366 286 virtual bool SaveFile( const wxString& name, int type );
9e9ee68e 287 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
bf38cbff
JS
288
289#if wxUSE_STREAMS
3d05544e 290 virtual bool SaveFile( wxOutputStream& stream, int type );
9e9ee68e 291 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
bf38cbff 292#endif
01111366
RR
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 );
23280650 300
01111366
RR
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
ce9a75d2
VZ
308 wxImage& operator = (const wxImage& image)
309 {
310 if ( (*this) != image )
ce3ed50d 311 Ref(image);
ce9a75d2
VZ
312 return *this;
313 }
ce3ed50d 314
ce9a75d2 315 bool operator == (const wxImage& image)
01111366 316 { return m_refData == image.m_refData; }
23280650 317 bool operator != (const wxImage& image)
01111366
RR
318 { return m_refData != image.m_refData; }
319
ce9a75d2 320 static wxList& GetHandlers() { return sm_handlers; }
01111366
RR
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 );
9e9ee68e
VS
327 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
328
01111366 329 static void CleanUpHandlers();
fd0eed64 330 static void InitStandardHandlers();
01111366
RR
331
332protected:
333
334 static wxList sm_handlers;
23280650 335
01111366
RR
336};
337
338#endif
339 // _WX_IMAGE_H_
9e9ee68e 340