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