]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Header file for MSW GSocket
[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 #endif
110 };
111 #endif
112
113 //-----------------------------------------------------------------------------
114 // wxJPEGHandler
115 //-----------------------------------------------------------------------------
116
117 #if wxUSE_LIBJPEG
118 class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
119 {
120 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
121
122 public:
123
124 inline wxJPEGHandler()
125 {
126 m_name = "JPEG file";
127 m_extension = "jpg";
128 m_type = wxBITMAP_TYPE_JPEG;
129 m_mime = "image/jpeg";
130 };
131
132 #if wxUSE_STREAMS
133 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
134 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
135 virtual bool CanRead( wxInputStream& stream );
136 #endif
137 };
138 #endif
139
140 //-----------------------------------------------------------------------------
141 // wxBMPHandler
142 //-----------------------------------------------------------------------------
143
144 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
145 {
146 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
147
148 public:
149
150 inline wxBMPHandler()
151 {
152 m_name = "BMP file";
153 m_extension = "bmp";
154 m_type = wxBITMAP_TYPE_BMP;
155 m_mime = "image/bmp";
156 };
157
158 #if wxUSE_STREAMS
159 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
160 virtual bool CanRead( wxInputStream& stream );
161 #endif
162 };
163
164 //-----------------------------------------------------------------------------
165 // wxGIFHandler
166 //-----------------------------------------------------------------------------
167
168 #if wxUSE_LIBGIF
169
170 class WXDLLEXPORT wxGIFHandler : public wxImageHandler
171 {
172 DECLARE_DYNAMIC_CLASS(wxGIFHandler)
173
174 public:
175
176 inline wxGIFHandler()
177 {
178 m_name = "GIF file";
179 m_extension = "gif";
180 m_type = wxBITMAP_TYPE_GIF;
181 m_mime = "image/gif";
182 };
183
184 #if wxUSE_STREAMS
185 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
186 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
187 virtual bool CanRead( wxInputStream& stream );
188 #endif
189 };
190 #endif
191
192 //-----------------------------------------------------------------------------
193 // wxPNMHandler
194 //-----------------------------------------------------------------------------
195
196 #if wxUSE_PNM
197 class WXDLLEXPORT wxPNMHandler : public wxImageHandler
198 {
199 DECLARE_DYNAMIC_CLASS(wxPNMHandler)
200
201 public:
202
203 inline wxPNMHandler()
204 {
205 m_name = "PNM file";
206 m_extension = "pnm";
207 m_type = wxBITMAP_TYPE_PNM;
208 m_mime = "image/pnm";
209 };
210
211 #if wxUSE_STREAMS
212 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
213 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
214 virtual bool CanRead( wxInputStream& stream );
215 #endif
216 };
217 #endif
218
219 //-----------------------------------------------------------------------------
220 // wxPCXHandler
221 //-----------------------------------------------------------------------------
222
223 #if wxUSE_PCX
224 class WXDLLEXPORT wxPCXHandler : public wxImageHandler
225 {
226 DECLARE_DYNAMIC_CLASS(wxPCXHandler)
227
228 public:
229
230 inline wxPCXHandler()
231 {
232 m_name = "PCX file";
233 m_extension = "pcx";
234 m_type = wxBITMAP_TYPE_PCX;
235 m_mime = "image/pcx";
236 };
237
238 #if wxUSE_STREAMS
239 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE );
240 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
241 virtual bool CanRead( wxInputStream& stream );
242 #endif
243 };
244 #endif
245
246 //-----------------------------------------------------------------------------
247 // wxImage
248 //-----------------------------------------------------------------------------
249
250 class WXDLLEXPORT wxImage: public wxObject
251 {
252 DECLARE_DYNAMIC_CLASS(wxImage)
253
254 friend class WXDLLEXPORT wxImageHandler;
255
256 public:
257
258 wxImage();
259 wxImage( int width, int height );
260 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
261 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
262 wxImage( const wxString& name, const wxString& mimetype );
263 wxImage( wxInputStream& stream, const wxString& mimetype );
264
265 wxImage( const wxImage& image );
266 wxImage( const wxImage* image );
267
268 // these functions get implemented in /src/(platform)/bitmap.cpp
269 wxImage( const wxBitmap &bitmap );
270 operator wxBitmap() const { return ConvertToBitmap(); }
271 wxBitmap ConvertToBitmap() const;
272
273 void Create( int width, int height );
274 void Destroy();
275
276 // return the new image with size width*height
277 wxImage GetSubImage( const wxRect& ) const;
278
279 // return the new image with size width*height
280 wxImage Scale( int width, int height ) const;
281
282 // rescales the image in place
283 void Rescale( int width, int height ) { *this = Scale(width, height); }
284
285 // these routines are slow but safe
286 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
287 unsigned char GetRed( int x, int y );
288 unsigned char GetGreen( int x, int y );
289 unsigned char GetBlue( int x, int y );
290
291 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
292 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
293
294 #if wxUSE_STREAMS
295 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
296 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
297 #endif
298
299 virtual bool SaveFile( const wxString& name, int type );
300 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
301
302 #if wxUSE_STREAMS
303 virtual bool SaveFile( wxOutputStream& stream, int type );
304 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
305 #endif
306
307 bool Ok() const;
308 int GetWidth() const;
309 int GetHeight() const;
310
311 char unsigned *GetData() const;
312 void SetData( char unsigned *data );
313
314 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
315 unsigned char GetMaskRed() const;
316 unsigned char GetMaskGreen() const;
317 unsigned char GetMaskBlue() const;
318 void SetMask( bool mask = TRUE );
319 bool HasMask() const;
320
321 wxImage& operator = (const wxImage& image)
322 {
323 if ( (*this) != image )
324 Ref(image);
325 return *this;
326 }
327
328 bool operator == (const wxImage& image)
329 { return m_refData == image.m_refData; }
330 bool operator != (const wxImage& image)
331 { return m_refData != image.m_refData; }
332
333 static wxList& GetHandlers() { return sm_handlers; }
334 static void AddHandler( wxImageHandler *handler );
335 static void InsertHandler( wxImageHandler *handler );
336 static bool RemoveHandler( const wxString& name );
337 static wxImageHandler *FindHandler( const wxString& name );
338 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
339 static wxImageHandler *FindHandler( long imageType );
340 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
341
342 static void CleanUpHandlers();
343 static void InitStandardHandlers();
344
345 protected:
346
347 static wxList sm_handlers;
348
349 };
350
351 #endif
352 // _WX_IMAGE_H_
353