]>
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; | |
01111366 RR |
32 | class WXDLLEXPORT wxImage; |
33 | ||
34 | //----------------------------------------------------------------------------- | |
35 | // wxImageHandler | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
38 | class WXDLLEXPORT wxImageHandler: public wxObject | |
39 | { | |
ac0ac824 | 40 | DECLARE_CLASS(wxImageHandler) |
23280650 | 41 | |
01111366 RR |
42 | public: |
43 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } | |
44 | ||
bf38cbff | 45 | #if wxUSE_STREAMS |
700ec454 | 46 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); |
deb2fec0 | 47 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); |
8f177c8e | 48 | |
700ec454 | 49 | virtual int GetImageCount( wxInputStream& stream ); |
0828c087 | 50 | |
995612e2 VZ |
51 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } |
52 | bool CanRead( const wxString& name ); | |
8f177c8e | 53 | #endif // wxUSE_STREAMS |
01111366 | 54 | |
995612e2 VZ |
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; } | |
9e9ee68e | 63 | |
01111366 | 64 | protected: |
8f177c8e | 65 | #if wxUSE_STREAMS |
995612e2 | 66 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
8f177c8e | 67 | #endif // wxUSE_STREAMS |
995612e2 | 68 | |
01111366 RR |
69 | wxString m_name; |
70 | wxString m_extension; | |
9e9ee68e | 71 | wxString m_mime; |
01111366 | 72 | long m_type; |
8f177c8e VZ |
73 | }; |
74 | ||
97fdfcc9 DW |
75 | #if !defined(__VISAGECPP__) |
76 | // Why define these here and then again in the individual image format headers?? | |
77 | ||
8f177c8e VZ |
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 | ||
d5e29597 VZ |
160 | // ---------------------------------------------------------------------------- |
161 | // wxPNMHandler | |
162 | // ---------------------------------------------------------------------------- | |
8f177c8e VZ |
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 | }; | |
23280650 | 178 | |
8f177c8e VZ |
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 | |
01111366 | 184 | }; |
8f177c8e | 185 | #endif |
01111366 | 186 | |
8f177c8e VZ |
187 | //----------------------------------------------------------------------------- |
188 | // wxPCXHandler | |
189 | //----------------------------------------------------------------------------- | |
190 | ||
191 | #if wxUSE_PCX | |
192 | class WXDLLEXPORT wxPCXHandler : public wxImageHandler | |
193 | { | |
194 | DECLARE_DYNAMIC_CLASS(wxPCXHandler) | |
195 | ||
196 | public: | |
b9943f8e | 197 | |
8f177c8e VZ |
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 | |
b9943f8e | 213 | |
97fdfcc9 DW |
214 | #endif //__VISAGECPP__ |
215 | ||
01111366 RR |
216 | //----------------------------------------------------------------------------- |
217 | // wxImage | |
218 | //----------------------------------------------------------------------------- | |
219 | ||
c9d01afd GRG |
220 | |
221 | // GRG: Dic/99 | |
222 | class WXDLLEXPORT wxHNode | |
223 | { | |
224 | public: | |
225 | unsigned long index; | |
226 | unsigned long value; | |
227 | }; | |
228 | ||
229 | ||
01111366 RR |
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 ); | |
deb2fec0 SB |
240 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
241 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
9e9ee68e VS |
242 | wxImage( const wxString& name, const wxString& mimetype ); |
243 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
244 | ||
01111366 RR |
245 | wxImage( const wxImage& image ); |
246 | wxImage( const wxImage* image ); | |
23280650 VZ |
247 | |
248 | // these functions get implemented in /src/(platform)/bitmap.cpp | |
4bc67cc5 | 249 | wxImage( const wxBitmap &bitmap ); |
ce9a75d2 | 250 | operator wxBitmap() const { return ConvertToBitmap(); } |
4bc67cc5 | 251 | wxBitmap ConvertToBitmap() const; |
01111366 RR |
252 | |
253 | void Create( int width, int height ); | |
254 | void Destroy(); | |
23280650 | 255 | |
7b2471a0 SB |
256 | // return the new image with size width*height |
257 | wxImage GetSubImage( const wxRect& ) const; | |
258 | ||
ce9a75d2 VZ |
259 | // return the new image with size width*height |
260 | wxImage Scale( int width, int height ) const; | |
261 | ||
262 | // rescales the image in place | |
6e807169 | 263 | wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); } |
ce9a75d2 | 264 | |
23280650 | 265 | // these routines are slow but safe |
ef539066 RR |
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 ); | |
23280650 | 270 | |
87202f78 | 271 | static bool CanRead( const wxString& name ); |
deb2fec0 | 272 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
9e9ee68e | 273 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
274 | |
275 | #if wxUSE_STREAMS | |
87202f78 | 276 | static bool CanRead( wxInputStream& stream ); |
deb2fec0 | 277 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); |
9e9ee68e | 278 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); |
bf38cbff JS |
279 | #endif |
280 | ||
01111366 | 281 | virtual bool SaveFile( const wxString& name, int type ); |
9e9ee68e | 282 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
283 | |
284 | #if wxUSE_STREAMS | |
3d05544e | 285 | virtual bool SaveFile( wxOutputStream& stream, int type ); |
9e9ee68e | 286 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); |
bf38cbff | 287 | #endif |
01111366 RR |
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 ); | |
23280650 | 295 | |
01111366 RR |
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 | ||
ce9a75d2 VZ |
303 | wxImage& operator = (const wxImage& image) |
304 | { | |
305 | if ( (*this) != image ) | |
ce3ed50d | 306 | Ref(image); |
ce9a75d2 VZ |
307 | return *this; |
308 | } | |
ce3ed50d | 309 | |
ce9a75d2 | 310 | bool operator == (const wxImage& image) |
01111366 | 311 | { return m_refData == image.m_refData; } |
23280650 | 312 | bool operator != (const wxImage& image) |
01111366 RR |
313 | { return m_refData != image.m_refData; } |
314 | ||
ce9a75d2 | 315 | static wxList& GetHandlers() { return sm_handlers; } |
01111366 RR |
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 ); | |
9e9ee68e VS |
322 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); |
323 | ||
01111366 | 324 | static void CleanUpHandlers(); |
fd0eed64 | 325 | static void InitStandardHandlers(); |
a091d18c | 326 | |
c9d01afd | 327 | // GRG: Dic/99 |
cc9f7d79 | 328 | unsigned long CountColours( unsigned long stopafter = -1 ); |
c9d01afd GRG |
329 | unsigned long ComputeHistogram( wxHashTable &h ); |
330 | ||
331 | ||
01111366 RR |
332 | protected: |
333 | ||
334 | static wxList sm_handlers; | |
23280650 | 335 | |
01111366 RR |
336 | }; |
337 | ||
8f493002 | 338 | |
a091d18c | 339 | extern void WXDLLEXPORT wxInitAllImageHandlers(); |
b5a4a47d | 340 | |
8f493002 VS |
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 | ||
01111366 RR |
354 | #endif |
355 | // _WX_IMAGE_H_ | |
9e9ee68e | 356 |