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
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
82 class WXDLLEXPORT wxHNode
90 class WXDLLEXPORT wxImage
: public wxObject
92 DECLARE_DYNAMIC_CLASS(wxImage
)
94 friend class WXDLLEXPORT wxImageHandler
;
99 wxImage( int width
, int height
);
100 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
101 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
102 wxImage( const wxString
& name
, const wxString
& mimetype
);
103 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
105 wxImage( const wxImage
& image
);
106 wxImage( const wxImage
* image
);
108 // these functions get implemented in /src/(platform)/bitmap.cpp
109 wxImage( const wxBitmap
&bitmap
);
110 operator wxBitmap() const { return ConvertToBitmap(); }
111 wxBitmap
ConvertToBitmap() const;
113 void Create( int width
, int height
);
116 // return the new image with size width*height
117 wxImage
GetSubImage( const wxRect
& ) const;
119 // return the new image with size width*height
120 wxImage
Scale( int width
, int height
) const;
122 // rescales the image in place
123 wxImage
& Rescale( int width
, int height
) { return *this = Scale(width
, height
); }
125 // these routines are slow but safe
126 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
127 unsigned char GetRed( int x
, int y
);
128 unsigned char GetGreen( int x
, int y
);
129 unsigned char GetBlue( int x
, int y
);
131 static bool CanRead( const wxString
& name
);
132 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
133 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
136 static bool CanRead( wxInputStream
& stream
);
137 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
138 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
141 virtual bool SaveFile( const wxString
& name
, int type
);
142 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
145 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
146 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
150 int GetWidth() const;
151 int GetHeight() const;
153 char unsigned *GetData() const;
154 void SetData( char unsigned *data
);
156 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
157 unsigned char GetMaskRed() const;
158 unsigned char GetMaskGreen() const;
159 unsigned char GetMaskBlue() const;
160 void SetMask( bool mask
= TRUE
);
161 bool HasMask() const;
163 wxImage
& operator = (const wxImage
& image
)
165 if ( (*this) != image
)
170 bool operator == (const wxImage
& image
)
171 { return m_refData
== image
.m_refData
; }
172 bool operator != (const wxImage
& image
)
173 { return m_refData
!= image
.m_refData
; }
175 static wxList
& GetHandlers() { return sm_handlers
; }
176 static void AddHandler( wxImageHandler
*handler
);
177 static void InsertHandler( wxImageHandler
*handler
);
178 static bool RemoveHandler( const wxString
& name
);
179 static wxImageHandler
*FindHandler( const wxString
& name
);
180 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
181 static wxImageHandler
*FindHandler( long imageType
);
182 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
184 static void CleanUpHandlers();
185 static void InitStandardHandlers();
188 unsigned long CountColours( unsigned long stopafter
= (unsigned long) -1 );
189 unsigned long ComputeHistogram( wxHashTable
&h
);
194 static wxList sm_handlers
;
199 extern void WXDLLEXPORT
wxInitAllImageHandlers();
202 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
206 #include "wx/imagbmp.h"
207 #include "wx/imagpng.h"
208 #include "wx/imaggif.h"
209 #include "wx/imagpcx.h"
210 #include "wx/imagjpeg.h"
211 #include "wx/imagtiff.h"
212 #include "wx/imagpnm.h"