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
;
38 class WXDLLEXPORT wxBMPHandler
;
40 class WXDLLEXPORT wxGIFHandler
;
43 class WXDLLEXPORT wxPNMHandler
;
46 class WXDLLEXPORT wxPCXHandler
;
48 class WXDLLEXPORT wxImage
;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 class WXDLLEXPORT wxImageHandler
: public wxObject
56 DECLARE_DYNAMIC_CLASS(wxImageHandler
)
59 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
62 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
63 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
65 virtual bool CanRead( wxInputStream
& stream
);
66 virtual bool CanRead( const wxString
& name
);
69 inline void SetName(const wxString
& name
) { m_name
= name
; }
70 inline void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
71 inline void SetType(long type
) { m_type
= type
; }
72 inline void SetMimeType(const wxString
& type
) { m_mime
= type
; }
73 inline wxString
GetName() const { return m_name
; }
74 inline wxString
GetExtension() const { return m_extension
; }
75 inline long GetType() const { return m_type
; }
76 inline wxString
GetMimeType() const { return m_mime
; }
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
91 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
93 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
101 m_type
= wxBITMAP_TYPE_PNG
;
102 m_mime
= "image/png";
106 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
107 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
108 virtual bool CanRead( wxInputStream
& stream
);
110 // hiding base class virtuals again!
111 inline bool CanRead( const wxString
& name
) { return(wxImageHandler::CanRead(name
)); };
116 //-----------------------------------------------------------------------------
118 //-----------------------------------------------------------------------------
121 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
123 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
127 inline wxJPEGHandler()
129 m_name
= "JPEG file";
131 m_type
= wxBITMAP_TYPE_JPEG
;
132 m_mime
= "image/jpeg";
136 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
137 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
138 virtual bool CanRead( wxInputStream
& stream
);
140 // hiding base class virtuals again!
141 inline bool CanRead( const wxString
& name
) { return(wxImageHandler::CanRead(name
)); };
146 //-----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
150 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
152 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
156 inline wxBMPHandler()
160 m_type
= wxBITMAP_TYPE_BMP
;
161 m_mime
= "image/bmp";
165 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
166 virtual bool CanRead( wxInputStream
& stream
);
168 // hiding base class virtuals again!
169 inline bool CanRead( const wxString
& name
) { return(wxImageHandler::CanRead(name
)); };
173 //-----------------------------------------------------------------------------
175 //-----------------------------------------------------------------------------
179 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
181 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
185 inline wxGIFHandler()
189 m_type
= wxBITMAP_TYPE_GIF
;
190 m_mime
= "image/gif";
194 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
195 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
196 virtual bool CanRead( wxInputStream
& stream
);
198 // hiding base class virtuals again!
199 inline bool CanRead( const wxString
& name
) { return(wxImageHandler::CanRead(name
)); };
204 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
209 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
211 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
215 inline wxPNMHandler()
219 m_type
= wxBITMAP_TYPE_PNM
;
220 m_mime
= "image/pnm";
224 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
225 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
226 virtual bool CanRead( wxInputStream
& stream
);
228 // hiding base class virtuals again!
229 inline bool CanRead( const wxString
& name
) { return(wxImageHandler::CanRead(name
)); };
234 //-----------------------------------------------------------------------------
236 //-----------------------------------------------------------------------------
239 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
241 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
245 inline wxPCXHandler()
249 m_type
= wxBITMAP_TYPE_PCX
;
250 m_mime
= "image/pcx";
254 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
);
255 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
256 virtual bool CanRead( wxInputStream
& stream
);
261 //-----------------------------------------------------------------------------
263 //-----------------------------------------------------------------------------
265 class WXDLLEXPORT wxImage
: public wxObject
267 DECLARE_DYNAMIC_CLASS(wxImage
)
269 friend class WXDLLEXPORT wxImageHandler
;
274 wxImage( int width
, int height
);
275 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
276 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
277 wxImage( const wxString
& name
, const wxString
& mimetype
);
278 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
280 wxImage( const wxImage
& image
);
281 wxImage( const wxImage
* image
);
283 // these functions get implemented in /src/(platform)/bitmap.cpp
284 wxImage( const wxBitmap
&bitmap
);
285 operator wxBitmap() const { return ConvertToBitmap(); }
286 wxBitmap
ConvertToBitmap() const;
288 void Create( int width
, int height
);
291 // return the new image with size width*height
292 wxImage
GetSubImage( const wxRect
& ) const;
294 // return the new image with size width*height
295 wxImage
Scale( int width
, int height
) const;
297 // rescales the image in place
298 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
300 // these routines are slow but safe
301 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
302 unsigned char GetRed( int x
, int y
);
303 unsigned char GetGreen( int x
, int y
);
304 unsigned char GetBlue( int x
, int y
);
306 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
307 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
310 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
311 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
314 virtual bool SaveFile( const wxString
& name
, int type
);
315 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
318 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
319 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
323 int GetWidth() const;
324 int GetHeight() const;
326 char unsigned *GetData() const;
327 void SetData( char unsigned *data
);
329 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
330 unsigned char GetMaskRed() const;
331 unsigned char GetMaskGreen() const;
332 unsigned char GetMaskBlue() const;
333 void SetMask( bool mask
= TRUE
);
334 bool HasMask() const;
336 wxImage
& operator = (const wxImage
& image
)
338 if ( (*this) != image
)
343 bool operator == (const wxImage
& image
)
344 { return m_refData
== image
.m_refData
; }
345 bool operator != (const wxImage
& image
)
346 { return m_refData
!= image
.m_refData
; }
348 static wxList
& GetHandlers() { return sm_handlers
; }
349 static void AddHandler( wxImageHandler
*handler
);
350 static void InsertHandler( wxImageHandler
*handler
);
351 static bool RemoveHandler( const wxString
& name
);
352 static wxImageHandler
*FindHandler( const wxString
& name
);
353 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
354 static wxImageHandler
*FindHandler( long imageType
);
355 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
357 static void CleanUpHandlers();
358 static void InitStandardHandlers();
362 static wxList sm_handlers
;
366 extern void WXDLLEXPORT
wxInitAllImageHandlers();