]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
93d16b3778fdbc887b86ffbaf0d34d8506367017
[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 // wxPNMHandler
159 // ----------------------------------------------------------------------------
160
161 #if wxUSE_PNM
162 class WXDLLEXPORT wxPNMHandler : public wxImageHandler
163 {
164 DECLARE_DYNAMIC_CLASS(wxPNMHandler)
165
166 public:
167
168 inline wxPNMHandler()
169 {
170 m_name = "PNM file";
171 m_extension = "pnm";
172 m_type = wxBITMAP_TYPE_PNM;
173 m_mime = "image/pnm";
174 };
175
176 #if wxUSE_STREAMS
177 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 );
178 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
179 virtual bool DoCanRead( wxInputStream& stream );
180 #endif
181 };
182 #endif
183
184 //-----------------------------------------------------------------------------
185 // wxPCXHandler
186 //-----------------------------------------------------------------------------
187
188 #if wxUSE_PCX
189 class WXDLLEXPORT wxPCXHandler : public wxImageHandler
190 {
191 DECLARE_DYNAMIC_CLASS(wxPCXHandler)
192
193 public:
194
195 inline wxPCXHandler()
196 {
197 m_name = "PCX file";
198 m_extension = "pcx";
199 m_type = wxBITMAP_TYPE_PCX;
200 m_mime = "image/pcx";
201 };
202
203 #if wxUSE_STREAMS
204 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 );
205 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
206 virtual bool DoCanRead( wxInputStream& stream );
207 #endif // wxUSE_STREAMS
208 };
209 #endif // wxUSE_PCX
210
211 //-----------------------------------------------------------------------------
212 // wxImage
213 //-----------------------------------------------------------------------------
214
215
216 // GRG: Dic/99
217 class WXDLLEXPORT wxHNode
218 {
219 public:
220 unsigned long index;
221 unsigned long value;
222 };
223
224
225 class WXDLLEXPORT wxImage: public wxObject
226 {
227 DECLARE_DYNAMIC_CLASS(wxImage)
228
229 friend class WXDLLEXPORT wxImageHandler;
230
231 public:
232
233 wxImage();
234 wxImage( int width, int height );
235 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
236 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
237 wxImage( const wxString& name, const wxString& mimetype );
238 wxImage( wxInputStream& stream, const wxString& mimetype );
239
240 wxImage( const wxImage& image );
241 wxImage( const wxImage* image );
242
243 // these functions get implemented in /src/(platform)/bitmap.cpp
244 wxImage( const wxBitmap &bitmap );
245 operator wxBitmap() const { return ConvertToBitmap(); }
246 wxBitmap ConvertToBitmap() const;
247
248 void Create( int width, int height );
249 void Destroy();
250
251 // return the new image with size width*height
252 wxImage GetSubImage( const wxRect& ) const;
253
254 // return the new image with size width*height
255 wxImage Scale( int width, int height ) const;
256
257 // rescales the image in place
258 void Rescale( int width, int height ) { *this = Scale(width, height); }
259
260 // these routines are slow but safe
261 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
262 unsigned char GetRed( int x, int y );
263 unsigned char GetGreen( int x, int y );
264 unsigned char GetBlue( int x, int y );
265
266 static bool CanRead( const wxString& name );
267 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
268 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
269
270 #if wxUSE_STREAMS
271 static bool CanRead( wxInputStream& stream );
272 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
273 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
274 #endif
275
276 virtual bool SaveFile( const wxString& name, int type );
277 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
278
279 #if wxUSE_STREAMS
280 virtual bool SaveFile( wxOutputStream& stream, int type );
281 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
282 #endif
283
284 bool Ok() const;
285 int GetWidth() const;
286 int GetHeight() const;
287
288 char unsigned *GetData() const;
289 void SetData( char unsigned *data );
290
291 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
292 unsigned char GetMaskRed() const;
293 unsigned char GetMaskGreen() const;
294 unsigned char GetMaskBlue() const;
295 void SetMask( bool mask = TRUE );
296 bool HasMask() const;
297
298 wxImage& operator = (const wxImage& image)
299 {
300 if ( (*this) != image )
301 Ref(image);
302 return *this;
303 }
304
305 bool operator == (const wxImage& image)
306 { return m_refData == image.m_refData; }
307 bool operator != (const wxImage& image)
308 { return m_refData != image.m_refData; }
309
310 static wxList& GetHandlers() { return sm_handlers; }
311 static void AddHandler( wxImageHandler *handler );
312 static void InsertHandler( wxImageHandler *handler );
313 static bool RemoveHandler( const wxString& name );
314 static wxImageHandler *FindHandler( const wxString& name );
315 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
316 static wxImageHandler *FindHandler( long imageType );
317 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
318
319 static void CleanUpHandlers();
320 static void InitStandardHandlers();
321
322 // GRG: Dic/99
323 unsigned long CountColours( unsigned long stopafter = -1 );
324 unsigned long ComputeHistogram( wxHashTable &h );
325
326
327 protected:
328
329 static wxList sm_handlers;
330
331 };
332
333
334 extern void WXDLLEXPORT wxInitAllImageHandlers();
335
336
337 //-----------------------------------------------------------------------------
338 // wxImage handlers
339 //-----------------------------------------------------------------------------
340
341 #include "wx/imagbmp.h"
342 #include "wx/imagpng.h"
343 #include "wx/imaggif.h"
344 #include "wx/imagpcx.h"
345 #include "wx/imagjpeg.h"
346 #include "wx/imagtiff.h"
347 #include "wx/imagpnm.h"
348
349 #endif
350 // _WX_IMAGE_H_
351