1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxImage class
4 // Author: Robert Roebling
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
14 #pragma interface "image.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/gdicmn.h"
21 #include "wx/bitmap.h"
24 # include "wx/stream.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 class WXDLLEXPORT wxImageHandler
;
33 class WXDLLEXPORT wxPNGHandler
;
36 class WXDLLEXPORT wxJPEGHandler
;
39 class WXDLLEXPORT wxTIFFHandler
;
41 class WXDLLEXPORT wxBMPHandler
;
43 class WXDLLEXPORT wxGIFHandler
;
46 class WXDLLEXPORT wxPNMHandler
;
49 class WXDLLEXPORT wxPCXHandler
;
51 class WXDLLEXPORT wxImage
;
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
57 class WXDLLEXPORT wxImageHandler
: public wxObject
59 DECLARE_CLASS(wxImageHandler
)
62 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
65 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
66 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
68 bool CanRead( wxInputStream
& stream
) { return DoCanRead(stream
); }
69 bool CanRead( const wxString
& name
);
72 void SetName(const wxString
& name
) { m_name
= name
; }
73 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
74 void SetType(long type
) { m_type
= type
; }
75 void SetMimeType(const wxString
& type
) { m_mime
= type
; }
76 wxString
GetName() const { return m_name
; }
77 wxString
GetExtension() const { return m_extension
; }
78 long GetType() const { return m_type
; }
79 wxString
GetMimeType() const { return m_mime
; }
82 virtual bool DoCanRead( wxInputStream
& stream
) = 0;
91 //-----------------------------------------------------------------------------
93 //-----------------------------------------------------------------------------
96 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
98 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
102 inline wxPNGHandler()
106 m_type
= wxBITMAP_TYPE_PNG
;
107 m_mime
= "image/png";
111 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
112 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
113 virtual bool DoCanRead( wxInputStream
& stream
);
118 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
123 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
125 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
129 inline wxJPEGHandler()
131 m_name
= "JPEG file";
133 m_type
= wxBITMAP_TYPE_JPEG
;
134 m_mime
= "image/jpeg";
138 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
139 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
140 virtual bool DoCanRead( wxInputStream
& stream
);
145 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
150 class WXDLLEXPORT wxTIFFHandler
: public wxImageHandler
152 DECLARE_DYNAMIC_CLASS(wxTIFFHandler
)
156 inline wxTIFFHandler()
158 m_name
= "TIFF file";
160 m_type
= wxBITMAP_TYPE_TIF
;
161 m_mime
= "image/tiff";
165 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
166 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
167 virtual bool DoCanRead( wxInputStream
& stream
);
172 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
176 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
178 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
182 inline wxBMPHandler()
186 m_type
= wxBITMAP_TYPE_BMP
;
187 m_mime
= "image/bmp";
191 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
192 virtual bool DoCanRead( wxInputStream
& stream
);
196 //-----------------------------------------------------------------------------
198 //-----------------------------------------------------------------------------
202 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
204 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
208 inline wxGIFHandler()
212 m_type
= wxBITMAP_TYPE_GIF
;
213 m_mime
= "image/gif";
217 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
218 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
219 virtual bool DoCanRead( wxInputStream
& stream
);
224 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
229 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
231 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
235 inline wxPNMHandler()
239 m_type
= wxBITMAP_TYPE_PNM
;
240 m_mime
= "image/pnm";
244 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
245 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
246 virtual bool DoCanRead( wxInputStream
& stream
);
251 //-----------------------------------------------------------------------------
253 //-----------------------------------------------------------------------------
256 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
258 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
262 inline wxPCXHandler()
266 m_type
= wxBITMAP_TYPE_PCX
;
267 m_mime
= "image/pcx";
271 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
272 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
273 virtual bool DoCanRead( wxInputStream
& stream
);
274 #endif // wxUSE_STREAMS
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 class WXDLLEXPORT wxImage
: public wxObject
284 DECLARE_DYNAMIC_CLASS(wxImage
)
286 friend class WXDLLEXPORT wxImageHandler
;
291 wxImage( int width
, int height
);
292 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
293 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
294 wxImage( const wxString
& name
, const wxString
& mimetype
);
295 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
297 wxImage( const wxImage
& image
);
298 wxImage( const wxImage
* image
);
300 // these functions get implemented in /src/(platform)/bitmap.cpp
301 wxImage( const wxBitmap
&bitmap
);
302 operator wxBitmap() const { return ConvertToBitmap(); }
303 wxBitmap
ConvertToBitmap() const;
305 void Create( int width
, int height
);
308 // return the new image with size width*height
309 wxImage
GetSubImage( const wxRect
& ) const;
311 // return the new image with size width*height
312 wxImage
Scale( int width
, int height
) const;
314 // rescales the image in place
315 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
317 // these routines are slow but safe
318 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
319 unsigned char GetRed( int x
, int y
);
320 unsigned char GetGreen( int x
, int y
);
321 unsigned char GetBlue( int x
, int y
);
323 static bool CanRead( const wxString
& name
);
324 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
325 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
328 static bool CanRead( wxInputStream
& stream
);
329 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
330 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
333 virtual bool SaveFile( const wxString
& name
, int type
);
334 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
337 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
338 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
342 int GetWidth() const;
343 int GetHeight() const;
345 char unsigned *GetData() const;
346 void SetData( char unsigned *data
);
348 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
349 unsigned char GetMaskRed() const;
350 unsigned char GetMaskGreen() const;
351 unsigned char GetMaskBlue() const;
352 void SetMask( bool mask
= TRUE
);
353 bool HasMask() const;
355 wxImage
& operator = (const wxImage
& image
)
357 if ( (*this) != image
)
362 bool operator == (const wxImage
& image
)
363 { return m_refData
== image
.m_refData
; }
364 bool operator != (const wxImage
& image
)
365 { return m_refData
!= image
.m_refData
; }
367 static wxList
& GetHandlers() { return sm_handlers
; }
368 static void AddHandler( wxImageHandler
*handler
);
369 static void InsertHandler( wxImageHandler
*handler
);
370 static bool RemoveHandler( const wxString
& name
);
371 static wxImageHandler
*FindHandler( const wxString
& name
);
372 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
373 static wxImageHandler
*FindHandler( long imageType
);
374 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
376 static void CleanUpHandlers();
377 static void InitStandardHandlers();
381 static wxList sm_handlers
;
385 extern void WXDLLEXPORT
wxInitAllImageHandlers();