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
;
32 class WXDLLEXPORT wxImage
;
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 class WXDLLEXPORT wxImageHandler
: public wxObject
40 DECLARE_CLASS(wxImageHandler
)
43 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
46 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
47 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
49 virtual int GetImageCount( wxInputStream
& stream
);
51 bool CanRead( wxInputStream
& stream
) { return DoCanRead(stream
); }
52 bool CanRead( const wxString
& name
);
53 #endif // wxUSE_STREAMS
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
; }
66 virtual bool DoCanRead( wxInputStream
& stream
) = 0;
67 #endif // wxUSE_STREAMS
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
80 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
82 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
90 m_type
= wxBITMAP_TYPE_PNG
;
95 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
96 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
97 virtual bool DoCanRead( wxInputStream
& stream
);
102 //-----------------------------------------------------------------------------
104 //-----------------------------------------------------------------------------
107 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
109 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
113 inline wxJPEGHandler()
115 m_name
= "JPEG file";
117 m_type
= wxBITMAP_TYPE_JPEG
;
118 m_mime
= "image/jpeg";
122 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
123 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
124 virtual bool DoCanRead( wxInputStream
& stream
);
129 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
134 class WXDLLEXPORT wxTIFFHandler
: public wxImageHandler
136 DECLARE_DYNAMIC_CLASS(wxTIFFHandler
)
140 inline wxTIFFHandler()
142 m_name
= "TIFF file";
144 m_type
= wxBITMAP_TYPE_TIF
;
145 m_mime
= "image/tiff";
149 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
150 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
151 virtual bool DoCanRead( wxInputStream
& stream
);
152 virtual int GetImageCount( wxInputStream
& stream
);
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
162 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
164 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
168 inline wxPNMHandler()
172 m_type
= wxBITMAP_TYPE_PNM
;
173 m_mime
= "image/pnm";
177 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
178 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
179 virtual bool DoCanRead( wxInputStream
& stream
);
184 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
189 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
191 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
195 inline wxPCXHandler()
199 m_type
= wxBITMAP_TYPE_PCX
;
200 m_mime
= "image/pcx";
204 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
205 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
206 virtual bool DoCanRead( wxInputStream
& stream
);
207 #endif // wxUSE_STREAMS
211 //-----------------------------------------------------------------------------
213 //-----------------------------------------------------------------------------
217 class WXDLLEXPORT wxHNode
225 class WXDLLEXPORT wxImage
: public wxObject
227 DECLARE_DYNAMIC_CLASS(wxImage
)
229 friend class WXDLLEXPORT wxImageHandler
;
234 wxImage( int width
, int height
);
235 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
236 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
237 wxImage( const wxString
& name
, const wxString
& mimetype
);
238 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
240 wxImage( const wxImage
& image
);
241 wxImage( const wxImage
* image
);
243 // these functions get implemented in /src/(platform)/bitmap.cpp
244 wxImage( const wxBitmap
&bitmap
);
245 operator wxBitmap() const { return ConvertToBitmap(); }
246 wxBitmap
ConvertToBitmap() const;
248 void Create( int width
, int height
);
251 // return the new image with size width*height
252 wxImage
GetSubImage( const wxRect
& ) const;
254 // return the new image with size width*height
255 wxImage
Scale( int width
, int height
) const;
257 // rescales the image in place
258 wxImage
& Rescale( int width
, int height
) { return *this = Scale(width
, height
); }
260 // these routines are slow but safe
261 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
262 unsigned char GetRed( int x
, int y
);
263 unsigned char GetGreen( int x
, int y
);
264 unsigned char GetBlue( int x
, int y
);
266 static bool CanRead( const wxString
& name
);
267 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
268 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
271 static bool CanRead( wxInputStream
& stream
);
272 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
273 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
276 virtual bool SaveFile( const wxString
& name
, int type
);
277 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
280 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
281 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
285 int GetWidth() const;
286 int GetHeight() const;
288 char unsigned *GetData() const;
289 void SetData( char unsigned *data
);
291 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
292 unsigned char GetMaskRed() const;
293 unsigned char GetMaskGreen() const;
294 unsigned char GetMaskBlue() const;
295 void SetMask( bool mask
= TRUE
);
296 bool HasMask() const;
298 wxImage
& operator = (const wxImage
& image
)
300 if ( (*this) != image
)
305 bool operator == (const wxImage
& image
)
306 { return m_refData
== image
.m_refData
; }
307 bool operator != (const wxImage
& image
)
308 { return m_refData
!= image
.m_refData
; }
310 static wxList
& GetHandlers() { return sm_handlers
; }
311 static void AddHandler( wxImageHandler
*handler
);
312 static void InsertHandler( wxImageHandler
*handler
);
313 static bool RemoveHandler( const wxString
& name
);
314 static wxImageHandler
*FindHandler( const wxString
& name
);
315 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
316 static wxImageHandler
*FindHandler( long imageType
);
317 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
319 static void CleanUpHandlers();
320 static void InitStandardHandlers();
323 unsigned long CountColours( unsigned long stopafter
= -1 );
324 unsigned long ComputeHistogram( wxHashTable
&h
);
329 static wxList sm_handlers
;
334 extern void WXDLLEXPORT
wxInitAllImageHandlers();
337 //-----------------------------------------------------------------------------
339 //-----------------------------------------------------------------------------
341 #include "wx/imagbmp.h"
342 #include "wx/imagpng.h"
343 #include "wx/imaggif.h"
344 #include "wx/imagpcx.h"
345 #include "wx/imagjpeg.h"
346 #include "wx/imagtiff.h"
347 #include "wx/imagpnm.h"