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