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