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
, int index
=0 );
66 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
68 virtual int GetImageCount( wxInputStream
& stream
);
70 bool CanRead( wxInputStream
& stream
) { return DoCanRead(stream
); }
71 bool CanRead( const wxString
& name
);
74 void SetName(const wxString
& name
) { m_name
= name
; }
75 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
76 void SetType(long type
) { m_type
= type
; }
77 void SetMimeType(const wxString
& type
) { m_mime
= type
; }
78 wxString
GetName() const { return m_name
; }
79 wxString
GetExtension() const { return m_extension
; }
80 long GetType() const { return m_type
; }
81 wxString
GetMimeType() const { return m_mime
; }
84 virtual bool DoCanRead( wxInputStream
& stream
) = 0;
93 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
98 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
100 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
104 inline wxPNGHandler()
108 m_type
= wxBITMAP_TYPE_PNG
;
109 m_mime
= "image/png";
113 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
114 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
115 virtual bool DoCanRead( wxInputStream
& stream
);
120 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
125 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
127 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
131 inline wxJPEGHandler()
133 m_name
= "JPEG file";
135 m_type
= wxBITMAP_TYPE_JPEG
;
136 m_mime
= "image/jpeg";
140 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
141 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
142 virtual bool DoCanRead( wxInputStream
& stream
);
147 //-----------------------------------------------------------------------------
149 //-----------------------------------------------------------------------------
152 class WXDLLEXPORT wxTIFFHandler
: public wxImageHandler
154 DECLARE_DYNAMIC_CLASS(wxTIFFHandler
)
158 inline wxTIFFHandler()
160 m_name
= "TIFF file";
162 m_type
= wxBITMAP_TYPE_TIF
;
163 m_mime
= "image/tiff";
167 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
168 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
169 virtual bool DoCanRead( wxInputStream
& stream
);
170 virtual int GetImageCount( wxInputStream
& stream
);
175 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
179 class WXDLLEXPORT wxBMPHandler
: public wxImageHandler
181 DECLARE_DYNAMIC_CLASS(wxBMPHandler
)
185 inline wxBMPHandler()
189 m_type
= wxBITMAP_TYPE_BMP
;
190 m_mime
= "image/bmp";
194 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
195 virtual bool DoCanRead( wxInputStream
& stream
);
199 //-----------------------------------------------------------------------------
201 //-----------------------------------------------------------------------------
205 class WXDLLEXPORT wxGIFHandler
: public wxImageHandler
207 DECLARE_DYNAMIC_CLASS(wxGIFHandler
)
211 inline wxGIFHandler()
215 m_type
= wxBITMAP_TYPE_GIF
;
216 m_mime
= "image/gif";
220 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
221 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
222 virtual bool DoCanRead( wxInputStream
& stream
);
227 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
232 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
234 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
238 inline wxPNMHandler()
242 m_type
= wxBITMAP_TYPE_PNM
;
243 m_mime
= "image/pnm";
247 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
248 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
249 virtual bool DoCanRead( wxInputStream
& stream
);
254 //-----------------------------------------------------------------------------
256 //-----------------------------------------------------------------------------
259 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
261 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
265 inline wxPCXHandler()
269 m_type
= wxBITMAP_TYPE_PCX
;
270 m_mime
= "image/pcx";
274 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
275 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
276 virtual bool DoCanRead( wxInputStream
& stream
);
277 #endif // wxUSE_STREAMS
281 //-----------------------------------------------------------------------------
283 //-----------------------------------------------------------------------------
287 class WXDLLEXPORT wxHNode
295 class WXDLLEXPORT wxImage
: public wxObject
297 DECLARE_DYNAMIC_CLASS(wxImage
)
299 friend class WXDLLEXPORT wxImageHandler
;
304 wxImage( int width
, int height
);
305 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
306 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
307 wxImage( const wxString
& name
, const wxString
& mimetype
);
308 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
310 wxImage( const wxImage
& image
);
311 wxImage( const wxImage
* image
);
313 // these functions get implemented in /src/(platform)/bitmap.cpp
314 wxImage( const wxBitmap
&bitmap
);
315 operator wxBitmap() const { return ConvertToBitmap(); }
316 wxBitmap
ConvertToBitmap() const;
318 void Create( int width
, int height
);
321 // return the new image with size width*height
322 wxImage
GetSubImage( const wxRect
& ) const;
324 // return the new image with size width*height
325 wxImage
Scale( int width
, int height
) const;
327 // rescales the image in place
328 void Rescale( int width
, int height
) { *this = Scale(width
, height
); }
330 // these routines are slow but safe
331 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
332 unsigned char GetRed( int x
, int y
);
333 unsigned char GetGreen( int x
, int y
);
334 unsigned char GetBlue( int x
, int y
);
336 static bool CanRead( const wxString
& name
);
337 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
338 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
341 static bool CanRead( wxInputStream
& stream
);
342 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
343 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
346 virtual bool SaveFile( const wxString
& name
, int type
);
347 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
350 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
351 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
355 int GetWidth() const;
356 int GetHeight() const;
358 char unsigned *GetData() const;
359 void SetData( char unsigned *data
);
361 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
362 unsigned char GetMaskRed() const;
363 unsigned char GetMaskGreen() const;
364 unsigned char GetMaskBlue() const;
365 void SetMask( bool mask
= TRUE
);
366 bool HasMask() const;
368 wxImage
& operator = (const wxImage
& image
)
370 if ( (*this) != image
)
375 bool operator == (const wxImage
& image
)
376 { return m_refData
== image
.m_refData
; }
377 bool operator != (const wxImage
& image
)
378 { return m_refData
!= image
.m_refData
; }
380 static wxList
& GetHandlers() { return sm_handlers
; }
381 static void AddHandler( wxImageHandler
*handler
);
382 static void InsertHandler( wxImageHandler
*handler
);
383 static bool RemoveHandler( const wxString
& name
);
384 static wxImageHandler
*FindHandler( const wxString
& name
);
385 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
386 static wxImageHandler
*FindHandler( long imageType
);
387 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
389 static void CleanUpHandlers();
390 static void InitStandardHandlers();
393 unsigned long CountColours( unsigned long stopat
= -1 );
394 unsigned long ComputeHistogram( wxHashTable
&h
);
399 static wxList sm_handlers
;
403 extern void WXDLLEXPORT
wxInitAllImageHandlers();