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( int width
, int height
, unsigned char* data
, bool static_data
= FALSE
);
93 wxImage( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
94 wxImage( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
95 wxImage( const wxString
& name
, const wxString
& mimetype
);
96 wxImage( wxInputStream
& stream
, const wxString
& mimetype
);
98 wxImage( const wxImage
& image
);
99 wxImage( const wxImage
* image
);
101 wxImage( const wxBitmap
&bitmap
);
102 operator wxBitmap() const { return ConvertToBitmap(); }
103 wxBitmap
ConvertToBitmap() const;
105 wxBitmap
ConvertToMonoBitmap( unsigned char red
, unsigned char green
, unsigned char blue
);
108 void Create( int width
, int height
);
109 void Create( int width
, int height
, unsigned char* data
, bool static_data
= FALSE
);
112 // creates an identical copy of the image (the = operator
113 // just raises the ref count)
114 wxImage
Copy() const;
116 // return the new image with size width*height
117 wxImage
GetSubImage( const wxRect
& ) const;
119 // pastes image into this instance and takes care of
120 // the mask colour and out of bounds problems
121 void Paste( const wxImage
&image
, int x
, int y
);
123 // return the new image with size width*height
124 wxImage
Scale( int width
, int height
) const;
126 // rescales the image in place
127 wxImage
& Rescale( int width
, int height
) { return *this = Scale(width
, height
); }
129 // Rotates the image about the given point, 'angle' radians.
130 // Returns the rotated image, leaving this image intact.
131 wxImage
Rotate(double angle
, const wxPoint
& centre_of_rotation
,
132 bool interpolating
= TRUE
, wxPoint
* offset_after_rotation
= (wxPoint
*) NULL
) const;
134 wxImage
Rotate90( bool clockwise
= TRUE
) const;
135 wxImage
Mirror( bool horizontally
= TRUE
) const;
137 // replace one colour with another
138 void Replace( unsigned char r1
, unsigned char g1
, unsigned char b1
,
139 unsigned char r2
, unsigned char g2
, unsigned char b2
);
141 // these routines are slow but safe
142 void SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
);
143 unsigned char GetRed( int x
, int y
) const;
144 unsigned char GetGreen( int x
, int y
) const;
145 unsigned char GetBlue( int x
, int y
) const;
147 static bool CanRead( const wxString
& name
);
148 virtual bool LoadFile( const wxString
& name
, long type
= wxBITMAP_TYPE_ANY
);
149 virtual bool LoadFile( const wxString
& name
, const wxString
& mimetype
);
152 static bool CanRead( wxInputStream
& stream
);
153 virtual bool LoadFile( wxInputStream
& stream
, long type
= wxBITMAP_TYPE_ANY
);
154 virtual bool LoadFile( wxInputStream
& stream
, const wxString
& mimetype
);
157 virtual bool SaveFile( const wxString
& name
, int type
);
158 virtual bool SaveFile( const wxString
& name
, const wxString
& mimetype
);
161 virtual bool SaveFile( wxOutputStream
& stream
, int type
);
162 virtual bool SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
);
166 int GetWidth() const;
167 int GetHeight() const;
169 char unsigned *GetData() const;
170 void SetData( char unsigned *data
);
171 void SetData( char unsigned *data
, int new_width
, int new_height
);
173 void SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
);
174 unsigned char GetMaskRed() const;
175 unsigned char GetMaskGreen() const;
176 unsigned char GetMaskBlue() const;
177 void SetMask( bool mask
= TRUE
);
178 bool HasMask() const;
180 unsigned long CountColours( unsigned long stopafter
= (unsigned long) -1 );
181 unsigned long ComputeHistogram( wxHashTable
&h
);
183 wxImage
& operator = (const wxImage
& image
)
185 if ( (*this) != image
)
190 bool operator == (const wxImage
& image
)
191 { return m_refData
== image
.m_refData
; }
192 bool operator != (const wxImage
& image
)
193 { return m_refData
!= image
.m_refData
; }
195 static wxList
& GetHandlers() { return sm_handlers
; }
196 static void AddHandler( wxImageHandler
*handler
);
197 static void InsertHandler( wxImageHandler
*handler
);
198 static bool RemoveHandler( const wxString
& name
);
199 static wxImageHandler
*FindHandler( const wxString
& name
);
200 static wxImageHandler
*FindHandler( const wxString
& extension
, long imageType
);
201 static wxImageHandler
*FindHandler( long imageType
);
202 static wxImageHandler
*FindHandlerMime( const wxString
& mimetype
);
204 static void CleanUpHandlers();
205 static void InitStandardHandlers();
208 static wxList sm_handlers
;
211 friend class WXDLLEXPORT wxImageHandler
;
213 DECLARE_DYNAMIC_CLASS(wxImage
)
217 extern void WXDLLEXPORT
wxInitAllImageHandlers();
220 //-----------------------------------------------------------------------------
222 //-----------------------------------------------------------------------------
224 #include "wx/imagbmp.h"
225 #include "wx/imagpng.h"
226 #include "wx/imaggif.h"
227 #include "wx/imagpcx.h"
228 #include "wx/imagjpeg.h"
229 #include "wx/imagtiff.h"
230 #include "wx/imagpnm.h"