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