]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/image.i
SWIGged updates for wxMSW
[wxWidgets.git] / wxPython / src / image.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: image.i
3 // Purpose: SWIG interface file for wxImage, wxImageHandler, etc.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 28-Apr-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13
14 %module image
15
16 %{
17 #include "helpers.h"
18 #include "pyistream.h"
19 #include <wx/image.h>
20 %}
21
22 //----------------------------------------------------------------------
23
24 %include typemaps.i
25 %include my_typemaps.i
26
27 // Import some definitions of other classes, etc.
28 %import _defs.i
29 %import misc.i
30 %import gdi.i
31 %import streams.i
32
33 //---------------------------------------------------------------------------
34
35 class wxImageHistogram /* : public wxImageHistogramBase */
36 {
37 public:
38 wxImageHistogram();
39
40 // get the key in the histogram for the given RGB values
41 static unsigned long MakeKey(unsigned char r,
42 unsigned char g,
43 unsigned char b);
44
45 // find first colour that is not used in the image and has higher
46 // RGB values than RGB(startR, startG, startB)
47 //
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;
56 };
57
58
59 //---------------------------------------------------------------------------
60
61 class wxImageHandler : public wxObject {
62 public:
63 // wxImageHandler(); Abstract Base Class
64 wxString GetName();
65 wxString GetExtension();
66 long GetType();
67 wxString GetMimeType();
68
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 );
73
74 bool CanRead( const wxString& name );
75
76 void SetName(const wxString& name);
77 void SetExtension(const wxString& extension);
78 void SetType(long type);
79 void SetMimeType(const wxString& mimetype);
80 };
81
82 //---------------------------------------------------------------------------
83
84 class wxPNGHandler : public wxImageHandler {
85 public:
86 wxPNGHandler();
87 };
88
89
90 class wxJPEGHandler : public wxImageHandler {
91 public:
92 wxJPEGHandler();
93 };
94
95
96 class wxBMPHandler : public wxImageHandler {
97 public:
98 wxBMPHandler();
99 };
100
101 class wxICOHandler : public wxBMPHandler {
102 public:
103 wxICOHandler();
104 };
105
106 class wxCURHandler : public wxICOHandler {
107 public:
108 wxCURHandler();
109 };
110
111 class wxANIHandler : public wxCURHandler {
112 public:
113 wxANIHandler();
114 };
115
116 class wxGIFHandler : public wxImageHandler {
117 public:
118 wxGIFHandler();
119 };
120
121 class wxPNMHandler : public wxImageHandler {
122 public:
123 wxPNMHandler();
124 };
125
126 class wxPCXHandler : public wxImageHandler {
127 public:
128 wxPCXHandler();
129 };
130
131 class wxTIFFHandler : public wxImageHandler {
132 public:
133 wxTIFFHandler();
134 };
135
136
137
138 //---------------------------------------------------------------------------
139
140 class wxImage : public wxObject {
141 public:
142 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
143 ~wxImage();
144
145 void Create( int width, int height );
146 void Destroy();
147
148 wxImage Scale( int width, int height );
149 wxImage ShrinkBy( int xFactor , int yFactor ) const ;
150 wxImage& Rescale(int width, int height);
151
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 );
156
157 void SetAlpha(int x, int y, unsigned char alpha);
158 unsigned char GetAlpha(int x, int y);
159 bool HasAlpha();
160
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;
165
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);
169
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 */ ) ;
175
176 static bool CanRead( const wxString& name );
177 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
178
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 );
181
182 bool SaveFile( const wxString& name, int type );
183 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
184
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 );
188
189 bool Ok();
190 int GetWidth();
191 int GetHeight();
192
193 wxImage GetSubImage(const wxRect& rect);
194 wxImage Copy();
195 void Paste( const wxImage &image, int x, int y );
196
197 //unsigned char *GetData();
198 //void SetData( unsigned char *data );
199
200 %addmethods {
201 PyObject* GetData() {
202 unsigned char* data = self->GetData();
203 int len = self->GetWidth() * self->GetHeight() * 3;
204 return PyString_FromStringAndSize((char*)data, len);
205 }
206 void SetData(PyObject* data) {
207 unsigned char* dataPtr;
208
209 if (! PyString_Check(data)) {
210 PyErr_SetString(PyExc_TypeError, "Expected string object");
211 return /* NULL */ ;
212 }
213
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...
219 }
220
221
222
223 PyObject* GetDataBuffer() {
224 unsigned char* data = self->GetData();
225 int len = self->GetWidth() * self->GetHeight() * 3;
226 return PyBuffer_FromReadWriteMemory(data, len);
227 }
228 void SetDataBuffer(PyObject* data) {
229 unsigned char* buffer;
230 int size;
231
232 if (!PyArg_Parse(data, "w#", &buffer, &size))
233 return;
234
235 if (size != self->GetWidth() * self->GetHeight() * 3) {
236 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
237 return;
238 }
239 self->SetData(buffer);
240 }
241
242
243
244 PyObject* GetAlphaData() {
245 unsigned char* data = self->GetAlpha();
246 if (! data) {
247 RETURN_NONE();
248 } else {
249 int len = self->GetWidth() * self->GetHeight();
250 return PyString_FromStringAndSize((char*)data, len);
251 }
252 }
253 void SetAlphaData(PyObject* data) {
254 unsigned char* dataPtr;
255
256 if (! PyString_Check(data)) {
257 PyErr_SetString(PyExc_TypeError, "Expected string object");
258 return /* NULL */ ;
259 }
260
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...
266 }
267
268
269
270 PyObject* GetAlphaBuffer() {
271 unsigned char* data = self->GetAlpha();
272 int len = self->GetWidth() * self->GetHeight();
273 return PyBuffer_FromReadWriteMemory(data, len);
274 }
275 void SetAlphaBuffer(PyObject* data) {
276 unsigned char* buffer;
277 int size;
278
279 if (!PyArg_Parse(data, "w#", &buffer, &size))
280 return;
281
282 if (size != self->GetWidth() * self->GetHeight()) {
283 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
284 return;
285 }
286 self->SetAlpha(buffer);
287 }
288 }
289
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 );
295 bool HasMask();
296
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 ) ;
301
302 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
303 unsigned char r2, unsigned char g2, unsigned char b2 );
304
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;
307
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;
313
314 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
315 unsigned long ComputeHistogram( wxImageHistogram& h );
316
317 static void AddHandler( wxImageHandler *handler );
318 static void InsertHandler( wxImageHandler *handler );
319 static bool RemoveHandler( const wxString& name );
320
321
322 %addmethods {
323 wxBitmap ConvertToBitmap() {
324 wxBitmap bitmap(*self);
325 return bitmap;
326 }
327
328 wxBitmap ConvertToMonoBitmap( unsigned char red,
329 unsigned char green,
330 unsigned char blue ) {
331 wxImage mono = self->ConvertToMono( red, green, blue );
332 wxBitmap bitmap( mono, 1 );
333 return bitmap;
334 }
335 }
336 };
337
338
339 // Alternate constructors
340 %new wxImage* wxEmptyImage(int width=0, int height=0);
341 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
342 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
343 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
344 %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
345 %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 );
346
347 %{
348 wxImage* wxEmptyImage(int width=0, int height=0) {
349 if (width == 0 && height == 0)
350 return new wxImage;
351 else
352 return new wxImage(width, height);
353 }
354
355
356 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
357 return new wxImage(name, mimetype, index);
358 }
359
360
361 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
362 return new wxImage(bitmap.ConvertToImage());
363 }
364
365
366 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
367 // Copy the source data so the wxImage can clean it up later
368 unsigned char* copy = (unsigned char*)malloc(width*height*3);
369 if (copy == NULL) {
370 PyErr_NoMemory();
371 return NULL;
372 }
373 memcpy(copy, data, width*height*3);
374 return new wxImage(width, height, copy, FALSE);
375 }
376
377
378 wxImage* wxImageFromStream(wxInputStream& stream,
379 long type = wxBITMAP_TYPE_ANY, int index = -1) {
380 return new wxImage(stream, type, index);
381 }
382
383
384 wxImage* wxImageFromStreamMime(wxInputStream& stream,
385 const wxString& mimetype, int index = -1 ) {
386 return new wxImage(stream, mimetype, index);
387 }
388 %}
389
390
391
392 void wxInitAllImageHandlers();
393
394
395 %readonly
396 %{
397 #if 0
398 %}
399
400 extern wxImage wxNullImage;
401
402 %readwrite
403 %{
404 #endif
405 %}
406
407
408
409 //---------------------------------------------------------------------------
410 // This one is here to avoid circular imports
411
412 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
413
414 %{
415 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
416 return new wxBitmap(img, depth);
417 }
418
419 %}
420
421
422 //---------------------------------------------------------------------------