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