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 #if !defined(__VISAGECPP__)
76 // Why define these here and then again in the individual image format headers??
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
83 class WXDLLEXPORT wxPNGHandler
: public wxImageHandler
85 DECLARE_DYNAMIC_CLASS(wxPNGHandler
)
93 m_type
= wxBITMAP_TYPE_PNG
;
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
);
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
110 class WXDLLEXPORT wxJPEGHandler
: public wxImageHandler
112 DECLARE_DYNAMIC_CLASS(wxJPEGHandler
)
116 inline wxJPEGHandler()
118 m_name
= "JPEG file";
120 m_type
= wxBITMAP_TYPE_JPEG
;
121 m_mime
= "image/jpeg";
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
);
132 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
137 class WXDLLEXPORT wxTIFFHandler
: public wxImageHandler
139 DECLARE_DYNAMIC_CLASS(wxTIFFHandler
)
143 inline wxTIFFHandler()
145 m_name
= "TIFF file";
147 m_type
= wxBITMAP_TYPE_TIF
;
148 m_mime
= "image/tiff";
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
);
160 // ----------------------------------------------------------------------------
162 // ----------------------------------------------------------------------------
165 class WXDLLEXPORT wxPNMHandler
: public wxImageHandler
167 DECLARE_DYNAMIC_CLASS(wxPNMHandler
)
171 inline wxPNMHandler()
175 m_type
= wxBITMAP_TYPE_PNM
;
176 m_mime
= "image/pnm";
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
);
187 //-----------------------------------------------------------------------------
189 //-----------------------------------------------------------------------------
192 class WXDLLEXPORT wxPCXHandler
: public wxImageHandler
194 DECLARE_DYNAMIC_CLASS(wxPCXHandler
)
198 inline wxPCXHandler()
202 m_type
= wxBITMAP_TYPE_PCX
;
203 m_mime
= "image/pcx";
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
214 #endif //__VISAGECPP__
216 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
222 class WXDLLEXPORT wxHNode
230 class WXDLLEXPORT wxImage
: public wxObject
232 DECLARE_DYNAMIC_CLASS(wxImage
)
234 friend class WXDLLEXPORT wxImageHandler
;
239 wxImage( int width
, int height
);
240 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
241 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
242 wxImage( const wxString
& name
, const wxString
& mimetype
);
243 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
245 wxImage( const wxImage
& image
);
246 wxImage( const wxImage
* image
);
248 // these functions get implemented in /src/(platform)/bitmap.cpp
249 wxImage( const wxBitmap
&bitmap
);
250 operator wxBitmap() const { return ConvertToBitmap(); }
251 wxBitmap
ConvertToBitmap() const;
253 void Create( int width
, int height
);
256 // return the new image with size width*height
257 wxImage
GetSubImage( const wxRect
& ) const;
259 // return the new image with size width*height
260 wxImage
Scale( int width
, int height
) const;
262 // rescales the image in place
263 wxImage
& Rescale( int width
, int height
) { return *this = Scale(width
, height
); }
265 // these routines are slow but safe
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
);
271 static bool CanRead( const wxString
& name
);
272 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
273 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
276 static bool CanRead( wxInputStream
& stream
);
277 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
278 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
281 virtual bool SaveFile( const wxString
& name
, int type
);
282 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
285 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
286 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
290 int GetWidth() const;
291 int GetHeight() const;
293 char unsigned *GetData() const;
294 void SetData( char unsigned *data
);
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;
303 wxImage
& operator = (const wxImage
& image
)
305 if ( (*this) != image
)
310 bool operator == (const wxImage
& image
)
311 { return m_refData
== image
.m_refData
; }
312 bool operator != (const wxImage
& image
)
313 { return m_refData
!= image
.m_refData
; }
315 static wxList
& GetHandlers() { return sm_handlers
; }
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
);
322 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
324 static void CleanUpHandlers();
325 static void InitStandardHandlers();
328 unsigned long CountColours( unsigned long stopafter
= -1 );
329 unsigned long ComputeHistogram( wxHashTable
&h
);
334 static wxList sm_handlers
;
339 extern void WXDLLEXPORT
wxInitAllImageHandlers();
342 //-----------------------------------------------------------------------------
344 //-----------------------------------------------------------------------------
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"