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 /////////////////////////////////////////////////////////////////////////////
21 //----------------------------------------------------------------------
24 %include my_typemaps.i
26 // Import some definitions of other classes, etc.
31 //---------------------------------------------------------------------------
33 class wxImageHandler : public wxObject {
35 // wxImageHandler(); Abstract Base Class
37 wxString GetExtension();
39 wxString GetMimeType();
41 //bool LoadFile(wxImage* image, wxInputStream& stream);
42 //bool SaveFile(wxImage* image, wxOutputStream& stream);
43 //virtual int GetImageCount( wxInputStream& stream );
44 //bool CanRead( wxInputStream& stream );
46 bool CanRead( const wxString& name );
48 void SetName(const wxString& name);
49 void SetExtension(const wxString& extension);
50 void SetType(long type);
51 void SetMimeType(const wxString& mimetype);
54 //---------------------------------------------------------------------------
56 class wxPNGHandler : public wxImageHandler {
62 class wxJPEGHandler : public wxImageHandler {
68 class wxBMPHandler : public wxImageHandler {
73 class wxICOHandler : public wxBMPHandler {
78 class wxGIFHandler : public wxImageHandler {
83 class wxPNMHandler : public wxImageHandler {
88 class wxPCXHandler : public wxImageHandler {
93 class wxTIFFHandler : public wxImageHandler {
99 //---------------------------------------------------------------------------
101 class wxImage : public wxObject {
103 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
106 wxBitmap ConvertToBitmap(); // deprecated
108 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
110 void Create( int width, int height );
113 wxImage Scale( int width, int height );
114 wxImage& Rescale(int width, int height);
116 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
117 unsigned char GetRed( int x, int y );
118 unsigned char GetGreen( int x, int y );
119 unsigned char GetBlue( int x, int y );
121 static bool CanRead( const wxString& name );
122 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
124 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
125 %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
127 bool SaveFile( const wxString& name, int type );
128 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
134 wxImage GetSubImage(const wxRect& rect);
136 void Paste( const wxImage &image, int x, int y );
138 //unsigned char *GetData();
139 //void SetData( unsigned char *data );
142 PyObject* GetData() {
143 unsigned char* data = self->GetData();
144 int len = self->GetWidth() * self->GetHeight() * 3;
145 return PyString_FromStringAndSize((char*)data, len);
148 void SetData(PyObject* data) {
149 unsigned char* dataPtr;
151 if (! PyString_Check(data)) {
152 PyErr_SetString(PyExc_TypeError, "Expected string object");
156 size_t len = self->GetWidth() * self->GetHeight() * 3;
157 dataPtr = (unsigned char*) malloc(len);
158 memcpy(dataPtr, PyString_AsString(data), len);
159 self->SetData(dataPtr);
163 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
164 unsigned char GetMaskRed();
165 unsigned char GetMaskGreen();
166 unsigned char GetMaskBlue();
167 void SetMask( bool mask = TRUE );
170 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
171 bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ;
172 wxImage Rotate90( bool clockwise = TRUE ) ;
173 wxImage Mirror( bool horizontally = TRUE ) ;
175 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
176 unsigned char r2, unsigned char g2, unsigned char b2 );
178 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
179 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
181 void SetOption(const wxString& name, const wxString& value);
182 %name(SetOptionInt)void SetOption(const wxString& name, int value);
183 wxString GetOption(const wxString& name) const;
184 int GetOptionInt(const wxString& name) const;
185 bool HasOption(const wxString& name) const;
187 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
188 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
190 static void AddHandler( wxImageHandler *handler );
191 static void InsertHandler( wxImageHandler *handler );
192 static bool RemoveHandler( const wxString& name );
196 // Alternate constructors
197 %new wxImage* wxEmptyImage(int width=0, int height=0);
198 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
199 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
200 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
202 wxImage* wxEmptyImage(int width=0, int height=0) {
203 if (width == 0 && height == 0)
206 return new wxImage(width, height);
209 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
210 return new wxImage(name, mimetype, index);
213 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
214 return new wxImage(bitmap);
217 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
218 // Copy the source data so the wxImage can clean it up later
219 unsigned char* copy = (unsigned char*)malloc(width*height*3);
224 memcpy(copy, data, width*height*3);
225 return new wxImage(width, height, copy, FALSE);
229 void wxInitAllImageHandlers();
237 extern wxImage wxNullImage;
246 //---------------------------------------------------------------------------
247 // This one is here to avoid circular imports
249 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
252 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
253 return new wxBitmap(img, depth);
259 //---------------------------------------------------------------------------