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"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 class WXDLLEXPORT wxImageHandler
;
34 class WXDLLEXPORT wxImage
;
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 class WXDLLEXPORT wxImageHandler
: public wxObject
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 DECLARE_CLASS(wxImageHandler
)
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 class WXDLLEXPORT wxHNode
89 class WXDLLEXPORT wxImage
: public wxObject
93 wxImage( int width
, int height
);
94 wxImage( int width
, int height
, unsigned char* data
, bool static_data
= FALSE
);
95 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
96 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
97 wxImage( const wxString
& name
, const wxString
& mimetype
);
98 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
100 wxImage( const wxImage
& image
);
101 wxImage( const wxImage
* image
);
104 // convertion to/from wxBitmap (deprecated, use wxBitmap's methods instead):
105 wxImage( const wxBitmap
&bitmap
);
106 wxBitmap
ConvertToBitmap() const;
108 wxBitmap
ConvertToMonoBitmap( unsigned char red
, unsigned char green
, unsigned char blue
) const;
112 void Create( int width
, int height
);
113 void Create( int width
, int height
, unsigned char* data
, bool static_data
= FALSE
);
116 // creates an identical copy of the image (the = operator
117 // just raises the ref count)
118 wxImage
Copy() const;
120 // return the new image with size width*height
121 wxImage
GetSubImage( const wxRect
& ) const;
123 // pastes image into this instance and takes care of
124 // the mask colour and out of bounds problems
125 void Paste( const wxImage
&image
, int x
, int y
);
127 // return the new image with size width*height
128 wxImage
Scale( int width
, int height
) const;
130 // rescales the image in place
131 wxImage
& Rescale( int width
, int height
) { return *this = Scale(width
, height
); }
133 // Rotates the image about the given point, 'angle' radians.
134 // Returns the rotated image, leaving this image intact.
135 wxImage
Rotate(double angle
, const wxPoint
& centre_of_rotation
,
136 bool interpolating
= TRUE
, wxPoint
* offset_after_rotation
= (wxPoint
*) NULL
) const;
138 wxImage
Rotate90( bool clockwise
= TRUE
) const;
139 wxImage
Mirror( bool horizontally
= TRUE
) const;
141 // replace one colour with another
142 void Replace( unsigned char r1
, unsigned char g1
, unsigned char b1
,
143 unsigned char r2
, unsigned char g2
, unsigned char b2
);
145 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
146 wxImage
ConvertToMono( unsigned char r
, unsigned char g
, unsigned char b
) const;
148 // these routines are slow but safe
149 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
150 unsigned char GetRed( int x
, int y
) const;
151 unsigned char GetGreen( int x
, int y
) const;
152 unsigned char GetBlue( int x
, int y
) const;
154 // used to manipulate the icons while extracting from .ico files
155 bool GetUnusedColour( unsigned char *r
, unsigned char *g
, unsigned char *b
);
156 bool ApplyMask( const wxImage
& mask
);
158 static bool CanRead( const wxString
& name
);
159 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
160 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
163 static bool CanRead( wxInputStream
& stream
);
164 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
165 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
168 virtual bool SaveFile( const wxString
& name
, int type
);
169 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
172 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
173 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
177 int GetWidth() const;
178 int GetHeight() const;
180 char unsigned *GetData() const;
181 void SetData( char unsigned *data
);
182 void SetData( char unsigned *data
, int new_width
, int new_height
);
185 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
186 unsigned char GetMaskRed() const;
187 unsigned char GetMaskGreen() const;
188 unsigned char GetMaskBlue() const;
189 void SetMask( bool mask
= TRUE
);
190 bool HasMask() const;
194 bool HasPalette() const;
195 const wxPalette
& GetPalette() const;
196 void SetPalette(const wxPalette
& palette
);
197 #endif // wxUSE_PALETTE
199 // Option functions (arbitrary name/value mapping)
200 void SetOption(const wxString
& name
, const wxString
& value
);
201 void SetOption(const wxString
& name
, int value
);
202 wxString
GetOption(const wxString
& name
) const;
203 int GetOptionInt(const wxString
& name
) const;
204 bool HasOption(const wxString
& name
) const;
206 unsigned long CountColours( unsigned long stopafter
= (unsigned long) -1 );
207 unsigned long ComputeHistogram( wxHashTable
&h
);
209 wxImage
& operator = (const wxImage
& image
)
211 if ( (*this) != image
)
216 bool operator == (const wxImage
& image
)
217 { return m_refData
== image
.m_refData
; }
218 bool operator != (const wxImage
& image
)
219 { return m_refData
!= image
.m_refData
; }
221 static wxList
& GetHandlers() { return sm_handlers
; }
222 static void AddHandler( wxImageHandler
*handler
);
223 static void InsertHandler( wxImageHandler
*handler
);
224 static bool RemoveHandler( const wxString
& name
);
225 static wxImageHandler
*FindHandler( const wxString
& name
);
226 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
227 static wxImageHandler
*FindHandler( long imageType
);
228 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
230 static void CleanUpHandlers();
231 static void InitStandardHandlers();
234 static wxList sm_handlers
;
237 friend class WXDLLEXPORT wxImageHandler
;
239 DECLARE_DYNAMIC_CLASS(wxImage
)
243 extern void WXDLLEXPORT
wxInitAllImageHandlers();
245 WXDLLEXPORT_DATA(extern wxImage
) wxNullImage
;
247 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
251 #include "wx/imagbmp.h"
252 #include "wx/imagpng.h"
253 #include "wx/imaggif.h"
254 #include "wx/imagpcx.h"
255 #include "wx/imagjpeg.h"
256 #include "wx/imagtiff.h"
257 #include "wx/imagpnm.h"
258 #include "wx/imagxpm.h"
260 #endif // wxUSE_IMAGE