1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface file for wxImage, wxImageHandler, etc.
7 // Created: 28-Apr-1999
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
18 #include "pyistream.h"
22 //----------------------------------------------------------------------
25 %include my_typemaps.i
27 // Import some definitions of other classes, etc.
33 //---------------------------------------------------------------------------
35 class wxImageHandler : public wxObject {
37 // wxImageHandler(); Abstract Base Class
39 wxString GetExtension();
41 wxString GetMimeType();
43 //bool LoadFile(wxImage* image, wxInputStream& stream);
44 //bool SaveFile(wxImage* image, wxOutputStream& stream);
45 //virtual int GetImageCount( wxInputStream& stream );
46 //bool CanRead( wxInputStream& stream );
48 bool CanRead( const wxString& name );
50 void SetName(const wxString& name);
51 void SetExtension(const wxString& extension);
52 void SetType(long type);
53 void SetMimeType(const wxString& mimetype);
56 //---------------------------------------------------------------------------
58 class wxPNGHandler : public wxImageHandler {
64 class wxJPEGHandler : public wxImageHandler {
70 class wxBMPHandler : public wxImageHandler {
75 class wxICOHandler : public wxBMPHandler {
80 class wxCURHandler : public wxICOHandler {
85 class wxANIHandler : public wxCURHandler {
90 class wxGIFHandler : public wxImageHandler {
95 class wxPNMHandler : public wxImageHandler {
100 class wxPCXHandler : public wxImageHandler {
105 class wxTIFFHandler : public wxImageHandler {
112 //---------------------------------------------------------------------------
114 class wxImage : public wxObject {
116 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
119 wxBitmap ConvertToBitmap(); // deprecated
121 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
123 void Create( int width, int height );
126 wxImage Scale( int width, int height );
127 wxImage& Rescale(int width, int height);
129 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
130 unsigned char GetRed( int x, int y );
131 unsigned char GetGreen( int x, int y );
132 unsigned char GetBlue( int x, int y );
134 static bool CanRead( const wxString& name );
135 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
137 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
138 %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
140 bool SaveFile( const wxString& name, int type );
141 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
143 %name(CanReadStream) static bool CanRead( wxInputStream& stream );
144 %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
145 %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
151 wxImage GetSubImage(const wxRect& rect);
153 void Paste( const wxImage &image, int x, int y );
155 //unsigned char *GetData();
156 //void SetData( unsigned char *data );
159 PyObject* GetData() {
160 unsigned char* data = self->GetData();
161 int len = self->GetWidth() * self->GetHeight() * 3;
162 return PyString_FromStringAndSize((char*)data, len);
165 void SetData(PyObject* data) {
166 unsigned char* dataPtr;
168 if (! PyString_Check(data)) {
169 PyErr_SetString(PyExc_TypeError, "Expected string object");
173 size_t len = self->GetWidth() * self->GetHeight() * 3;
174 dataPtr = (unsigned char*) malloc(len);
175 memcpy(dataPtr, PyString_AsString(data), len);
176 self->SetData(dataPtr);
180 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
181 unsigned char GetMaskRed();
182 unsigned char GetMaskGreen();
183 unsigned char GetMaskBlue();
184 void SetMask( bool mask = TRUE );
187 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
188 bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ;
189 wxImage Rotate90( bool clockwise = TRUE ) ;
190 wxImage Mirror( bool horizontally = TRUE ) ;
192 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
193 unsigned char r2, unsigned char g2, unsigned char b2 );
195 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
196 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
198 void SetOption(const wxString& name, const wxString& value);
199 %name(SetOptionInt)void SetOption(const wxString& name, int value);
200 wxString GetOption(const wxString& name) const;
201 int GetOptionInt(const wxString& name) const;
202 bool HasOption(const wxString& name) const;
204 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
205 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
207 static void AddHandler( wxImageHandler *handler );
208 static void InsertHandler( wxImageHandler *handler );
209 static bool RemoveHandler( const wxString& name );
213 // Alternate constructors
214 %new wxImage* wxEmptyImage(int width=0, int height=0);
215 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
216 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
217 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
218 %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
219 %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 );
222 wxImage* wxEmptyImage(int width=0, int height=0) {
223 if (width == 0 && height == 0)
226 return new wxImage(width, height);
230 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
231 return new wxImage(name, mimetype, index);
235 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
236 return new wxImage(bitmap);
240 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
241 // Copy the source data so the wxImage can clean it up later
242 unsigned char* copy = (unsigned char*)malloc(width*height*3);
247 memcpy(copy, data, width*height*3);
248 return new wxImage(width, height, copy, FALSE);
252 wxImage* wxImageFromStream(wxInputStream& stream,
253 long type = wxBITMAP_TYPE_ANY, int index = -1) {
254 return new wxImage(stream, type, index);
258 wxImage* wxImageFromStreamMime(wxInputStream& stream,
259 const wxString& mimetype, int index = -1 ) {
260 return new wxImage(stream, mimetype, index);
266 void wxInitAllImageHandlers();
274 extern wxImage wxNullImage;
283 //---------------------------------------------------------------------------
284 // This one is here to avoid circular imports
286 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
289 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
290 return new wxBitmap(img, depth);
296 //---------------------------------------------------------------------------