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 );
323 wxBitmap ConvertToBitmap() {
324 wxBitmap bitmap(*self);
328 wxBitmap ConvertToMonoBitmap( unsigned char red,
330 unsigned char blue ) {
331 wxImage mono = self->ConvertToMono( red, green, blue );
332 wxBitmap bitmap( mono, 1 );
337 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
341 // Alternate constructors
342 %new wxImage* wxEmptyImage(int width=0, int height=0);
343 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
344 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
345 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
346 %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
347 %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 );
350 wxImage* wxEmptyImage(int width=0, int height=0) {
351 if (width == 0 && height == 0)
354 return new wxImage(width, height);
358 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
359 return new wxImage(name, mimetype, index);
363 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
364 return new wxImage(bitmap.ConvertToImage());
368 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
369 // Copy the source data so the wxImage can clean it up later
370 unsigned char* copy = (unsigned char*)malloc(width*height*3);
375 memcpy(copy, data, width*height*3);
376 return new wxImage(width, height, copy, FALSE);
380 wxImage* wxImageFromStream(wxInputStream& stream,
381 long type = wxBITMAP_TYPE_ANY, int index = -1) {
382 return new wxImage(stream, type, index);
386 wxImage* wxImageFromStreamMime(wxInputStream& stream,
387 const wxString& mimetype, int index = -1 ) {
388 return new wxImage(stream, mimetype, index);
394 void wxInitAllImageHandlers();
402 // See also wxPy_ReinitStockObjects in helpers.cpp
403 extern wxImage wxNullImage;
412 //---------------------------------------------------------------------------
413 // This one is here to avoid circular imports
415 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
418 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
419 return new wxBitmap(img, depth);
425 //---------------------------------------------------------------------------