]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_image.i
Correct a compile warning
[wxWidgets.git] / wxPython / src / _image.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _image.i
3 // Purpose: SWIG definitions for wxImage and such
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 25-Sept-2000
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include "wx/wxPython/pyistream.h"
20 %}
21
22 //---------------------------------------------------------------------------
23 %newgroup
24
25
26 class wxImageHandler : public wxObject {
27 public:
28 // wxImageHandler(); Abstract Base Class
29 wxString GetName();
30 wxString GetExtension();
31 long GetType();
32 wxString GetMimeType();
33
34 //bool LoadFile(wxImage* image, wxInputStream& stream);
35 //bool SaveFile(wxImage* image, wxOutputStream& stream);
36 //virtual int GetImageCount( wxInputStream& stream );
37 //bool CanRead( wxInputStream& stream );
38
39 bool CanRead( const wxString& name );
40
41 void SetName(const wxString& name);
42 void SetExtension(const wxString& extension);
43 void SetType(long type);
44 void SetMimeType(const wxString& mimetype);
45 };
46
47
48 //---------------------------------------------------------------------------
49
50 class wxImageHistogram /* : public wxImageHistogramBase */
51 {
52 public:
53 wxImageHistogram();
54
55 // get the key in the histogram for the given RGB values
56 static unsigned long MakeKey(unsigned char r,
57 unsigned char g,
58 unsigned char b);
59
60 // find first colour that is not used in the image and has higher
61 // RGB values than RGB(startR, startG, startB)
62 //
63 // returns true and puts this colour in r, g, b (each of which may be NULL)
64 // on success or returns false if there are no more free colours
65 bool FindFirstUnusedColour(unsigned char *OUTPUT,
66 unsigned char *OUTPUT,
67 unsigned char *OUTPUT,
68 unsigned char startR = 1,
69 unsigned char startG = 0,
70 unsigned char startB = 0 ) const;
71 };
72
73
74 //---------------------------------------------------------------------------
75
76
77 class wxImage : public wxObject {
78 public:
79 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
80 ~wxImage();
81
82 // Alternate constructors
83 %name(ImageFromMime) wxImage(const wxString& name, const wxString& mimetype, int index = -1);
84 %name(ImageFromStream) wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
85 %name(ImageFromStreamMime) wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 );
86 %extend {
87 %name(EmptyImage) wxImage(int width=0, int height=0, bool clear = TRUE) {
88 if (width > 0 && height > 0)
89 return new wxImage(width, height, clear);
90 else
91 return new wxImage;
92 }
93
94 %name(ImageFromBitmap) wxImage(const wxBitmap &bitmap) {
95 return new wxImage(bitmap.ConvertToImage());
96 }
97
98 %name(ImageFromData) wxImage(int width, int height, unsigned char* data) {
99 // Copy the source data so the wxImage can clean it up later
100 unsigned char* copy = (unsigned char*)malloc(width*height*3);
101 if (copy == NULL) {
102 PyErr_NoMemory();
103 return NULL;
104 }
105 memcpy(copy, data, width*height*3);
106 return new wxImage(width, height, copy, FALSE);
107 }
108 }
109
110 void Create( int width, int height );
111 void Destroy();
112
113 wxImage Scale( int width, int height );
114 wxImage ShrinkBy( int xFactor , int yFactor ) const ;
115 wxImage& Rescale(int width, int height);
116
117 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
118 unsigned char GetRed( int x, int y );
119 unsigned char GetGreen( int x, int y );
120 unsigned char GetBlue( int x, int y );
121
122 void SetAlpha(int x, int y, unsigned char alpha);
123 unsigned char GetAlpha(int x, int y);
124 bool HasAlpha();
125
126 // find first colour that is not used in the image and has higher
127 // RGB values than <startR,startG,startB>
128 bool FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
129 byte startR = 0, byte startG = 0, byte startB = 0 ) const;
130
131 // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour
132 bool SetMaskFromImage(const wxImage & mask,
133 byte mr, byte mg, byte mb);
134
135 // void DoFloodFill (wxCoord x, wxCoord y,
136 // const wxBrush & fillBrush,
137 // const wxColour& testColour,
138 // int style = wxFLOOD_SURFACE,
139 // int LogicalFunction = wxCOPY /* currently unused */ ) ;
140
141 static bool CanRead( const wxString& name );
142 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
143
144 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
145 %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
146
147 bool SaveFile( const wxString& name, int type );
148 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
149
150 %name(CanReadStream) static bool CanRead( wxInputStream& stream );
151 %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
152 %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
153
154 bool Ok();
155 int GetWidth();
156 int GetHeight();
157
158 wxImage GetSubImage(const wxRect& rect);
159 wxImage Copy();
160 void Paste( const wxImage &image, int x, int y );
161
162 //unsigned char *GetData();
163 //void SetData( unsigned char *data );
164
165 %extend {
166 PyObject* GetData() {
167 unsigned char* data = self->GetData();
168 int len = self->GetWidth() * self->GetHeight() * 3;
169 PyObject* rv;
170 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
171 return rv;
172 }
173 void SetData(PyObject* data) {
174 unsigned char* dataPtr;
175
176 if (! PyString_Check(data)) {
177 PyErr_SetString(PyExc_TypeError, "Expected string object");
178 return /* NULL */ ;
179 }
180
181 size_t len = self->GetWidth() * self->GetHeight() * 3;
182 dataPtr = (unsigned char*) malloc(len);
183 wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) );
184 self->SetData(dataPtr);
185 // wxImage takes ownership of dataPtr...
186 }
187
188
189
190 PyObject* GetDataBuffer() {
191 unsigned char* data = self->GetData();
192 int len = self->GetWidth() * self->GetHeight() * 3;
193 PyObject* rv;
194 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
195 return rv;
196 }
197 void SetDataBuffer(PyObject* data) {
198 unsigned char* buffer;
199 int size;
200
201 wxPyBeginBlockThreads();
202 if (!PyArg_Parse(data, "t#", &buffer, &size))
203 goto done;
204
205 if (size != self->GetWidth() * self->GetHeight() * 3) {
206 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
207 goto done;
208 }
209 self->SetData(buffer);
210 done:
211 wxPyEndBlockThreads();
212 }
213
214
215
216 PyObject* GetAlphaData() {
217 unsigned char* data = self->GetAlpha();
218 if (! data) {
219 RETURN_NONE();
220 } else {
221 int len = self->GetWidth() * self->GetHeight();
222 PyObject* rv;
223 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
224 return rv;
225 }
226 }
227 void SetAlphaData(PyObject* data) {
228 unsigned char* dataPtr;
229
230 if (! PyString_Check(data)) {
231 PyErr_SetString(PyExc_TypeError, "Expected string object");
232 return /* NULL */ ;
233 }
234
235 size_t len = self->GetWidth() * self->GetHeight();
236 dataPtr = (unsigned char*) malloc(len);
237 wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) );
238 self->SetAlpha(dataPtr);
239 // wxImage takes ownership of dataPtr...
240 }
241
242
243
244 PyObject* GetAlphaBuffer() {
245 unsigned char* data = self->GetAlpha();
246 int len = self->GetWidth() * self->GetHeight();
247 PyObject* rv;
248 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
249 return rv;
250 }
251 void SetAlphaBuffer(PyObject* data) {
252 unsigned char* buffer;
253 int size;
254
255 wxPyBeginBlockThreads();
256 if (!PyArg_Parse(data, "t#", &buffer, &size))
257 goto done;
258
259 if (size != self->GetWidth() * self->GetHeight()) {
260 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
261 goto done;
262 }
263 self->SetAlpha(buffer);
264 done:
265 wxPyEndBlockThreads();
266 }
267 }
268
269 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
270 unsigned char GetMaskRed();
271 unsigned char GetMaskGreen();
272 unsigned char GetMaskBlue();
273 void SetMask( bool mask = TRUE );
274 bool HasMask();
275
276 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
277 bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ;
278 wxImage Rotate90( bool clockwise = TRUE ) ;
279 wxImage Mirror( bool horizontally = TRUE ) ;
280
281 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
282 unsigned char r2, unsigned char g2, unsigned char b2 );
283
284 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
285 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
286
287 void SetOption(const wxString& name, const wxString& value);
288 %name(SetOptionInt)void SetOption(const wxString& name, int value);
289 wxString GetOption(const wxString& name) const;
290 int GetOptionInt(const wxString& name) const;
291 bool HasOption(const wxString& name) const;
292
293 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
294 unsigned long ComputeHistogram( wxImageHistogram& h );
295
296 static void AddHandler( wxImageHandler *handler );
297 static void InsertHandler( wxImageHandler *handler );
298 static bool RemoveHandler( const wxString& name );
299 static wxString GetImageExtWildcard();
300
301
302 %extend {
303 wxBitmap ConvertToBitmap() {
304 wxBitmap bitmap(*self);
305 return bitmap;
306 }
307
308 wxBitmap ConvertToMonoBitmap( unsigned char red,
309 unsigned char green,
310 unsigned char blue ) {
311 wxImage mono = self->ConvertToMono( red, green, blue );
312 wxBitmap bitmap( mono, 1 );
313 return bitmap;
314 }
315 }
316
317 %pythoncode { def __nonzero__(self): return self.Ok() }
318 };
319
320
321
322 void wxInitAllImageHandlers();
323
324
325 // See also wxPy_ReinitStockObjects in helpers.cpp
326 %immutable;
327 const wxImage wxNullImage;
328 %mutable;
329
330 //---------------------------------------------------------------------------
331
332
333 MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
334 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
335 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
336 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
337 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
338
339 enum
340 {
341 wxIMAGE_RESOLUTION_INCHES = 1,
342 wxIMAGE_RESOLUTION_CM = 2
343 };
344
345
346 enum
347 {
348 wxBMP_24BPP = 24, // default, do not need to set
349 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
350 wxBMP_8BPP = 8, // 8bpp, quantized colors
351 wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
352 wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
353 wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
354 wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
355 wxBMP_4BPP = 4, // 4bpp, quantized colors
356 wxBMP_1BPP = 1, // 1bpp, quantized "colors"
357 wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
358 };
359
360
361 class wxBMPHandler : public wxImageHandler {
362 public:
363 wxBMPHandler();
364 };
365
366 class wxICOHandler : public wxBMPHandler {
367 public:
368 wxICOHandler();
369 };
370
371 class wxCURHandler : public wxICOHandler {
372 public:
373 wxCURHandler();
374 };
375
376 class wxANIHandler : public wxCURHandler {
377 public:
378 wxANIHandler();
379 };
380
381
382 //---------------------------------------------------------------------------
383
384 class wxPNGHandler : public wxImageHandler {
385 public:
386 wxPNGHandler();
387 };
388
389
390 class wxGIFHandler : public wxImageHandler {
391 public:
392 wxGIFHandler();
393 };
394
395
396 class wxPCXHandler : public wxImageHandler {
397 public:
398 wxPCXHandler();
399 };
400
401
402 class wxJPEGHandler : public wxImageHandler {
403 public:
404 wxJPEGHandler();
405 };
406
407
408 class wxPNMHandler : public wxImageHandler {
409 public:
410 wxPNMHandler();
411 };
412
413 class wxXPMHandler : public wxImageHandler {
414 public:
415 wxXPMHandler();
416 };
417
418 class wxTIFFHandler : public wxImageHandler {
419 public:
420 wxTIFFHandler();
421 };
422
423
424 #if wxUSE_IFF
425 class wxIFFHandler : public wxImageHandler {
426 public:
427 wxIFFHandler();
428 };
429 #endif
430
431 //---------------------------------------------------------------------------