]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/image.i
Lots of changes for wxPython to start using many of the new featues in
[wxWidgets.git] / wxPython / src / image.i
CommitLineData
cf694132
RD
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"
4152e8b9 18#include "pyistream.h"
cf694132
RD
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
f74ff5ef 31%import streams.i
cf694132 32
9cbf6f6e
RD
33//---------------------------------------------------------------------------
34
35class wxImageHistogram /* : public wxImageHistogramBase */
36{
37public:
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
cf694132
RD
59//---------------------------------------------------------------------------
60
9416aa89 61class wxImageHandler : public wxObject {
cf694132 62public:
1dec68aa 63 // wxImageHandler(); Abstract Base Class
cf694132
RD
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);
b5a5d647
RD
71 //virtual int GetImageCount( wxInputStream& stream );
72 //bool CanRead( wxInputStream& stream );
73
74 bool CanRead( const wxString& name );
cf694132
RD
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
84class wxPNGHandler : public wxImageHandler {
85public:
86 wxPNGHandler();
87};
88
89
90class wxJPEGHandler : public wxImageHandler {
91public:
92 wxJPEGHandler();
93};
94
95
96class wxBMPHandler : public wxImageHandler {
97public:
98 wxBMPHandler();
99};
100
b5a5d647
RD
101class wxICOHandler : public wxBMPHandler {
102public:
103 wxICOHandler();
104};
cf694132 105
68320e40
RD
106class wxCURHandler : public wxICOHandler {
107public:
108 wxCURHandler();
109};
110
111class wxANIHandler : public wxCURHandler {
112public:
113 wxANIHandler();
114};
115
cf694132
RD
116class wxGIFHandler : public wxImageHandler {
117public:
118 wxGIFHandler();
119};
120
06c0fba4
RD
121class wxPNMHandler : public wxImageHandler {
122public:
123 wxPNMHandler();
124};
cf694132 125
06c0fba4
RD
126class wxPCXHandler : public wxImageHandler {
127public:
128 wxPCXHandler();
129};
cf694132 130
9b3d3bc4
RD
131class wxTIFFHandler : public wxImageHandler {
132public:
133 wxTIFFHandler();
134};
135
136
68320e40 137
cf694132
RD
138//---------------------------------------------------------------------------
139
9416aa89 140class wxImage : public wxObject {
cf694132 141public:
b5a5d647 142 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
cf694132
RD
143 ~wxImage();
144
cf694132
RD
145 void Create( int width, int height );
146 void Destroy();
6c0168c9 147
cf694132 148 wxImage Scale( int width, int height );
9cbf6f6e 149 wxImage ShrinkBy( int xFactor , int yFactor ) const ;
f6bcfd97 150 wxImage& Rescale(int width, int height);
cf694132
RD
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
9cbf6f6e
RD
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
68bc8549
RD
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
db0ff83e
RD
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 */ ) ;
68bc8549 175
96bfd053 176 static bool CanRead( const wxString& name );
b5a5d647
RD
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 );
cf694132
RD
181
182 bool SaveFile( const wxString& name, int type );
183 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
184
f74ff5ef
RD
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
cf694132
RD
189 bool Ok();
190 int GetWidth();
191 int GetHeight();
192
9d8bd15f 193 wxImage GetSubImage(const wxRect& rect);
f6bcfd97
BP
194 wxImage Copy();
195 void Paste( const wxImage &image, int x, int y );
9d8bd15f 196
1dc2f865
RD
197 //unsigned char *GetData();
198 //void SetData( unsigned char *data );
199
200 %addmethods {
9cbf6f6e 201 PyObject* GetData() {
d55d6b3f
RD
202 unsigned char* data = self->GetData();
203 int len = self->GetWidth() * self->GetHeight() * 3;
9cbf6f6e 204 return PyString_FromStringAndSize((char*)data, len);
d55d6b3f 205 }
9cbf6f6e
RD
206 void SetData(PyObject* data) {
207 unsigned char* dataPtr;
d55d6b3f 208
9cbf6f6e
RD
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() {
1dc2f865
RD
224 unsigned char* data = self->GetData();
225 int len = self->GetWidth() * self->GetHeight() * 3;
9cbf6f6e 226 return PyBuffer_FromReadWriteMemory(data, len);
1dc2f865 227 }
1e4a197e
RD
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 }
1e4a197e
RD
239 self->SetData(buffer);
240 }
241
9cbf6f6e
RD
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) {
1dc2f865
RD
254 unsigned char* dataPtr;
255
256 if (! PyString_Check(data)) {
257 PyErr_SetString(PyExc_TypeError, "Expected string object");
258 return /* NULL */ ;
259 }
9d8bd15f 260
9cbf6f6e 261 size_t len = self->GetWidth() * self->GetHeight();
185d7c3e 262 dataPtr = (unsigned char*) malloc(len);
9d8bd15f 263 memcpy(dataPtr, PyString_AsString(data), len);
9cbf6f6e 264 self->SetAlpha(dataPtr);
3b5ccda1 265 // wxImage takes ownership of dataPtr...
1dc2f865 266 }
9cbf6f6e
RD
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 }
1dc2f865 288 }
cf694132
RD
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
f6bcfd97
BP
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
6c0168c9
RD
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
f6bcfd97 314 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
9cbf6f6e 315 unsigned long ComputeHistogram( wxImageHistogram& h );
f6bcfd97 316
96bfd053
RD
317 static void AddHandler( wxImageHandler *handler );
318 static void InsertHandler( wxImageHandler *handler );
319 static bool RemoveHandler( const wxString& name );
3ef86e32 320 static wxString GetImageExtWildcard();
b96c7a38
RD
321
322
323 %addmethods {
324 wxBitmap ConvertToBitmap() {
325 wxBitmap bitmap(*self);
326 return bitmap;
327 }
328
329 wxBitmap ConvertToMonoBitmap( unsigned char red,
330 unsigned char green,
331 unsigned char blue ) {
332 wxImage mono = self->ConvertToMono( red, green, blue );
333 wxBitmap bitmap( mono, 1 );
334 return bitmap;
335 }
336 }
1fded56b
RD
337
338 %pragma(python) addtoclass = "def __nonzero__(self): return self.Ok()"
cf694132
RD
339};
340
926bb76c 341
cf694132 342// Alternate constructors
3ef86e32 343%new wxImage* wxEmptyImage(int width=0, int height=0, bool clear = TRUE);
b5a5d647 344%new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
cf694132 345%new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
b5a5d647 346%new wxImage* wxImageFromData(int width, int height, unsigned char* data);
f74ff5ef
RD
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 );
349
cf694132 350%{
3ef86e32
RD
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);
0a651eb8 354 else
3ef86e32 355 return new wxImage;
cf694132
RD
356 }
357
f74ff5ef 358
b5a5d647
RD
359 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
360 return new wxImage(name, mimetype, index);
cf694132
RD
361 }
362
f74ff5ef 363
cf694132 364 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
b96c7a38 365 return new wxImage(bitmap.ConvertToImage());
cf694132 366 }
b5a5d647 367
f74ff5ef 368
b5a5d647
RD
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);
372 if (copy == NULL) {
373 PyErr_NoMemory();
374 return NULL;
375 }
376 memcpy(copy, data, width*height*3);
377 return new wxImage(width, height, copy, FALSE);
378 }
f74ff5ef
RD
379
380
381 wxImage* wxImageFromStream(wxInputStream& stream,
382 long type = wxBITMAP_TYPE_ANY, int index = -1) {
383 return new wxImage(stream, type, index);
384 }
385
386
387 wxImage* wxImageFromStreamMime(wxInputStream& stream,
388 const wxString& mimetype, int index = -1 ) {
389 return new wxImage(stream, mimetype, index);
390 }
cf694132
RD
391%}
392
f74ff5ef
RD
393
394
06c0fba4
RD
395void wxInitAllImageHandlers();
396
0a651eb8
RD
397
398%readonly
399%{
400#if 0
401%}
402
dd116e73 403// See also wxPy_ReinitStockObjects in helpers.cpp
0a651eb8
RD
404extern wxImage wxNullImage;
405
406%readwrite
407%{
408#endif
409%}
410
411
412
cf694132 413//---------------------------------------------------------------------------
926bb76c
RD
414// This one is here to avoid circular imports
415
416%new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
417
418%{
419 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
420 return new wxBitmap(img, depth);
421 }
422
423%}
424
425
cf694132 426//---------------------------------------------------------------------------