]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
*** empty log message ***
[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 #if wxUSE_GIF
40 class WXDLLEXPORT wxGIFHandler;
41 #endif
42 #if wxUSE_PNM
43 class WXDLLEXPORT wxPNMHandler;
44 #endif
45 #if wxUSE_PCX
46 class WXDLLEXPORT wxPCXHandler;
47 #endif
48 class WXDLLEXPORT wxImage;
49
50 //-----------------------------------------------------------------------------
51 // wxImageHandler
52 //-----------------------------------------------------------------------------
53
54 class WXDLLEXPORT wxImageHandler: public wxObject
55 {
56 DECLARE_DYNAMIC_CLASS(wxImageHandler)
57
58 public:
59 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
60
61 #if wxUSE_STREAMS
62 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
63 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
64
65 virtual bool CanRead( wxInputStream& stream );
66 virtual bool CanRead( const wxString& name );
67 #endif
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; }
72 inline void SetMimeType(const wxString& type) { m_mime = type; }
73 inline wxString GetName() const { return m_name; }
74 inline wxString GetExtension() const { return m_extension; }
75 inline long GetType() const { return m_type; }
76 inline wxString GetMimeType() const { return m_mime; }
77
78 protected:
79 wxString m_name;
80 wxString m_extension;
81 wxString m_mime;
82 long m_type;
83
84 };
85
86 //-----------------------------------------------------------------------------
87 // wxPNGHandler
88 //-----------------------------------------------------------------------------
89
90 #if wxUSE_LIBPNG
91 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
92 {
93 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
94
95 public:
96
97 inline wxPNGHandler()
98 {
99 m_name = "PNG file";
100 m_extension = "png";
101 m_type = wxBITMAP_TYPE_PNG;
102 m_mime = "image/png";
103 };
104
105 #if wxUSE_STREAMS
106 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
107 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
108 virtual bool CanRead( wxInputStream& stream );
109 private:
110 // hiding base class virtuals again!
111 inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
112 #endif
113 };
114 #endif
115
116 //-----------------------------------------------------------------------------
117 // wxJPEGHandler
118 //-----------------------------------------------------------------------------
119
120 #if wxUSE_LIBJPEG
121 class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
122 {
123 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
124
125 public:
126
127 inline wxJPEGHandler()
128 {
129 m_name = "JPEG file";
130 m_extension = "jpg";
131 m_type = wxBITMAP_TYPE_JPEG;
132 m_mime = "image/jpeg";
133 };
134
135 #if wxUSE_STREAMS
136 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
137 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
138 virtual bool CanRead( wxInputStream& stream );
139 private:
140 // hiding base class virtuals again!
141 inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
142 #endif
143 };
144 #endif
145
146 //-----------------------------------------------------------------------------
147 // wxBMPHandler
148 //-----------------------------------------------------------------------------
149
150 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
151 {
152 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
153
154 public:
155
156 inline wxBMPHandler()
157 {
158 m_name = "BMP file";
159 m_extension = "bmp";
160 m_type = wxBITMAP_TYPE_BMP;
161 m_mime = "image/bmp";
162 };
163
164 #if wxUSE_STREAMS
165 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
166 virtual bool CanRead( wxInputStream& stream );
167 private:
168 // hiding base class virtuals again!
169 inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
170 #endif
171 };
172
173 //-----------------------------------------------------------------------------
174 // wxGIFHandler
175 //-----------------------------------------------------------------------------
176
177 #if wxUSE_GIF
178
179 class WXDLLEXPORT wxGIFHandler : public wxImageHandler
180 {
181 DECLARE_DYNAMIC_CLASS(wxGIFHandler)
182
183 public:
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 };
192
193 #if wxUSE_STREAMS
194 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
195 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
196 virtual bool CanRead( wxInputStream& stream );
197 private:
198 // hiding base class virtuals again!
199 inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
200 #endif
201 };
202 #endif
203
204 //-----------------------------------------------------------------------------
205 // wxPNMHandler
206 //-----------------------------------------------------------------------------
207
208 #if wxUSE_PNM
209 class WXDLLEXPORT wxPNMHandler : public wxImageHandler
210 {
211 DECLARE_DYNAMIC_CLASS(wxPNMHandler)
212
213 public:
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 );
226 virtual bool CanRead( wxInputStream& stream );
227 private:
228 // hiding base class virtuals again!
229 inline bool CanRead( const wxString& name ) { return(wxImageHandler::CanRead(name)); };
230 #endif
231 };
232 #endif
233
234 //-----------------------------------------------------------------------------
235 // wxPCXHandler
236 //-----------------------------------------------------------------------------
237
238 #if wxUSE_PCX
239 class WXDLLEXPORT wxPCXHandler : public wxImageHandler
240 {
241 DECLARE_DYNAMIC_CLASS(wxPCXHandler)
242
243 public:
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 };
259 #endif
260
261 //-----------------------------------------------------------------------------
262 // wxImage
263 //-----------------------------------------------------------------------------
264
265 class WXDLLEXPORT wxImage: public wxObject
266 {
267 DECLARE_DYNAMIC_CLASS(wxImage)
268
269 friend class WXDLLEXPORT wxImageHandler;
270
271 public:
272
273 wxImage();
274 wxImage( int width, int height );
275 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
276 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
277 wxImage( const wxString& name, const wxString& mimetype );
278 wxImage( wxInputStream& stream, const wxString& mimetype );
279
280 wxImage( const wxImage& image );
281 wxImage( const wxImage* image );
282
283 // these functions get implemented in /src/(platform)/bitmap.cpp
284 wxImage( const wxBitmap &bitmap );
285 operator wxBitmap() const { return ConvertToBitmap(); }
286 wxBitmap ConvertToBitmap() const;
287
288 void Create( int width, int height );
289 void Destroy();
290
291 // return the new image with size width*height
292 wxImage GetSubImage( const wxRect& ) const;
293
294 // return the new image with size width*height
295 wxImage Scale( int width, int height ) const;
296
297 // rescales the image in place
298 void Rescale( int width, int height ) { *this = Scale(width, height); }
299
300 // these routines are slow but safe
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 );
305
306 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
307 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
308
309 #if wxUSE_STREAMS
310 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
311 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
312 #endif
313
314 virtual bool SaveFile( const wxString& name, int type );
315 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
316
317 #if wxUSE_STREAMS
318 virtual bool SaveFile( wxOutputStream& stream, int type );
319 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
320 #endif
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 );
328
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
336 wxImage& operator = (const wxImage& image)
337 {
338 if ( (*this) != image )
339 Ref(image);
340 return *this;
341 }
342
343 bool operator == (const wxImage& image)
344 { return m_refData == image.m_refData; }
345 bool operator != (const wxImage& image)
346 { return m_refData != image.m_refData; }
347
348 static wxList& GetHandlers() { return sm_handlers; }
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 );
355 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
356
357 static void CleanUpHandlers();
358 static void InitStandardHandlers();
359
360 protected:
361
362 static wxList sm_handlers;
363
364 };
365
366 #endif
367 // _WX_IMAGE_H_
368