]>
Commit | Line | Data |
---|---|---|
01111366 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: image.h | |
3 | // Purpose: wxImage class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert Roebling | |
23280650 | 7 | // Licence: wxWindows licence |
01111366 RR |
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" | |
23280650 | 21 | #include "wx/bitmap.h" |
bf38cbff JS |
22 | |
23 | #if wxUSE_STREAMS | |
b9943f8e | 24 | # include "wx/stream.h" |
bf38cbff | 25 | #endif |
01111366 RR |
26 | |
27 | //----------------------------------------------------------------------------- | |
28 | // classes | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | class WXDLLEXPORT wxImageHandler; | |
9838df2c | 32 | #if wxUSE_LIBPNG |
01111366 | 33 | class WXDLLEXPORT wxPNGHandler; |
ac57418f | 34 | #endif |
56b9c741 VS |
35 | #if wxUSE_LIBJPEG |
36 | class WXDLLEXPORT wxJPEGHandler; | |
37 | #endif | |
01111366 | 38 | class WXDLLEXPORT wxBMPHandler; |
1044a386 | 39 | #if wxUSE_GIF |
b9943f8e | 40 | class WXDLLEXPORT wxGIFHandler; |
1044a386 JS |
41 | #endif |
42 | #if wxUSE_PNM | |
b9943f8e | 43 | class WXDLLEXPORT wxPNMHandler; |
1044a386 JS |
44 | #endif |
45 | #if wxUSE_PCX | |
b9943f8e | 46 | class WXDLLEXPORT wxPCXHandler; |
1044a386 | 47 | #endif |
01111366 RR |
48 | class WXDLLEXPORT wxImage; |
49 | ||
50 | //----------------------------------------------------------------------------- | |
51 | // wxImageHandler | |
52 | //----------------------------------------------------------------------------- | |
53 | ||
54 | class WXDLLEXPORT wxImageHandler: public wxObject | |
55 | { | |
56 | DECLARE_DYNAMIC_CLASS(wxImageHandler) | |
23280650 | 57 | |
01111366 RR |
58 | public: |
59 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } | |
60 | ||
bf38cbff | 61 | #if wxUSE_STREAMS |
deb2fec0 SB |
62 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
63 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
0828c087 | 64 | |
995612e2 VZ |
65 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } |
66 | bool CanRead( const wxString& name ); | |
bf38cbff | 67 | #endif |
01111366 | 68 | |
995612e2 VZ |
69 | void SetName(const wxString& name) { m_name = name; } |
70 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
71 | void SetType(long type) { m_type = type; } | |
72 | void SetMimeType(const wxString& type) { m_mime = type; } | |
73 | wxString GetName() const { return m_name; } | |
74 | wxString GetExtension() const { return m_extension; } | |
75 | long GetType() const { return m_type; } | |
76 | wxString GetMimeType() const { return m_mime; } | |
9e9ee68e | 77 | |
01111366 | 78 | protected: |
995612e2 VZ |
79 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
80 | ||
01111366 RR |
81 | wxString m_name; |
82 | wxString m_extension; | |
9e9ee68e | 83 | wxString m_mime; |
01111366 | 84 | long m_type; |
23280650 | 85 | |
01111366 RR |
86 | }; |
87 | ||
88 | //----------------------------------------------------------------------------- | |
89 | // wxPNGHandler | |
90 | //----------------------------------------------------------------------------- | |
91 | ||
9838df2c | 92 | #if wxUSE_LIBPNG |
01111366 RR |
93 | class WXDLLEXPORT wxPNGHandler: public wxImageHandler |
94 | { | |
95 | DECLARE_DYNAMIC_CLASS(wxPNGHandler) | |
23280650 | 96 | |
01111366 RR |
97 | public: |
98 | ||
fd0eed64 RR |
99 | inline wxPNGHandler() |
100 | { | |
101 | m_name = "PNG file"; | |
102 | m_extension = "png"; | |
103 | m_type = wxBITMAP_TYPE_PNG; | |
9e9ee68e | 104 | m_mime = "image/png"; |
fd0eed64 RR |
105 | }; |
106 | ||
bf38cbff | 107 | #if wxUSE_STREAMS |
deb2fec0 SB |
108 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
109 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
995612e2 | 110 | virtual bool DoCanRead( wxInputStream& stream ); |
bf38cbff | 111 | #endif |
01111366 | 112 | }; |
ac57418f | 113 | #endif |
01111366 | 114 | |
56b9c741 VS |
115 | //----------------------------------------------------------------------------- |
116 | // wxJPEGHandler | |
117 | //----------------------------------------------------------------------------- | |
118 | ||
9ef4a31e | 119 | #if wxUSE_LIBJPEG |
56b9c741 VS |
120 | class WXDLLEXPORT wxJPEGHandler: public wxImageHandler |
121 | { | |
122 | DECLARE_DYNAMIC_CLASS(wxJPEGHandler) | |
123 | ||
124 | public: | |
125 | ||
126 | inline wxJPEGHandler() | |
127 | { | |
128 | m_name = "JPEG file"; | |
129 | m_extension = "jpg"; | |
130 | m_type = wxBITMAP_TYPE_JPEG; | |
9e9ee68e | 131 | m_mime = "image/jpeg"; |
56b9c741 VS |
132 | }; |
133 | ||
ce4169a4 | 134 | #if wxUSE_STREAMS |
deb2fec0 SB |
135 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
136 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
995612e2 | 137 | virtual bool DoCanRead( wxInputStream& stream ); |
ce4169a4 | 138 | #endif |
56b9c741 VS |
139 | }; |
140 | #endif | |
141 | ||
01111366 RR |
142 | //----------------------------------------------------------------------------- |
143 | // wxBMPHandler | |
144 | //----------------------------------------------------------------------------- | |
145 | ||
146 | class WXDLLEXPORT wxBMPHandler: public wxImageHandler | |
147 | { | |
148 | DECLARE_DYNAMIC_CLASS(wxBMPHandler) | |
23280650 | 149 | |
01111366 RR |
150 | public: |
151 | ||
fd0eed64 RR |
152 | inline wxBMPHandler() |
153 | { | |
154 | m_name = "BMP file"; | |
155 | m_extension = "bmp"; | |
156 | m_type = wxBITMAP_TYPE_BMP; | |
9e9ee68e | 157 | m_mime = "image/bmp"; |
fd0eed64 | 158 | }; |
01111366 | 159 | |
bf38cbff | 160 | #if wxUSE_STREAMS |
deb2fec0 | 161 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
995612e2 | 162 | virtual bool DoCanRead( wxInputStream& stream ); |
bf38cbff | 163 | #endif |
01111366 | 164 | }; |
fd0eed64 | 165 | |
e1929140 RR |
166 | //----------------------------------------------------------------------------- |
167 | // wxGIFHandler | |
168 | //----------------------------------------------------------------------------- | |
169 | ||
83413d6d GRG |
170 | #if wxUSE_GIF |
171 | ||
ce4169a4 RR |
172 | class WXDLLEXPORT wxGIFHandler : public wxImageHandler |
173 | { | |
174 | DECLARE_DYNAMIC_CLASS(wxGIFHandler) | |
175 | ||
176 | public: | |
177 | ||
178 | inline wxGIFHandler() | |
179 | { | |
180 | m_name = "GIF file"; | |
181 | m_extension = "gif"; | |
182 | m_type = wxBITMAP_TYPE_GIF; | |
183 | m_mime = "image/gif"; | |
184 | }; | |
e1929140 | 185 | |
ce4169a4 | 186 | #if wxUSE_STREAMS |
deb2fec0 SB |
187 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); |
188 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
995612e2 | 189 | virtual bool DoCanRead( wxInputStream& stream ); |
ce4169a4 RR |
190 | #endif |
191 | }; | |
aa6d9706 GL |
192 | #endif |
193 | ||
7b2471a0 SB |
194 | //----------------------------------------------------------------------------- |
195 | // wxPNMHandler | |
196 | //----------------------------------------------------------------------------- | |
197 | ||
1044a386 | 198 | #if wxUSE_PNM |
7b2471a0 SB |
199 | class WXDLLEXPORT wxPNMHandler : public wxImageHandler |
200 | { | |
201 | DECLARE_DYNAMIC_CLASS(wxPNMHandler) | |
202 | ||
203 | public: | |
204 | ||
205 | inline wxPNMHandler() | |
206 | { | |
207 | m_name = "PNM file"; | |
208 | m_extension = "pnm"; | |
209 | m_type = wxBITMAP_TYPE_PNM; | |
210 | m_mime = "image/pnm"; | |
211 | }; | |
212 | ||
213 | #if wxUSE_STREAMS | |
214 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); | |
215 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
995612e2 | 216 | virtual bool DoCanRead( wxInputStream& stream ); |
7b2471a0 SB |
217 | #endif |
218 | }; | |
1044a386 | 219 | #endif |
7b2471a0 | 220 | |
b9943f8e GRG |
221 | //----------------------------------------------------------------------------- |
222 | // wxPCXHandler | |
223 | //----------------------------------------------------------------------------- | |
224 | ||
1044a386 | 225 | #if wxUSE_PCX |
b9943f8e GRG |
226 | class WXDLLEXPORT wxPCXHandler : public wxImageHandler |
227 | { | |
228 | DECLARE_DYNAMIC_CLASS(wxPCXHandler) | |
229 | ||
230 | public: | |
231 | ||
232 | inline wxPCXHandler() | |
233 | { | |
234 | m_name = "PCX file"; | |
235 | m_extension = "pcx"; | |
236 | m_type = wxBITMAP_TYPE_PCX; | |
237 | m_mime = "image/pcx"; | |
238 | }; | |
239 | ||
240 | #if wxUSE_STREAMS | |
241 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE ); | |
242 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
995612e2 | 243 | virtual bool DoCanRead( wxInputStream& stream ); |
b9943f8e | 244 | }; |
1044a386 | 245 | #endif |
b9943f8e | 246 | |
01111366 RR |
247 | //----------------------------------------------------------------------------- |
248 | // wxImage | |
249 | //----------------------------------------------------------------------------- | |
250 | ||
251 | class WXDLLEXPORT wxImage: public wxObject | |
252 | { | |
253 | DECLARE_DYNAMIC_CLASS(wxImage) | |
254 | ||
255 | friend class WXDLLEXPORT wxImageHandler; | |
256 | ||
257 | public: | |
258 | ||
259 | wxImage(); | |
260 | wxImage( int width, int height ); | |
deb2fec0 SB |
261 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
262 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
9e9ee68e VS |
263 | wxImage( const wxString& name, const wxString& mimetype ); |
264 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
265 | ||
01111366 RR |
266 | wxImage( const wxImage& image ); |
267 | wxImage( const wxImage* image ); | |
23280650 VZ |
268 | |
269 | // these functions get implemented in /src/(platform)/bitmap.cpp | |
4bc67cc5 | 270 | wxImage( const wxBitmap &bitmap ); |
ce9a75d2 | 271 | operator wxBitmap() const { return ConvertToBitmap(); } |
4bc67cc5 | 272 | wxBitmap ConvertToBitmap() const; |
01111366 RR |
273 | |
274 | void Create( int width, int height ); | |
275 | void Destroy(); | |
23280650 | 276 | |
7b2471a0 SB |
277 | // return the new image with size width*height |
278 | wxImage GetSubImage( const wxRect& ) const; | |
279 | ||
ce9a75d2 VZ |
280 | // return the new image with size width*height |
281 | wxImage Scale( int width, int height ) const; | |
282 | ||
283 | // rescales the image in place | |
23280650 | 284 | void Rescale( int width, int height ) { *this = Scale(width, height); } |
ce9a75d2 | 285 | |
23280650 | 286 | // these routines are slow but safe |
ef539066 RR |
287 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); |
288 | unsigned char GetRed( int x, int y ); | |
289 | unsigned char GetGreen( int x, int y ); | |
290 | unsigned char GetBlue( int x, int y ); | |
23280650 | 291 | |
deb2fec0 | 292 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
9e9ee68e | 293 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
294 | |
295 | #if wxUSE_STREAMS | |
deb2fec0 | 296 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); |
9e9ee68e | 297 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); |
bf38cbff JS |
298 | #endif |
299 | ||
01111366 | 300 | virtual bool SaveFile( const wxString& name, int type ); |
9e9ee68e | 301 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
302 | |
303 | #if wxUSE_STREAMS | |
3d05544e | 304 | virtual bool SaveFile( wxOutputStream& stream, int type ); |
9e9ee68e | 305 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); |
bf38cbff | 306 | #endif |
01111366 RR |
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 ); | |
23280650 | 314 | |
01111366 RR |
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 | ||
ce9a75d2 VZ |
322 | wxImage& operator = (const wxImage& image) |
323 | { | |
324 | if ( (*this) != image ) | |
ce3ed50d | 325 | Ref(image); |
ce9a75d2 VZ |
326 | return *this; |
327 | } | |
ce3ed50d | 328 | |
ce9a75d2 | 329 | bool operator == (const wxImage& image) |
01111366 | 330 | { return m_refData == image.m_refData; } |
23280650 | 331 | bool operator != (const wxImage& image) |
01111366 RR |
332 | { return m_refData != image.m_refData; } |
333 | ||
ce9a75d2 | 334 | static wxList& GetHandlers() { return sm_handlers; } |
01111366 RR |
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 ); | |
9e9ee68e VS |
341 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); |
342 | ||
01111366 | 343 | static void CleanUpHandlers(); |
fd0eed64 | 344 | static void InitStandardHandlers(); |
a091d18c | 345 | |
01111366 RR |
346 | protected: |
347 | ||
348 | static wxList sm_handlers; | |
23280650 | 349 | |
01111366 RR |
350 | }; |
351 | ||
a091d18c | 352 | extern void WXDLLEXPORT wxInitAllImageHandlers(); |
b5a4a47d | 353 | |
01111366 RR |
354 | #endif |
355 | // _WX_IMAGE_H_ | |
9e9ee68e | 356 |