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