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