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
41 wxImageHandler() { m_name
= ""; m_extension
= ""; m_type
= 0; }
44 virtual bool LoadFile( wxImage
*image
, wxInputStream
& stream
, bool verbose
=TRUE
, int index
=0 );
45 virtual bool SaveFile( wxImage
*image
, wxOutputStream
& stream
, bool verbose
=TRUE
);
47 virtual int GetImageCount( wxInputStream
& stream
);
49 bool CanRead( wxInputStream
& stream
) { return DoCanRead(stream
); }
50 bool CanRead( const wxString
& name
);
51 #endif // wxUSE_STREAMS
53 void SetName(const wxString
& name
) { m_name
= name
; }
54 void SetExtension(const wxString
& ext
) { m_extension
= ext
; }
55 void SetType(long type
) { m_type
= type
; }
56 void SetMimeType(const wxString
& type
) { m_mime
= type
; }
57 wxString
GetName() const { return m_name
; }
58 wxString
GetExtension() const { return m_extension
; }
59 long GetType() const { return m_type
; }
60 wxString
GetMimeType() const { return m_mime
; }
64 virtual bool DoCanRead( wxInputStream
& stream
) = 0;
65 #endif // wxUSE_STREAMS
73 DECLARE_CLASS(wxImageHandler
)
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 class WXDLLEXPORT wxHNode
87 class WXDLLEXPORT wxImage
: public wxObject
91 wxImage( int width
, int height
);
92 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
93 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
94 wxImage( const wxString
& name
, const wxString
& mimetype
);
95 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
97 wxImage( const wxImage
& image
);
98 wxImage( const wxImage
* image
);
100 // these functions get implemented in /src/(platform)/bitmap.cpp
101 wxImage( const wxBitmap
&bitmap
);
102 operator wxBitmap() const { return ConvertToBitmap(); }
103 wxBitmap
ConvertToBitmap() const;
105 void Create( int width
, int height
);
108 // return the new image with size width*height
109 wxImage
GetSubImage( const wxRect
& ) const;
111 // return the new image with size width*height
112 wxImage
Scale( int width
, int height
) const;
114 // rescales the image in place
115 wxImage
& Rescale( int width
, int height
) { return *this = Scale(width
, height
); }
117 // replace one colour with another
118 void Replace( unsigned char r1
, unsigned char g1
, unsigned char b1
,
119 unsigned char r2
, unsigned char g2
, unsigned char b2
);
121 // these routines are slow but safe
122 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
123 unsigned char GetRed( int x
, int y
);
124 unsigned char GetGreen( int x
, int y
);
125 unsigned char GetBlue( int x
, int y
);
127 static bool CanRead( const wxString
& name
);
128 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
129 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
132 static bool CanRead( wxInputStream
& stream
);
133 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
134 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
137 virtual bool SaveFile( const wxString
& name
, int type
);
138 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
141 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
142 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
146 int GetWidth() const;
147 int GetHeight() const;
149 char unsigned *GetData() const;
150 void SetData( char unsigned *data
);
152 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
153 unsigned char GetMaskRed() const;
154 unsigned char GetMaskGreen() const;
155 unsigned char GetMaskBlue() const;
156 void SetMask( bool mask
= TRUE
);
157 bool HasMask() const;
159 unsigned long CountColours( unsigned long stopafter
= (unsigned long) -1 );
160 unsigned long ComputeHistogram( wxHashTable
&h
);
162 wxImage
& operator = (const wxImage
& image
)
164 if ( (*this) != image
)
169 bool operator == (const wxImage
& image
)
170 { return m_refData
== image
.m_refData
; }
171 bool operator != (const wxImage
& image
)
172 { return m_refData
!= image
.m_refData
; }
174 static wxList
& GetHandlers() { return sm_handlers
; }
175 static void AddHandler( wxImageHandler
*handler
);
176 static void InsertHandler( wxImageHandler
*handler
);
177 static bool RemoveHandler( const wxString
& name
);
178 static wxImageHandler
*FindHandler( const wxString
& name
);
179 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
180 static wxImageHandler
*FindHandler( long imageType
);
181 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
183 static void CleanUpHandlers();
184 static void InitStandardHandlers();
187 static wxList sm_handlers
;
190 friend class WXDLLEXPORT wxImageHandler
;
192 DECLARE_DYNAMIC_CLASS(wxImage
)
196 extern void WXDLLEXPORT
wxInitAllImageHandlers();
199 //-----------------------------------------------------------------------------
201 //-----------------------------------------------------------------------------
203 #include "wx/imagbmp.h"
204 #include "wx/imagpng.h"
205 #include "wx/imaggif.h"
206 #include "wx/imagpcx.h"
207 #include "wx/imagjpeg.h"
208 #include "wx/imagtiff.h"
209 #include "wx/imagpnm.h"