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