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 void Create( int width, int height );
122 wxImage Scale( int width, int height );
123 wxImage& Rescale(int width, int height);
125 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
126 unsigned char GetRed( int x, int y );
127 unsigned char GetGreen( int x, int y );
128 unsigned char GetBlue( int x, int y );
130 // find first colour that is not used in the image and has higher
131 // RGB values than <startR,startG,startB>
132 bool FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
133 byte startR = 0, byte startG = 0, byte startB = 0 ) const;
135 // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour
136 bool SetMaskFromImage(const wxImage & mask,
137 byte mr, byte mg, byte mb);
139 // void DoFloodFill (wxCoord x, wxCoord y,
140 // const wxBrush & fillBrush,
141 // const wxColour& testColour,
142 // int style = wxFLOOD_SURFACE,
143 // int LogicalFunction = wxCOPY /* currently unused */ ) ;
145 static bool CanRead( const wxString& name );
146 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
148 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
149 %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
151 bool SaveFile( const wxString& name, int type );
152 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
154 %name(CanReadStream) static bool CanRead( wxInputStream& stream );
155 %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
156 %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
162 wxImage GetSubImage(const wxRect& rect);
164 void Paste( const wxImage &image, int x, int y );
166 //unsigned char *GetData();
167 //void SetData( unsigned char *data );
170 PyObject* GetDataBuffer() {
171 unsigned char* data = self->GetData();
172 int len = self->GetWidth() * self->GetHeight() * 3;
173 return PyBuffer_FromReadWriteMemory(data, len);
176 PyObject* GetData() {
177 unsigned char* data = self->GetData();
178 int len = self->GetWidth() * self->GetHeight() * 3;
179 return PyString_FromStringAndSize((char*)data, len);
182 void SetDataBuffer(PyObject* data) {
183 unsigned char* buffer;
186 if (!PyArg_Parse(data, "w#", &buffer, &size))
189 if (size != self->GetWidth() * self->GetHeight() * 3) {
190 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
194 self->SetData(buffer);
197 void SetData(PyObject* data) {
198 unsigned char* dataPtr;
200 if (! PyString_Check(data)) {
201 PyErr_SetString(PyExc_TypeError, "Expected string object");
205 size_t len = self->GetWidth() * self->GetHeight() * 3;
206 dataPtr = (unsigned char*) malloc(len);
207 memcpy(dataPtr, PyString_AsString(data), len);
208 self->SetData(dataPtr);
209 // wxImage takes ownership of dataPtr...
213 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
214 unsigned char GetMaskRed();
215 unsigned char GetMaskGreen();
216 unsigned char GetMaskBlue();
217 void SetMask( bool mask = TRUE );
220 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
221 bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ;
222 wxImage Rotate90( bool clockwise = TRUE ) ;
223 wxImage Mirror( bool horizontally = TRUE ) ;
225 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
226 unsigned char r2, unsigned char g2, unsigned char b2 );
228 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
229 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
231 void SetOption(const wxString& name, const wxString& value);
232 %name(SetOptionInt)void SetOption(const wxString& name, int value);
233 wxString GetOption(const wxString& name) const;
234 int GetOptionInt(const wxString& name) const;
235 bool HasOption(const wxString& name) const;
237 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
238 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
240 static void AddHandler( wxImageHandler *handler );
241 static void InsertHandler( wxImageHandler *handler );
242 static bool RemoveHandler( const wxString& name );
246 wxBitmap ConvertToBitmap() {
247 wxBitmap bitmap(*self);
251 wxBitmap ConvertToMonoBitmap( unsigned char red,
253 unsigned char blue ) {
254 wxImage mono = self->ConvertToMono( red, green, blue );
255 wxBitmap bitmap( mono, 1 );
262 // Alternate constructors
263 %new wxImage* wxEmptyImage(int width=0, int height=0);
264 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
265 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
266 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
267 %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
268 %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 );
271 wxImage* wxEmptyImage(int width=0, int height=0) {
272 if (width == 0 && height == 0)
275 return new wxImage(width, height);
279 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
280 return new wxImage(name, mimetype, index);
284 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
285 return new wxImage(bitmap.ConvertToImage());
289 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
290 // Copy the source data so the wxImage can clean it up later
291 unsigned char* copy = (unsigned char*)malloc(width*height*3);
296 memcpy(copy, data, width*height*3);
297 return new wxImage(width, height, copy, FALSE);
301 wxImage* wxImageFromStream(wxInputStream& stream,
302 long type = wxBITMAP_TYPE_ANY, int index = -1) {
303 return new wxImage(stream, type, index);
307 wxImage* wxImageFromStreamMime(wxInputStream& stream,
308 const wxString& mimetype, int index = -1 ) {
309 return new wxImage(stream, mimetype, index);
315 void wxInitAllImageHandlers();
323 extern wxImage wxNullImage;
332 //---------------------------------------------------------------------------
333 // This one is here to avoid circular imports
335 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
338 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
339 return new wxBitmap(img, depth);
345 //---------------------------------------------------------------------------