]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/_image.i
Squash exception on exit bug
[wxWidgets.git] / wxPython / src / _image.i
... / ...
CommitLineData
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
24enum {
25 wxIMAGE_ALPHA_TRANSPARENT,
26 wxIMAGE_ALPHA_THRESHOLD,
27 wxIMAGE_ALPHA_OPAQUE
28};
29
30
31//---------------------------------------------------------------------------
32%newgroup
33
34
35class wxImageHandler : public wxObject {
36public:
37 // wxImageHandler(); Abstract Base Class
38 wxString GetName();
39 wxString GetExtension();
40 long GetType();
41 wxString GetMimeType();
42
43 //bool LoadFile(wxImage* image, wxInputStream& stream);
44 //bool SaveFile(wxImage* image, wxOutputStream& stream);
45 //virtual int GetImageCount( wxInputStream& stream );
46 //bool CanRead( wxInputStream& stream );
47
48 bool CanRead( const wxString& name );
49
50 void SetName(const wxString& name);
51 void SetExtension(const wxString& extension);
52 void SetType(long type);
53 void SetMimeType(const wxString& mimetype);
54};
55
56
57//---------------------------------------------------------------------------
58
59class wxImageHistogram /* : public wxImageHistogramBase */
60{
61public:
62 wxImageHistogram();
63
64 DocStr(MakeKey, "Get the key in the histogram for the given RGB values", "");
65 static unsigned long MakeKey(unsigned char r,
66 unsigned char g,
67 unsigned char b);
68
69 DocDeclAStr(
70 bool, FindFirstUnusedColour(unsigned char *OUTPUT,
71 unsigned char *OUTPUT,
72 unsigned char *OUTPUT,
73 unsigned char startR = 1,
74 unsigned char startG = 0,
75 unsigned char startB = 0 ) const,
76 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
77 "Find first colour that is not used in the image and has higher RGB
78values than startR, startG, startB. Returns a tuple consisting of a
79success flag and rgb values.", "");
80
81 %extend {
82 DocStr(GetCount,
83 "Returns the pixel count for the given key. Use `MakeKey` to create a
84key value from a RGB tripple.", "");
85 unsigned long GetCount(unsigned long key) {
86 wxImageHistogramEntry e = (*self)[key];
87 return e.value;
88 }
89
90 DocStr(GetCountRGB,
91 "Returns the pixel count for the given RGB values.", "");
92 unsigned long GetCountRGB(unsigned char r,
93 unsigned char g,
94 unsigned char b) {
95 unsigned long key = wxImageHistogram::MakeKey(r, g, b);
96 wxImageHistogramEntry e = (*self)[key];
97 return e.value;
98 }
99
100 DocStr(GetCountColour,
101 "Returns the pixel count for the given `wx.Colour` value.", "");
102 unsigned long GetCountColour(const wxColour& colour) {
103 unsigned long key = wxImageHistogram::MakeKey(colour.Red(),
104 colour.Green(),
105 colour.Blue());
106 wxImageHistogramEntry e = (*self)[key];
107 return e.value;
108 }
109 }
110
111};
112
113
114//---------------------------------------------------------------------------
115
116%{
117 typedef unsigned char* buffer;
118%}
119
120%typemap(in) (buffer data, int DATASIZE)
121 { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; }
122
123%typemap(in) (buffer alpha, int ALPHASIZE)
124 { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; }
125
126//---------------------------------------------------------------------------
127
128
129class wxImage : public wxObject {
130public:
131 %typemap(out) wxImage*; // turn off this typemap
132
133 DocCtorStr(
134 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
135 "", "");
136
137 ~wxImage();
138
139 // Alternate constructors
140 DocCtorStrName(
141 wxImage(const wxString& name, const wxString& mimetype, int index = -1),
142 "", "",
143 ImageFromMime);
144
145 DocCtorStrName(
146 wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1),
147 "", "",
148 ImageFromStream);
149
150 DocCtorStrName(
151 wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ),
152 "", "",
153 ImageFromStreamMime);
154
155 %extend {
156 %RenameDocCtor(
157 EmptyImage,
158 "Construct an empty image of a given size, optionally setting all
159pixels to black.", "",
160 wxImage(int width=0, int height=0, bool clear = true))
161 {
162 if (width > 0 && height > 0)
163 return new wxImage(width, height, clear);
164 else
165 return new wxImage;
166 }
167
168
169 MustHaveApp(wxImage(const wxBitmap &bitmap));
170
171 %RenameDocCtor(
172 ImageFromBitmap,
173 "Construct an Image from a `wx.Bitmap`.", "",
174 wxImage(const wxBitmap &bitmap))
175 {
176 return new wxImage(bitmap.ConvertToImage());
177 }
178
179 %RenameDocCtor(
180 ImageFromData,
181 "Construct an Image from a buffer of RGB bytes. Accepts either a
182string or a buffer object holding the data and the length of the data
183must be width*height*3.", "",
184 wxImage(int width, int height, buffer data, int DATASIZE))
185 {
186 if (DATASIZE != width*height*3) {
187 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
188 return NULL;
189 }
190
191 // Copy the source data so the wxImage can clean it up later
192 buffer copy = (buffer)malloc(DATASIZE);
193 if (copy == NULL) {
194 wxPyBLOCK_THREADS(PyErr_NoMemory());
195 return NULL;
196 }
197 memcpy(copy, data, DATASIZE);
198 return new wxImage(width, height, copy, false);
199 }
200
201
202 %RenameDocCtor(
203 ImageFromDataWithAlpha,
204 "Construct an Image from a buffer of RGB bytes with an Alpha channel.
205Accepts either a string or a buffer object holding the data and the
206length of the data must be width*height*3.", "",
207 wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE))
208 {
209 if (DATASIZE != width*height*3) {
210 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
211 return NULL;
212 }
213 if (ALPHASIZE != width*height) {
214 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
215 return NULL;
216 }
217
218 // Copy the source data so the wxImage can clean it up later
219 buffer dcopy = (buffer)malloc(DATASIZE);
220 if (dcopy == NULL) {
221 wxPyBLOCK_THREADS(PyErr_NoMemory());
222 return NULL;
223 }
224 memcpy(dcopy, data, DATASIZE);
225
226 buffer acopy = (buffer)malloc(ALPHASIZE);
227 if (acopy == NULL) {
228 wxPyBLOCK_THREADS(PyErr_NoMemory());
229 return NULL;
230 }
231 memcpy(acopy, alpha, ALPHASIZE);
232
233 return new wxImage(width, height, dcopy, acopy, false);
234 }
235 }
236
237 // TODO: wxImage( char** xpmData );
238
239
240 // Turn it back on again
241 %typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); }
242
243
244 void Create( int width, int height );
245 void Destroy();
246
247 wxImage Scale( int width, int height );
248 wxImage ShrinkBy( int xFactor , int yFactor ) const ;
249 wxImage& Rescale(int width, int height);
250
251 // resizes the image in place
252 wxImage& Resize( const wxSize& size, const wxPoint& pos,
253 int r = -1, int g = -1, int b = -1 );
254
255 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
256
257 %Rename(SetRGBRect,
258 void, SetRGB( const wxRect& rect,
259 unsigned char r, unsigned char g, unsigned char b ));
260
261 unsigned char GetRed( int x, int y );
262 unsigned char GetGreen( int x, int y );
263 unsigned char GetBlue( int x, int y );
264
265 void SetAlpha(int x, int y, unsigned char alpha);
266 unsigned char GetAlpha(int x, int y);
267 bool HasAlpha();
268
269 DocDeclStr(
270 void , InitAlpha(),
271 "Initializes the image alpha channel data. It is an error to call it if
272the image already has alpha data. If it doesn't, alpha data will be by
273default initialized to all pixels being fully opaque. But if the image
274has a a mask colour, all mask pixels will be completely transparent.", "");
275
276
277 DocDeclStr(
278 bool , IsTransparent(int x, int y,
279 unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD) const,
280 "Returns True if this pixel is masked or has an alpha value less than
281the spcified threshold.", "");
282
283
284 // find first colour that is not used in the image and has higher
285 // RGB values than <startR,startG,startB>
286 DocDeclAStr(
287 bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
288 byte startR = 0, byte startG = 0, byte startB = 0 ) const,
289 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
290 "Find first colour that is not used in the image and has higher RGB
291values than startR, startG, startB. Returns a tuple consisting of a
292success flag and rgb values.", "");
293
294
295 DocDeclStr(
296 bool , ConvertAlphaToMask(byte threshold = wxIMAGE_ALPHA_THRESHOLD),
297 "If the image has alpha channel, this method converts it to mask. All pixels
298with alpha value less than ``threshold`` are replaced with mask colour and the
299alpha channel is removed. Mask colour is chosen automatically using
300`FindFirstUnusedColour`.
301
302If the image image doesn't have alpha channel, ConvertAlphaToMask does
303nothing.", "");
304
305
306 DocDeclStr(
307 bool , ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b ),
308 "This method converts an image where the original alpha information is
309only available as a shades of a colour (actually shades of grey)
310typically when you draw anti-aliased text into a bitmap. The DC
311drawing routines draw grey values on the black background although
312they actually mean to draw white with differnt alpha values. This
313method reverses it, assuming a black (!) background and white text.
314The method will then fill up the whole image with the colour given.", "");
315
316
317
318 // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour
319 bool SetMaskFromImage(const wxImage & mask,
320 byte mr, byte mg, byte mb);
321
322// void DoFloodFill (wxCoord x, wxCoord y,
323// const wxBrush & fillBrush,
324// const wxColour& testColour,
325// int style = wxFLOOD_SURFACE,
326// int LogicalFunction = wxCOPY /* currently unused */ ) ;
327
328 static bool CanRead( const wxString& name );
329 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
330
331 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
332 %Rename(LoadMimeFile, bool, LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ));
333
334 bool SaveFile( const wxString& name, int type );
335 %Rename(SaveMimeFile, bool, SaveFile( const wxString& name, const wxString& mimetype ));
336
337 %Rename(CanReadStream, static bool, CanRead( wxInputStream& stream ));
338 %Rename(LoadStream, bool, LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ));
339 %Rename(LoadMimeStream, bool, LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ));
340
341 bool Ok();
342 int GetWidth();
343 int GetHeight();
344
345 %extend {
346 wxSize GetSize() {
347 wxSize size(self->GetWidth(), self->GetHeight());
348 return size;
349 }
350 }
351
352 wxImage GetSubImage(const wxRect& rect);
353
354 // Paste the image or part of this image into an image of the given size at the pos
355 // any newly exposed areas will be filled with the rgb colour
356 // by default if r = g = b = -1 then fill with this image's mask colour or find and
357 // set a suitable mask colour
358 wxImage Size( const wxSize& size, const wxPoint& pos,
359 int r = -1, int g = -1, int b = -1 ) const;
360
361 wxImage Copy();
362 void Paste( const wxImage &image, int x, int y );
363
364 //unsigned char *GetData();
365 //void SetData( unsigned char *data );
366
367 %extend {
368 DocStr(GetData,
369 "Returns a string containing a copy of the RGB bytes of the image.", "");
370 PyObject* GetData()
371 {
372 buffer data = self->GetData();
373 int len = self->GetWidth() * self->GetHeight() * 3;
374 PyObject* rv;
375 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
376 return rv;
377 }
378 DocStr(SetData,
379 "Resets the Image's RGB data from a buffer of RGB bytes. Accepts
380either a string or a buffer object holding the data and the length of
381the data must be width*height*3.", "");
382 void SetData(buffer data, int DATASIZE)
383 {
384 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
385 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
386 return;
387 }
388 buffer copy = (buffer)malloc(DATASIZE);
389 if (copy == NULL) {
390 wxPyBLOCK_THREADS(PyErr_NoMemory());
391 return;
392 }
393 memcpy(copy, data, DATASIZE);
394 self->SetData(copy, false);
395 // wxImage takes ownership of copy...
396 }
397
398
399 DocStr(GetDataBuffer,
400 "Returns a writable Python buffer object that is pointing at the RGB
401image data buffer inside the wx.Image.", "");
402 PyObject* GetDataBuffer()
403 {
404 buffer data = self->GetData();
405 int len = self->GetWidth() * self->GetHeight() * 3;
406 PyObject* rv;
407 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
408 return rv;
409 }
410
411 DocStr(SetDataBuffer,
412 "Sets the internal image data pointer to point at a Python buffer
413object. This can save a copy of the data but you must ensure that the
414buffer object lives longer than the wx.Image does.", "");
415 void SetDataBuffer(buffer data, int DATASIZE)
416 {
417 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
418 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
419 return;
420 }
421 self->SetData(data, true);
422 }
423
424
425
426 DocStr(GetAlphaData,
427 "Returns a string containing a copy of the alpha bytes of the image.", "");
428 PyObject* GetAlphaData() {
429 buffer data = self->GetAlpha();
430 if (! data) {
431 RETURN_NONE();
432 } else {
433 int len = self->GetWidth() * self->GetHeight();
434 PyObject* rv;
435 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
436 return rv;
437 }
438 }
439
440 DocStr(SetAlphaData,
441 "Resets the Image's alpha data from a buffer of bytes. Accepts either
442a string or a buffer object holding the data and the length of the
443data must be width*height.", "");
444 void SetAlphaData(buffer alpha, int ALPHASIZE)
445 {
446 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
447 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
448 return;
449 }
450 buffer acopy = (buffer)malloc(ALPHASIZE);
451 if (acopy == NULL) {
452 wxPyBLOCK_THREADS(PyErr_NoMemory());
453 return;
454 }
455 memcpy(acopy, alpha, ALPHASIZE);
456 self->SetAlpha(acopy, false);
457 // wxImage takes ownership of acopy...
458 }
459
460
461
462 DocStr(GetDataBuffer,
463 "Returns a writable Python buffer object that is pointing at the Alpha
464data buffer inside the wx.Image.", "");
465 PyObject* GetAlphaBuffer()
466 {
467 buffer data = self->GetAlpha();
468 int len = self->GetWidth() * self->GetHeight();
469 PyObject* rv;
470 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
471 return rv;
472 }
473
474
475 DocStr(SetDataBuffer,
476 "Sets the internal image alpha pointer to point at a Python buffer
477object. This can save a copy of the data but you must ensure that the
478buffer object lives longer than the wx.Image does.", "");
479 void SetAlphaBuffer(buffer alpha, int ALPHASIZE)
480 {
481 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
482 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
483 return;
484 }
485 self->SetAlpha(alpha, true);
486 }
487 }
488
489 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
490
491 DocDeclAStr(
492 /*bool*/ void , GetOrFindMaskColour( unsigned char *OUTPUT,
493 unsigned char *OUTPUT,
494 unsigned char *OUTPUT ) const,
495 "GetOrFindMaskColour() -> (r,g,b)",
496 "Get the current mask colour or find a suitable colour.", "");
497
498
499 unsigned char GetMaskRed();
500 unsigned char GetMaskGreen();
501 unsigned char GetMaskBlue();
502 void SetMask( bool mask = true );
503 bool HasMask();
504
505 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
506 bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ;
507 wxImage Rotate90( bool clockwise = true ) ;
508 wxImage Mirror( bool horizontally = true ) ;
509
510 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
511 unsigned char r2, unsigned char g2, unsigned char b2 );
512
513 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
514 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
515
516 void SetOption(const wxString& name, const wxString& value);
517 %Rename(SetOptionInt, void, SetOption(const wxString& name, int value));
518 wxString GetOption(const wxString& name) const;
519 int GetOptionInt(const wxString& name) const;
520 bool HasOption(const wxString& name) const;
521
522 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
523 unsigned long ComputeHistogram( wxImageHistogram& h );
524
525 static void AddHandler( wxImageHandler *handler );
526 static void InsertHandler( wxImageHandler *handler );
527 static bool RemoveHandler( const wxString& name );
528 static wxString GetImageExtWildcard();
529
530
531MustHaveApp(ConvertToBitmap);
532MustHaveApp(ConvertToMonoBitmap);
533
534 %extend {
535 wxBitmap ConvertToBitmap(int depth=-1) {
536 wxBitmap bitmap(*self, depth);
537 return bitmap;
538 }
539
540 wxBitmap ConvertToMonoBitmap( unsigned char red,
541 unsigned char green,
542 unsigned char blue ) {
543 wxImage mono = self->ConvertToMono( red, green, blue );
544 wxBitmap bitmap( mono, 1 );
545 return bitmap;
546 }
547 }
548
549 %pythoncode { def __nonzero__(self): return self.Ok() }
550};
551
552
553
554///void wxInitAllImageHandlers();
555
556%pythoncode {
557 def InitAllImageHandlers():
558 """
559 The former functionality of InitAllImageHanders is now done internal to
560 the _core_ extension module and so this function has become a simple NOP.
561 """
562 pass
563}
564
565
566
567// See also wxPy_ReinitStockObjects in helpers.cpp
568%immutable;
569const wxImage wxNullImage;
570%mutable;
571
572//---------------------------------------------------------------------------
573
574MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME);
575MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
576MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
577MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
578MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
579MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX);
580MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY);
581MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
582MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY);
583
584enum
585{
586 wxIMAGE_RESOLUTION_INCHES = 1,
587 wxIMAGE_RESOLUTION_CM = 2
588};
589
590
591MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE);
592MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL);
593MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION);
594MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR);
595
596MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT);
597MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH);
598
599enum
600{
601 wxPNG_TYPE_COLOUR = 0,
602 wxPNG_TYPE_GREY = 2,
603 wxPNG_TYPE_GREY_RED = 3
604};
605
606enum
607{
608 wxBMP_24BPP = 24, // default, do not need to set
609 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
610 wxBMP_8BPP = 8, // 8bpp, quantized colors
611 wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
612 wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
613 wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
614 wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
615 wxBMP_4BPP = 4, // 4bpp, quantized colors
616 wxBMP_1BPP = 1, // 1bpp, quantized "colors"
617 wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
618};
619
620
621class wxBMPHandler : public wxImageHandler {
622public:
623 wxBMPHandler();
624};
625
626class wxICOHandler : public wxBMPHandler {
627public:
628 wxICOHandler();
629};
630
631class wxCURHandler : public wxICOHandler {
632public:
633 wxCURHandler();
634};
635
636class wxANIHandler : public wxCURHandler {
637public:
638 wxANIHandler();
639};
640
641
642//---------------------------------------------------------------------------
643
644class wxPNGHandler : public wxImageHandler {
645public:
646 wxPNGHandler();
647};
648
649
650class wxGIFHandler : public wxImageHandler {
651public:
652 wxGIFHandler();
653};
654
655
656class wxPCXHandler : public wxImageHandler {
657public:
658 wxPCXHandler();
659};
660
661
662class wxJPEGHandler : public wxImageHandler {
663public:
664 wxJPEGHandler();
665};
666
667
668class wxPNMHandler : public wxImageHandler {
669public:
670 wxPNMHandler();
671};
672
673class wxXPMHandler : public wxImageHandler {
674public:
675 wxXPMHandler();
676};
677
678class wxTIFFHandler : public wxImageHandler {
679public:
680 wxTIFFHandler();
681};
682
683
684#if wxUSE_IFF
685class wxIFFHandler : public wxImageHandler {
686public:
687 wxIFFHandler();
688};
689#endif
690
691//---------------------------------------------------------------------------
692
693%{
694#include <wx/quantize.h>
695%}
696
697enum {
698 wxQUANTIZE_INCLUDE_WINDOWS_COLOURS,
699// wxQUANTIZE_RETURN_8BIT_DATA,
700 wxQUANTIZE_FILL_DESTINATION_IMAGE
701};
702
703
704DocStr(wxQuantize,
705 "Performs quantization, or colour reduction, on a wxImage.", "");
706
707class wxQuantize /*: public wxObject */
708{
709public:
710
711 %extend {
712 DocStr(
713 Quantize,
714 "Reduce the colours in the source image and put the result into the
715destination image, setting the palette in the destination if
716needed. Both images may be the same, to overwrite the source image.", "
717:todo: Create a version that returns the wx.Palette used.");
718
719 static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
720 int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE)
721 {
722 return wxQuantize::Quantize(src, dest,
723 //NULL, // palette
724 desiredNoColours,
725 NULL, // eightBitData
726 flags);
727 }
728 }
729};
730
731
732//---------------------------------------------------------------------------