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 wxImageHistogram /* : public wxImageHistogramBase */
40 // get the key in the histogram for the given RGB values
41 static unsigned long MakeKey(unsigned char r,
45 // find first colour that is not used in the image and has higher
46 // RGB values than RGB(startR, startG, startB)
48 // returns true and puts this colour in r, g, b (each of which may be NULL)
49 // on success or returns false if there are no more free colours
50 bool FindFirstUnusedColour(unsigned char *OUTPUT,
51 unsigned char *OUTPUT,
52 unsigned char *OUTPUT,
53 unsigned char startR = 1,
54 unsigned char startG = 0,
55 unsigned char startB = 0 ) const;
59 //---------------------------------------------------------------------------
61 class wxImageHandler : public wxObject {
63 // wxImageHandler(); Abstract Base Class
65 wxString GetExtension();
67 wxString GetMimeType();
69 //bool LoadFile(wxImage* image, wxInputStream& stream);
70 //bool SaveFile(wxImage* image, wxOutputStream& stream);
71 //virtual int GetImageCount( wxInputStream& stream );
72 //bool CanRead( wxInputStream& stream );
74 bool CanRead( const wxString& name );
76 void SetName(const wxString& name);
77 void SetExtension(const wxString& extension);
78 void SetType(long type);
79 void SetMimeType(const wxString& mimetype);
82 //---------------------------------------------------------------------------
84 class wxPNGHandler : public wxImageHandler {
90 class wxJPEGHandler : public wxImageHandler {
96 class wxBMPHandler : public wxImageHandler {
101 class wxICOHandler : public wxBMPHandler {
106 class wxCURHandler : public wxICOHandler {
111 class wxANIHandler : public wxCURHandler {
116 class wxGIFHandler : public wxImageHandler {
121 class wxPNMHandler : public wxImageHandler {
126 class wxPCXHandler : public wxImageHandler {
131 class wxTIFFHandler : public wxImageHandler {
138 //---------------------------------------------------------------------------
140 class wxImage : public wxObject {
142 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
145 void Create( int width, int height );
148 wxImage Scale( int width, int height );
149 wxImage ShrinkBy( int xFactor , int yFactor ) const ;
150 wxImage& Rescale(int width, int height);
152 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
153 unsigned char GetRed( int x, int y );
154 unsigned char GetGreen( int x, int y );
155 unsigned char GetBlue( int x, int y );
157 void SetAlpha(int x, int y, unsigned char alpha);
158 unsigned char GetAlpha(int x, int y);
161 // find first colour that is not used in the image and has higher
162 // RGB values than <startR,startG,startB>
163 bool FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
164 byte startR = 0, byte startG = 0, byte startB = 0 ) const;
166 // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour
167 bool SetMaskFromImage(const wxImage & mask,
168 byte mr, byte mg, byte mb);
170 // void DoFloodFill (wxCoord x, wxCoord y,
171 // const wxBrush & fillBrush,
172 // const wxColour& testColour,
173 // int style = wxFLOOD_SURFACE,
174 // int LogicalFunction = wxCOPY /* currently unused */ ) ;
176 static bool CanRead( const wxString& name );
177 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
179 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
180 %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
182 bool SaveFile( const wxString& name, int type );
183 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
185 %name(CanReadStream) static bool CanRead( wxInputStream& stream );
186 %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
187 %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
193 wxImage GetSubImage(const wxRect& rect);
195 void Paste( const wxImage &image, int x, int y );
197 //unsigned char *GetData();
198 //void SetData( unsigned char *data );
201 PyObject* GetData() {
202 unsigned char* data = self->GetData();
203 int len = self->GetWidth() * self->GetHeight() * 3;
204 return PyString_FromStringAndSize((char*)data, len);
206 void SetData(PyObject* data) {
207 unsigned char* dataPtr;
209 if (! PyString_Check(data)) {
210 PyErr_SetString(PyExc_TypeError, "Expected string object");
214 size_t len = self->GetWidth() * self->GetHeight() * 3;
215 dataPtr = (unsigned char*) malloc(len);
216 memcpy(dataPtr, PyString_AsString(data), len);
217 self->SetData(dataPtr);
218 // wxImage takes ownership of dataPtr...
223 PyObject* GetDataBuffer() {
224 unsigned char* data = self->GetData();
225 int len = self->GetWidth() * self->GetHeight() * 3;
226 return PyBuffer_FromReadWriteMemory(data, len);
228 void SetDataBuffer(PyObject* data) {
229 unsigned char* buffer;
232 if (!PyArg_Parse(data, "w#", &buffer, &size))
235 if (size != self->GetWidth() * self->GetHeight() * 3) {
236 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
239 self->SetData(buffer);
244 PyObject* GetAlphaData() {
245 unsigned char* data = self->GetAlpha();
249 int len = self->GetWidth() * self->GetHeight();
250 return PyString_FromStringAndSize((char*)data, len);
253 void SetAlphaData(PyObject* data) {
254 unsigned char* dataPtr;
256 if (! PyString_Check(data)) {
257 PyErr_SetString(PyExc_TypeError, "Expected string object");
261 size_t len = self->GetWidth() * self->GetHeight();
262 dataPtr = (unsigned char*) malloc(len);
263 memcpy(dataPtr, PyString_AsString(data), len);
264 self->SetAlpha(dataPtr);
265 // wxImage takes ownership of dataPtr...
270 PyObject* GetAlphaBuffer() {
271 unsigned char* data = self->GetAlpha();
272 int len = self->GetWidth() * self->GetHeight();
273 return PyBuffer_FromReadWriteMemory(data, len);
275 void SetAlphaBuffer(PyObject* data) {
276 unsigned char* buffer;
279 if (!PyArg_Parse(data, "w#", &buffer, &size))
282 if (size != self->GetWidth() * self->GetHeight()) {
283 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
286 self->SetAlpha(buffer);
290 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
291 unsigned char GetMaskRed();
292 unsigned char GetMaskGreen();
293 unsigned char GetMaskBlue();
294 void SetMask( bool mask = TRUE );
297 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
298 bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ;
299 wxImage Rotate90( bool clockwise = TRUE ) ;
300 wxImage Mirror( bool horizontally = TRUE ) ;
302 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
303 unsigned char r2, unsigned char g2, unsigned char b2 );
305 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
306 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
308 void SetOption(const wxString& name, const wxString& value);
309 %name(SetOptionInt)void SetOption(const wxString& name, int value);
310 wxString GetOption(const wxString& name) const;
311 int GetOptionInt(const wxString& name) const;
312 bool HasOption(const wxString& name) const;
314 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
315 unsigned long ComputeHistogram( wxImageHistogram& h );
317 static void AddHandler( wxImageHandler *handler );
318 static void InsertHandler( wxImageHandler *handler );
319 static bool RemoveHandler( const wxString& name );
320 static wxString GetImageExtWildcard();
324 wxBitmap ConvertToBitmap() {
325 wxBitmap bitmap(*self);
329 wxBitmap ConvertToMonoBitmap( unsigned char red,
331 unsigned char blue ) {
332 wxImage mono = self->ConvertToMono( red, green, blue );
333 wxBitmap bitmap( mono, 1 );
338 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
342 // Alternate constructors
343 %new wxImage* wxEmptyImage(int width=0, int height=0, bool clear = TRUE);
344 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
345 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
346 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
347 %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
348 %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 );
351 wxImage* wxEmptyImage(int width=0, int height=0, bool clear = TRUE) {
352 if (width > 0 && height > 0)
353 return new wxImage(width, height, clear);
359 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
360 return new wxImage(name, mimetype, index);
364 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
365 return new wxImage(bitmap.ConvertToImage());
369 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
370 // Copy the source data so the wxImage can clean it up later
371 unsigned char* copy = (unsigned char*)malloc(width*height*3);
376 memcpy(copy, data, width*height*3);
377 return new wxImage(width, height, copy, FALSE);
381 wxImage* wxImageFromStream(wxInputStream& stream,
382 long type = wxBITMAP_TYPE_ANY, int index = -1) {
383 return new wxImage(stream, type, index);
387 wxImage* wxImageFromStreamMime(wxInputStream& stream,
388 const wxString& mimetype, int index = -1 ) {
389 return new wxImage(stream, mimetype, index);
395 void wxInitAllImageHandlers();
403 // See also wxPy_ReinitStockObjects in helpers.cpp
404 extern wxImage wxNullImage;
413 //---------------------------------------------------------------------------
414 // This one is here to avoid circular imports
416 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
419 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
420 return new wxBitmap(img, depth);
426 //---------------------------------------------------------------------------