]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_image.i
mention wxLogInterposer(Temp)
[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
24 enum {
25 wxIMAGE_ALPHA_TRANSPARENT,
26 wxIMAGE_ALPHA_THRESHOLD,
27 wxIMAGE_ALPHA_OPAQUE
28 };
29
30 // Constants for wxImage::Scale() for determining the level of quality
31 enum
32 {
33 wxIMAGE_QUALITY_NORMAL = 0,
34 wxIMAGE_QUALITY_HIGH = 1
35 };
36
37 //---------------------------------------------------------------------------
38 %newgroup
39
40 DocStr(wxImageHandler,
41 "This is the base class for implementing image file loading/saving, and
42 image creation from data. It is used within `wx.Image` and is not
43 normally seen by the application.", "");
44 class wxImageHandler : public wxObject {
45 public:
46 // wxImageHandler(); Abstract Base Class
47 wxString GetName();
48 wxString GetExtension();
49 long GetType();
50 wxString GetMimeType();
51
52 //bool LoadFile(wxImage* image, wxInputStream& stream);
53 //bool SaveFile(wxImage* image, wxOutputStream& stream);
54 //virtual int GetImageCount( wxInputStream& stream );
55
56 bool CanRead( const wxString& name );
57 %Rename(CanReadStream, bool, CanRead( wxInputStream& stream ));
58
59 void SetName(const wxString& name);
60 void SetExtension(const wxString& extension);
61 void SetType(long type);
62 void SetMimeType(const wxString& mimetype);
63
64 %property(Extension, GetExtension, SetExtension, doc="See `GetExtension` and `SetExtension`");
65 %property(MimeType, GetMimeType, SetMimeType, doc="See `GetMimeType` and `SetMimeType`");
66 %property(Name, GetName, SetName, doc="See `GetName` and `SetName`");
67 %property(Type, GetType, SetType, doc="See `GetType` and `SetType`");
68 };
69
70
71 //---------------------------------------------------------------------------
72
73
74 DocStr(wxPyImageHandler,
75 "This is the base class for implementing image file loading/saving, and
76 image creation from data, all written in Python. To create a custom
77 image handler derive a new class from wx.PyImageHandler and provide
78 the following methods::
79
80 def DoCanRead(self, stream) --> bool
81 '''Check if this handler can read the image on the stream'''
82
83 def LoadFile(self, image, stream, verbose, index) --> bool
84 '''Load image data from the stream and load it into image.'''
85
86 def SaveFile(self, image, stream, verbose) --> bool
87 '''Save the iamge data in image to the stream using
88 this handler's image file format.'''
89
90 def GetImageCount(self, stream) --> int
91 '''If this image format can hold more than one image,
92 how many does the image on the stream have?'''
93
94 To activate your handler create an instance of it and pass it to
95 `wx.Image_AddHandler`. Be sure to call `SetName`, `SetType`, and
96 `SetExtension` from your constructor.
97 ", "");
98
99 class wxPyImageHandler: public wxImageHandler {
100 public:
101 %pythonAppend wxPyImageHandler() "self._SetSelf(self)"
102 wxPyImageHandler();
103 void _SetSelf(PyObject *self);
104 };
105
106
107 //---------------------------------------------------------------------------
108
109
110 class wxImageHistogram /* : public wxImageHistogramBase */
111 {
112 public:
113 wxImageHistogram();
114
115 DocStr(MakeKey, "Get the key in the histogram for the given RGB values", "");
116 static unsigned long MakeKey(byte r,
117 byte g,
118 byte b);
119
120 DocDeclAStr(
121 bool, FindFirstUnusedColour(byte *OUTPUT,
122 byte *OUTPUT,
123 byte *OUTPUT,
124 byte startR = 1,
125 byte startG = 0,
126 byte startB = 0 ) const,
127 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
128 "Find first colour that is not used in the image and has higher RGB
129 values than startR, startG, startB. Returns a tuple consisting of a
130 success flag and rgb values.", "");
131
132 %extend {
133 DocStr(GetCount,
134 "Returns the pixel count for the given key. Use `MakeKey` to create a
135 key value from a RGB tripple.", "");
136 unsigned long GetCount(unsigned long key) {
137 wxImageHistogramEntry e = (*self)[key];
138 return e.value;
139 }
140
141 DocStr(GetCountRGB,
142 "Returns the pixel count for the given RGB values.", "");
143 unsigned long GetCountRGB(byte r,
144 byte g,
145 byte b) {
146 unsigned long key = wxImageHistogram::MakeKey(r, g, b);
147 wxImageHistogramEntry e = (*self)[key];
148 return e.value;
149 }
150
151 DocStr(GetCountColour,
152 "Returns the pixel count for the given `wx.Colour` value.", "");
153 unsigned long GetCountColour(const wxColour& colour) {
154 unsigned long key = wxImageHistogram::MakeKey(colour.Red(),
155 colour.Green(),
156 colour.Blue());
157 wxImageHistogramEntry e = (*self)[key];
158 return e.value;
159 }
160 }
161
162 };
163
164
165 //---------------------------------------------------------------------------
166
167 DocStr(wxImage,
168 "A platform-independent image class. An image can be created from
169 data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a
170 variety of formats. Functions are available to set and get image
171 bits, so it can be used for basic image manipulation.
172
173 A wx.Image cannot be drawn directly to a `wx.DC`. Instead, a
174 platform-specific `wx.Bitmap` object must be created from it using the
175 `wx.BitmapFromImage` constructor. This bitmap can then be drawn in a
176 device context, using `wx.DC.DrawBitmap`.
177
178 One colour value of the image may be used as a mask colour which will
179 lead to the automatic creation of a `wx.Mask` object associated to the
180 bitmap object.
181
182 wx.Image supports alpha channel data, that is in addition to a byte
183 for the red, green and blue colour components for each pixel it also
184 stores a byte representing the pixel opacity. An alpha value of 0
185 corresponds to a transparent pixel (null opacity) while a value of 255
186 means that the pixel is 100% opaque.
187
188 Unlike RGB data, not all images have an alpha channel and before using
189 `GetAlpha` you should check if this image contains an alpha channel
190 with `HasAlpha`. Note that currently only images loaded from PNG files
191 with transparency information will have an alpha channel.", "");
192
193
194 %{
195 // Pull the nested class out to the top level for SWIG's sake
196 #define wxImage_RGBValue wxImage::RGBValue
197 #define wxImage_HSVValue wxImage::HSVValue
198 %}
199
200 DocStr(wxImage_RGBValue,
201 "An object that contains values for red, green and blue which represent
202 the value of a color. It is used by `wx.Image.HSVtoRGB` and
203 `wx.Image.RGBtoHSV`, which converts between HSV color space and RGB
204 color space.", "");
205 class wxImage_RGBValue
206 {
207 public:
208 DocCtorStr(
209 wxImage_RGBValue(byte r=0, byte g=0, byte b=0),
210 "Constructor.", "");
211 byte red;
212 byte green;
213 byte blue;
214 };
215
216
217 DocStr(wxImage_HSVValue,
218 "An object that contains values for hue, saturation and value which
219 represent the value of a color. It is used by `wx.Image.HSVtoRGB` and
220 `wx.Image.RGBtoHSV`, which +converts between HSV color space and RGB
221 color space.", "");
222 class wxImage_HSVValue
223 {
224 public:
225 DocCtorStr(
226 wxImage_HSVValue(double h=0.0, double s=0.0, double v=0.0),
227 "Constructor.", "");
228 double hue;
229 double saturation;
230 double value;
231 };
232
233
234
235 class wxImage : public wxObject {
236 public:
237 %typemap(out) wxImage*; // turn off this typemap
238
239 DocCtorStr(
240 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
241 "Loads an image from a file.",
242 "
243 :param name: Name of the file from which to load the image.
244
245 :param type: May be one of the following:
246
247 ==================== =======================================
248 wx.BITMAP_TYPE_BMP Load a Windows bitmap file.
249 wx.BITMAP_TYPE_GIF Load a GIF bitmap file.
250 wx.BITMAP_TYPE_JPEG Load a JPEG bitmap file.
251 wx.BITMAP_TYPE_PNG Load a PNG bitmap file.
252 wx.BITMAP_TYPE_PCX Load a PCX bitmap file.
253 wx.BITMAP_TYPE_PNM Load a PNM bitmap file.
254 wx.BITMAP_TYPE_TIF Load a TIFF bitmap file.
255 wx.BITMAP_TYPE_XPM Load a XPM bitmap file.
256 wx.BITMAP_TYPE_ICO Load a Windows icon file (ICO).
257 wx.BITMAP_TYPE_CUR Load a Windows cursor file (CUR).
258 wx.BITMAP_TYPE_ANI Load a Windows animated cursor file (ANI).
259 wx.BITMAP_TYPE_ANY Will try to autodetect the format.
260 ==================== =======================================
261
262 :param index: Index of the image to load in the case that the
263 image file contains multiple images. This is only used by GIF,
264 ICO and TIFF handlers. The default value (-1) means to choose
265 the default image and is interpreted as the first image (the
266 one with index=0) by the GIF and TIFF handler and as the
267 largest and most colourful one by the ICO handler.
268
269 :see: `wx.ImageFromMime`, `wx.ImageFromStream`, `wx.ImageFromStreamMime`,
270 `wx.EmptyImage`, `wx.ImageFromBitmap`, `wx.ImageFromBuffer`,
271 `wx.ImageFromData`, `wx.ImageFromDataWithAlpha`
272 ");
273
274 ~wxImage();
275
276 // Alternate constructors
277 DocCtorStrName(
278 wxImage(const wxString& name, const wxString& mimetype, int index = -1),
279 "Loads an image from a file, using a MIME type string (such as
280 'image/jpeg') to specify image type.", "
281
282 :see: `wx.Image`",
283 ImageFromMime);
284
285 DocCtorStrName(
286 wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1),
287 "Loads an image from an input stream, or any readable Python file-like
288 object.", "
289
290 :see: `wx.Image`",
291 ImageFromStream);
292
293 DocCtorStrName(
294 wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ),
295 "Loads an image from an input stream, or any readable Python file-like
296 object, specifying the image format with a MIME type string.", "
297
298 :see: `wx.Image`",
299 ImageFromStreamMime);
300
301 %extend {
302 %RenameDocCtor(
303 EmptyImage,
304 "Construct an empty image of a given size, optionally setting all
305 pixels to black.", "
306
307 :see: `wx.Image`",
308 wxImage(int width=0, int height=0, bool clear = true))
309 {
310 if (width > 0 && height > 0)
311 return new wxImage(width, height, clear);
312 else
313 return new wxImage;
314 }
315
316
317 MustHaveApp(wxImage(const wxBitmap &bitmap));
318
319 %RenameDocCtor(
320 ImageFromBitmap,
321 "Construct an Image from a `wx.Bitmap`.", "
322
323 :see: `wx.Image`",
324 wxImage(const wxBitmap &bitmap))
325 {
326 return new wxImage(bitmap.ConvertToImage());
327 }
328
329 %RenameDocCtor(
330 ImageFromData,
331 "Construct an Image from a buffer of RGB bytes. Accepts either a
332 string or a buffer object holding the data and the length of the data
333 must be width*height*3.", "
334
335 :see: `wx.Image`",
336 wxImage(int width, int height, buffer data, int DATASIZE))
337 {
338 if (DATASIZE != width*height*3) {
339 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
340 return NULL;
341 }
342
343 // Copy the source data so the wxImage can clean it up later
344 buffer copy = (buffer)malloc(DATASIZE);
345 if (copy == NULL) {
346 wxPyBLOCK_THREADS(PyErr_NoMemory());
347 return NULL;
348 }
349 memcpy(copy, data, DATASIZE);
350 return new wxImage(width, height, copy, false);
351 }
352
353
354 %RenameDocCtor(
355 ImageFromDataWithAlpha,
356 "Construct an Image from a buffer of RGB bytes with an Alpha channel.
357 Accepts either a string or a buffer object holding the data and the
358 length of the data must be width*height*3 bytes, and the length of the
359 alpha data must be width*height bytes.", "
360
361 :see: `wx.Image`",
362 wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE))
363 {
364 if (DATASIZE != width*height*3) {
365 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
366 return NULL;
367 }
368 if (ALPHASIZE != width*height) {
369 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
370 return NULL;
371 }
372
373 // Copy the source data so the wxImage can clean it up later
374 buffer dcopy = (buffer)malloc(DATASIZE);
375 if (dcopy == NULL) {
376 wxPyBLOCK_THREADS(PyErr_NoMemory());
377 return NULL;
378 }
379 memcpy(dcopy, data, DATASIZE);
380
381 buffer acopy = (buffer)malloc(ALPHASIZE);
382 if (acopy == NULL) {
383 wxPyBLOCK_THREADS(PyErr_NoMemory());
384 return NULL;
385 }
386 memcpy(acopy, alpha, ALPHASIZE);
387
388 return new wxImage(width, height, dcopy, acopy, false);
389 }
390 }
391
392 // TODO: wxImage( char** xpmData );
393
394 // Turn the typemap back on again
395 %typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); }
396
397
398 DocDeclStr(
399 void , Create( int width, int height, bool clear=true ),
400 "Creates a fresh image. If clear is ``True``, the new image will be
401 initialized to black. Otherwise, the image data will be uninitialized.", "");
402
403 DocDeclStr(
404 void , Destroy(),
405 "Destroys the image data.", "");
406
407
408 DocDeclStr(
409 wxImage , Scale( int width, int height, int quality = wxIMAGE_QUALITY_NORMAL ),
410 "Returns a scaled version of the image. This is also useful for scaling
411 bitmaps in general as the only other way to scale bitmaps is to blit a
412 `wx.MemoryDC` into another `wx.MemoryDC`. The ``quality`` parameter
413 specifies what method to use for resampling the image. It can be
414 either wx.IMAGE_QUALITY_NORMAL, which uses the normal default scaling
415 method of pixel replication, or wx.IMAGE_QUALITY_HIGH which uses
416 bicubic and box averaging resampling methods for upsampling and
417 downsampling respectively.", "
418
419 It should be noted that although using wx.IMAGE_QUALITY_HIGH produces
420 much nicer looking results it is a slower method. Downsampling will
421 use the box averaging method which seems to operate very fast. If you
422 are upsampling larger images using this method you will most likely
423 notice that it is a bit slower and in extreme cases it will be quite
424 substantially slower as the bicubic algorithm has to process a lot of
425 data.
426
427 It should also be noted that the high quality scaling may not work as
428 expected when using a single mask colour for transparency, as the
429 scaling will blur the image and will therefore remove the mask
430 partially. Using the alpha channel will work.
431
432 :see: `Rescale`");
433
434
435 wxImage ResampleBox(int width, int height) const;
436 wxImage ResampleBicubic(int width, int height) const;
437
438 DocDeclStr(
439 wxImage , Blur(int radius),
440 "Blurs the image in both horizontal and vertical directions by the
441 specified pixel ``radius``. This should not be used when using a
442 single mask colour for transparency.", "");
443
444 DocDeclStr(
445 wxImage , BlurHorizontal(int radius),
446 "Blurs the image in the horizontal direction only. This should not be
447 used when using a single mask colour for transparency.
448 ", "");
449
450 DocDeclStr(
451 wxImage , BlurVertical(int radius),
452 "Blurs the image in the vertical direction only. This should not be
453 used when using a single mask colour for transparency.", "");
454
455
456
457 DocDeclStr(
458 wxImage , ShrinkBy( int xFactor , int yFactor ) const ,
459 "Return a version of the image scaled smaller by the given factors.", "");
460
461 DocDeclStr(
462 wxImage& , Rescale(int width, int height, int quality = wxIMAGE_QUALITY_NORMAL),
463 "Changes the size of the image in-place by scaling it: after a call to
464 this function, the image will have the given width and height.
465
466 Returns the (modified) image itself.", "
467
468 :see: `Scale`");
469
470
471 // resizes the image in place
472 DocDeclStr(
473 wxImage& , Resize( const wxSize& size, const wxPoint& pos,
474 int r = -1, int g = -1, int b = -1 ),
475 "Changes the size of the image in-place without scaling it, by adding
476 either a border with the given colour or cropping as necessary. The
477 image is pasted into a new image with the given size and background
478 colour at the position pos relative to the upper left of the new
479 image. If red = green = blue = -1 then use either the current mask
480 colour if set or find, use, and set a suitable mask colour for any
481 newly exposed areas.
482
483 Returns the (modified) image itself.", "
484
485 :see: `Size`");
486
487
488 DocDeclStr(
489 void , SetRGB( int x, int y, byte r, byte g, byte b ),
490 "Sets the pixel at the given coordinate. This routine performs
491 bounds-checks for the coordinate so it can be considered a safe way to
492 manipulate the data, but in some cases this might be too slow so that
493 the data will have to be set directly. In that case you will have to
494 get access to the image data using the `GetData` method.", "");
495
496
497 DocDeclStrName(
498 void, SetRGB( const wxRect& rect,
499 byte r, byte g, byte b ),
500 "Sets the colour of the pixels within the given rectangle. This routine
501 performs bounds-checks for the rectangle so it can be considered a
502 safe way to manipulate the data.", "",
503 SetRGBRect);
504
505 DocDeclStr(
506 byte , GetRed( int x, int y ),
507 "Returns the red intensity at the given coordinate.", "");
508
509 DocDeclStr(
510 byte , GetGreen( int x, int y ),
511 "Returns the green intensity at the given coordinate.", "");
512
513 DocDeclStr(
514 byte , GetBlue( int x, int y ),
515 "Returns the blue intensity at the given coordinate.", "");
516
517
518 DocDeclStr(
519 void , SetAlpha(int x, int y, byte alpha),
520 "Sets the alpha value for the given pixel. This function should only be
521 called if the image has alpha channel data, use `HasAlpha` to check
522 for this.", "");
523
524 DocDeclStr(
525 byte , GetAlpha(int x, int y),
526 "Returns the alpha value for the given pixel. This function may only be
527 called for the images with alpha channel, use `HasAlpha` to check for
528 this.
529
530 The returned value is the *opacity* of the image, i.e. the value of 0
531 corresponds to the fully transparent pixels while the value of 255 to
532 the fully opaque pixels.", "");
533
534 DocDeclStr(
535 bool , HasAlpha(),
536 "Returns true if this image has alpha channel, false otherwise.", "
537
538 :see: `GetAlpha`, `SetAlpha`");
539
540
541 DocDeclStr(
542 void , InitAlpha(),
543 "Initializes the image alpha channel data. It is an error to call it if
544 the image already has alpha data. If it doesn't, alpha data will be by
545 default initialized to all pixels being fully opaque. But if the image
546 has a a mask colour, all mask pixels will be completely transparent.", "");
547
548
549 DocDeclStr(
550 bool , IsTransparent(int x, int y,
551 byte threshold = wxIMAGE_ALPHA_THRESHOLD) const,
552 "Returns ``True`` if this pixel is masked or has an alpha value less
553 than the spcified threshold.", "");
554
555
556 // find first colour that is not used in the image and has higher
557 // RGB values than <startR,startG,startB>
558 DocDeclAStr(
559 bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
560 byte startR = 0, byte startG = 0, byte startB = 0 ) const,
561 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
562 "Find first colour that is not used in the image and has higher RGB
563 values than startR, startG, startB. Returns a tuple consisting of a
564 success flag and rgb values.", "");
565
566
567 DocDeclStr(
568 bool , ConvertAlphaToMask(byte threshold = wxIMAGE_ALPHA_THRESHOLD),
569 "If the image has alpha channel, this method converts it to mask. All
570 pixels with alpha value less than ``threshold`` are replaced with the
571 mask colour and the alpha channel is removed. The mask colour is
572 chosen automatically using `FindFirstUnusedColour`.
573
574 If the image image doesn't have alpha channel, ConvertAlphaToMask does
575 nothing.", "");
576
577
578 DocDeclStr(
579 bool , ConvertColourToAlpha( byte r, byte g, byte b ),
580 "This method converts an image where the original alpha information is
581 only available as a shades of a colour (actually shades of grey)
582 typically when you draw anti-aliased text into a bitmap. The DC
583 drawing routines draw grey values on the black background although
584 they actually mean to draw white with differnt alpha values. This
585 method reverses it, assuming a black (!) background and white text.
586 The method will then fill up the whole image with the colour given.", "");
587
588
589
590 DocDeclStr(
591 bool , SetMaskFromImage(const wxImage & mask,
592 byte mr, byte mg, byte mb),
593 "Sets the image's mask so that the pixels that have RGB value of
594 ``(mr,mg,mb)`` in ``mask`` will be masked in this image. This is done
595 by first finding an unused colour in the image, setting this colour as
596 the mask colour and then using this colour to draw all pixels in the
597 image who corresponding pixel in mask has given RGB value.
598
599 Returns ``False`` if ``mask`` does not have same dimensions as the
600 image or if there is no unused colour left. Returns ``True`` if the
601 mask was successfully applied.
602
603 Note that this method involves computing the histogram, which is
604 computationally intensive operation.", "");
605
606
607 // void DoFloodFill (wxCoord x, wxCoord y,
608 // const wxBrush & fillBrush,
609 // const wxColour& testColour,
610 // int style = wxFLOOD_SURFACE,
611 // int LogicalFunction = wxCOPY /* currently unused */ ) ;
612
613 DocDeclStr(
614 static bool , CanRead( const wxString& filename ),
615 "Returns True if the image handlers can read this file.", "");
616
617 DocDeclStr(
618 static int , GetImageCount( const wxString& filename, long type = wxBITMAP_TYPE_ANY ),
619 "If the image file contains more than one image and the image handler
620 is capable of retrieving these individually, this function will return
621 the number of available images.", "");
622
623
624 DocDeclStr(
625 bool , LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
626 "Loads an image from a file. If no handler type is provided, the
627 library will try to autodetect the format.", "");
628
629 DocDeclStrName(
630 bool , LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ),
631 "Loads an image from a file, specifying the image type with a MIME type
632 string.", "",
633 LoadMimeFile);
634
635
636 DocDeclStr(
637 bool , SaveFile( const wxString& name, int type ),
638 "Saves an image in the named file.", "");
639
640
641 DocDeclStrName(
642 bool , SaveFile( const wxString& name, const wxString& mimetype ),
643 "Saves an image in the named file.", "",
644 SaveMimeFile);
645
646 DocDeclStrName(
647 bool , SaveFile( wxOutputStream& stream, int type ),
648 "Saves an image in the named file.", "",
649 SaveStream);
650
651
652 DocDeclStrName(
653 bool , SaveFile( wxOutputStream& stream, const wxString& mimetype ),
654 "Saves an image in the named file.", "",
655 SaveMimeStream);
656
657
658 DocDeclStrName(
659 static bool , CanRead( wxInputStream& stream ),
660 "Returns True if the image handlers can read an image file from the
661 data currently on the input stream, or a readable Python file-like
662 object.", "",
663 CanReadStream);
664
665
666 DocDeclStrName(
667 bool , LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
668 "Loads an image from an input stream or a readable Python file-like
669 object. If no handler type is provided, the library will try to
670 autodetect the format.", "",
671 LoadStream);
672
673
674 DocDeclStrName(
675 bool , LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ),
676 "Loads an image from an input stream or a readable Python file-like
677 object, using a MIME type string to specify the image file format.", "",
678 LoadMimeStream);
679
680
681 DocDeclStr(
682 bool , IsOk(),
683 "Returns true if image data is present.", "");
684 %pythoncode { Ok = IsOk }
685
686 DocDeclStr(
687 int , GetWidth(),
688 "Gets the width of the image in pixels.", "");
689
690 DocDeclStr(
691 int , GetHeight(),
692 "Gets the height of the image in pixels.", "");
693
694
695 %extend {
696 DocStr(GetSize,
697 "Returns the size of the image in pixels.", "");
698 wxSize GetSize() {
699 wxSize size(self->GetWidth(), self->GetHeight());
700 return size;
701 }
702 }
703
704
705 DocDeclStr(
706 wxImage , GetSubImage(const wxRect& rect),
707 "Returns a sub image of the current one as long as the rect belongs
708 entirely to the image.", "");
709
710
711 DocDeclStr(
712 wxImage , Size( const wxSize& size, const wxPoint& pos,
713 int r = -1, int g = -1, int b = -1 ) const,
714 "Returns a resized version of this image without scaling it by adding
715 either a border with the given colour or cropping as necessary. The
716 image is pasted into a new image with the given size and background
717 colour at the position ``pos`` relative to the upper left of the new
718 image. If red = green = blue = -1 then use either the current mask
719 colour if set or find, use, and set a suitable mask colour for any
720 newly exposed areas.", "
721
722 :see: `Resize`");
723
724
725 DocDeclStr(
726 wxImage , Copy(),
727 "Returns an identical copy of the image.", "");
728
729 DocDeclStr(
730 void , Paste( const wxImage &image, int x, int y ),
731 "Pastes ``image`` into this instance and takes care of the mask colour
732 and any out of bounds problems.", "");
733
734
735 //unsigned char *GetData();
736 //void SetData( unsigned char *data );
737
738 %extend {
739 DocStr(GetData,
740 "Returns a string containing a copy of the RGB bytes of the image.", "");
741 PyObject* GetData()
742 {
743 buffer data = self->GetData();
744 int len = self->GetWidth() * self->GetHeight() * 3;
745 PyObject* rv;
746 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
747 return rv;
748 }
749 DocStr(SetData,
750 "Resets the Image's RGB data from a buffer of RGB bytes. Accepts
751 either a string or a buffer object holding the data and the length of
752 the data must be width*height*3.", "");
753 void SetData(buffer data, int DATASIZE)
754 {
755 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
756 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
757 return;
758 }
759 buffer copy = (buffer)malloc(DATASIZE);
760 if (copy == NULL) {
761 wxPyBLOCK_THREADS(PyErr_NoMemory());
762 return;
763 }
764 memcpy(copy, data, DATASIZE);
765 self->SetData(copy, false);
766 // wxImage takes ownership of copy...
767 }
768
769
770 DocStr(GetDataBuffer,
771 "Returns a writable Python buffer object that is pointing at the RGB
772 image data buffer inside the wx.Image. You need to ensure that you do
773 not use this buffer object after the image has been destroyed.", "");
774 PyObject* GetDataBuffer()
775 {
776 buffer data = self->GetData();
777 int len = self->GetWidth() * self->GetHeight() * 3;
778 PyObject* rv;
779 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
780 return rv;
781 }
782
783 DocStr(SetDataBuffer,
784 "Sets the internal image data pointer to point at a Python buffer
785 object. This can save making an extra copy of the data but you must
786 ensure that the buffer object lives longer than the wx.Image does.", "");
787 void SetDataBuffer(buffer data, int DATASIZE)
788 {
789 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
790 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
791 return;
792 }
793 self->SetData(data, true);
794 }
795
796
797
798 DocStr(GetAlphaData,
799 "Returns a string containing a copy of the alpha bytes of the image.", "");
800 PyObject* GetAlphaData() {
801 buffer data = self->GetAlpha();
802 if (! data) {
803 RETURN_NONE();
804 } else {
805 int len = self->GetWidth() * self->GetHeight();
806 PyObject* rv;
807 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
808 return rv;
809 }
810 }
811
812 DocStr(SetAlphaData,
813 "Resets the Image's alpha data from a buffer of bytes. Accepts either
814 a string or a buffer object holding the data and the length of the
815 data must be width*height.", "");
816 void SetAlphaData(buffer alpha, int ALPHASIZE)
817 {
818 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
819 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
820 return;
821 }
822 buffer acopy = (buffer)malloc(ALPHASIZE);
823 if (acopy == NULL) {
824 wxPyBLOCK_THREADS(PyErr_NoMemory());
825 return;
826 }
827 memcpy(acopy, alpha, ALPHASIZE);
828 self->SetAlpha(acopy, false);
829 // wxImage takes ownership of acopy...
830 }
831
832
833
834 DocStr(GetAlphaBuffer,
835 "Returns a writable Python buffer object that is pointing at the Alpha
836 data buffer inside the wx.Image. You need to ensure that you do not
837 use this buffer object after the image has been destroyed.", "");
838 PyObject* GetAlphaBuffer()
839 {
840 buffer data = self->GetAlpha();
841 int len = self->GetWidth() * self->GetHeight();
842 PyObject* rv;
843 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
844 return rv;
845 }
846
847
848 DocStr(SetAlphaBuffer,
849 "Sets the internal image alpha pointer to point at a Python buffer
850 object. This can save making an extra copy of the data but you must
851 ensure that the buffer object lives as long as the wx.Image does.", "");
852 void SetAlphaBuffer(buffer alpha, int ALPHASIZE)
853 {
854 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
855 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
856 return;
857 }
858 self->SetAlpha(alpha, true);
859 }
860 }
861
862
863
864 DocDeclStr(
865 void , SetMaskColour( byte r, byte g, byte b ),
866 "Sets the mask colour for this image (and tells the image to use the
867 mask).", "");
868
869
870 DocDeclAStr(
871 /*bool*/ void , GetOrFindMaskColour( byte *OUTPUT,
872 byte *OUTPUT,
873 byte *OUTPUT ) const,
874 "GetOrFindMaskColour() -> (r,g,b)",
875 "Get the current mask colour or find a suitable colour.", "");
876
877
878 DocDeclStr(
879 byte , GetMaskRed(),
880 "Gets the red component of the mask colour.", "");
881
882 DocDeclStr(
883 byte , GetMaskGreen(),
884 "Gets the green component of the mask colour.", "");
885
886 DocDeclStr(
887 byte , GetMaskBlue(),
888 "Gets the blue component of the mask colour.", "");
889
890 DocDeclStr(
891 void , SetMask( bool mask = true ),
892 "Specifies whether there is a mask or not. The area of the mask is
893 determined by the current mask colour.", "");
894
895 DocDeclStr(
896 bool , HasMask(),
897 "Returns ``True`` if there is a mask active, ``False`` otherwise.", "");
898
899
900 DocDeclStr(
901 wxImage , Rotate(double angle, const wxPoint & centre_of_rotation,
902 bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ,
903 "Rotates the image about the given point, by ``angle`` radians. Passing
904 ``True`` to ``interpolating`` results in better image quality, but is
905 slower. If the image has a mask, then the mask colour is used for the
906 uncovered pixels in the rotated image background. Otherwise, black
907 will be used as the fill colour.
908
909 Returns the rotated image, leaving this image intact.", "");
910
911 DocDeclStr(
912 wxImage , Rotate90( bool clockwise = true ) ,
913 "Returns a copy of the image rotated 90 degrees in the direction
914 indicated by ``clockwise``.", "");
915
916 DocDeclStr(
917 wxImage , Mirror( bool horizontally = true ) ,
918 "Returns a mirrored copy of the image. The parameter ``horizontally``
919 indicates the orientation.", "");
920
921
922 DocDeclStr(
923 void , Replace( byte r1, byte g1, byte b1,
924 byte r2, byte g2, byte b2 ),
925 "Replaces the colour specified by ``(r1,g1,b1)`` by the colour
926 ``(r2,g2,b2)``.", "");
927
928 DocDeclStr(
929 wxImage , ConvertToGreyscale( double lr = 0.299,
930 double lg = 0.587,
931 double lb = 0.114 ) const,
932 "Convert to greyscale image. Uses the luminance component (Y) of the
933 image. The luma value (YUV) is calculated using (R * lr) + (G * lg) + (B * lb),
934 defaults to ITU-T BT.601", "");
935
936
937 DocDeclStr(
938 wxImage , ConvertToMono( byte r, byte g, byte b ) const,
939 "Returns monochromatic version of the image. The returned image has
940 white colour where the original has ``(r,g,b)`` colour and black
941 colour everywhere else.", "");
942
943
944 DocDeclStr(
945 void , SetOption(const wxString& name, const wxString& value),
946 "Sets an image handler defined option. For example, when saving as a
947 JPEG file, the option ``wx.IMAGE_OPTION_QUALITY`` is used, which is a
948 number between 0 and 100 (0 is terrible, 100 is very good).", "
949
950 ================================= ===
951 wx.IMAGE_OPTION_BMP_FORMAT
952 wx.IMAGE_OPTION_CUR_HOTSPOT_X
953 wx.IMAGE_OPTION_CUR_HOTSPOT_Y
954 wx.IMAGE_OPTION_RESOLUTION
955 wx.IMAGE_OPTION_RESOLUTIONX
956 wx.IMAGE_OPTION_RESOLUTIONY
957 wx.IMAGE_OPTION_RESOLUTIONUNIT
958 wx.IMAGE_OPTION_QUALITY
959 wx.IMAGE_OPTION_BITSPERSAMPLE
960 wx.IMAGE_OPTION_SAMPLESPERPIXEL
961 wx.IMAGE_OPTION_COMPRESSION
962 wx.IMAGE_OPTION_IMAGEDESCRIPTOR
963 wx.IMAGE_OPTION_PNG_FORMAT
964 wx.IMAGE_OPTION_PNG_BITDEPTH
965 ================================= ===
966
967 :see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOptionInt`");
968
969 DocDeclStrName(
970 void, SetOption(const wxString& name, int value),
971 "Sets an image option as an integer.", "
972
973 :see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOption`",
974 SetOptionInt);
975
976 DocDeclStr(
977 wxString , GetOption(const wxString& name) const,
978 "Gets the value of an image handler option.", "
979
980 :see: `HasOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
981
982 DocDeclStr(
983 int , GetOptionInt(const wxString& name) const,
984 "Gets the value of an image handler option as an integer. If the given
985 option is not present, the function returns 0.", "
986
987 :see: `HasOption`, `GetOption`, `SetOptionInt`, `SetOption`");
988
989 DocDeclStr(
990 bool , HasOption(const wxString& name) const,
991 "Returns true if the given option is present.", "
992
993 :see: `GetOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
994
995
996 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
997 unsigned long ComputeHistogram( wxImageHistogram& h );
998
999 static void AddHandler( wxImageHandler *handler );
1000 static void InsertHandler( wxImageHandler *handler );
1001 static bool RemoveHandler( const wxString& name );
1002 %extend {
1003 static PyObject* GetHandlers() {
1004 wxList& list = wxImage::GetHandlers();
1005 return wxPy_ConvertList(&list);
1006 }
1007 }
1008
1009 DocDeclStr(
1010 static wxString , GetImageExtWildcard(),
1011 "Iterates all registered wxImageHandler objects, and returns a string
1012 containing file extension masks suitable for passing to file open/save
1013 dialog boxes.", "");
1014
1015
1016
1017 MustHaveApp(ConvertToBitmap);
1018 MustHaveApp(ConvertToMonoBitmap);
1019
1020 %extend {
1021 wxBitmap ConvertToBitmap(int depth=-1) {
1022 wxBitmap bitmap(*self, depth);
1023 return bitmap;
1024 }
1025
1026 wxBitmap ConvertToMonoBitmap( byte red,
1027 byte green,
1028 byte blue ) {
1029 wxImage mono = self->ConvertToMono( red, green, blue );
1030 wxBitmap bitmap( mono, 1 );
1031 return bitmap;
1032 }
1033 }
1034
1035
1036 DocDeclStr(
1037 void , RotateHue(double angle),
1038 "Rotates the hue of each pixel of the image. Hue is a double in the
1039 range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees", "");
1040
1041 DocDeclStr(
1042 static wxImage_HSVValue , RGBtoHSV(wxImage_RGBValue rgb),
1043 "Converts a color in RGB color space to HSV color space.", "");
1044
1045 DocDeclStr(
1046 static wxImage_RGBValue , HSVtoRGB(wxImage_HSVValue hsv),
1047 "Converts a color in HSV color space to RGB color space.", "");
1048
1049
1050 %pythoncode { def __nonzero__(self): return self.IsOk() }
1051
1052 %property(AlphaBuffer, GetAlphaBuffer, SetAlphaBuffer, doc="See `GetAlphaBuffer` and `SetAlphaBuffer`");
1053 %property(AlphaData, GetAlphaData, SetAlphaData, doc="See `GetAlphaData` and `SetAlphaData`");
1054 %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
1055 %property(DataBuffer, GetDataBuffer, SetDataBuffer, doc="See `GetDataBuffer` and `SetDataBuffer`");
1056 %property(Height, GetHeight, doc="See `GetHeight`");
1057 %property(MaskBlue, GetMaskBlue, doc="See `GetMaskBlue`");
1058 %property(MaskGreen, GetMaskGreen, doc="See `GetMaskGreen`");
1059 %property(MaskRed, GetMaskRed, doc="See `GetMaskRed`");
1060 %property(Width, GetWidth, doc="See `GetWidth`");
1061
1062 };
1063
1064
1065
1066 // Make an image from buffer objects. Not that this is here instead of in the
1067 // wxImage class (as a constructor) because there is already another one with
1068 // the exact same signature, so there woudl be ambiguities in the generated
1069 // C++. Doing it as an independent factory function like this accomplishes
1070 // the same thing however.
1071 %newobject _ImageFromBuffer;
1072 %inline %{
1073 wxImage* _ImageFromBuffer(int width, int height,
1074 buffer data, int DATASIZE,
1075 buffer alpha=NULL, int ALPHASIZE=0)
1076 {
1077 if (DATASIZE != width*height*3) {
1078 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
1079 return NULL;
1080 }
1081 if (alpha != NULL) {
1082 if (ALPHASIZE != width*height) {
1083 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
1084 return NULL;
1085 }
1086 return new wxImage(width, height, data, alpha, true);
1087 }
1088 return new wxImage(width, height, data, true);
1089 }
1090 %}
1091
1092 %pythoncode {
1093 def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None):
1094 """
1095 Creates a `wx.Image` from the data in dataBuffer. The dataBuffer
1096 parameter must be a Python object that implements the buffer interface,
1097 such as a string, array, etc. The dataBuffer object is expected to
1098 contain a series of RGB bytes and be width*height*3 bytes long. A buffer
1099 object can optionally be supplied for the image's alpha channel data, and
1100 it is expected to be width*height bytes long.
1101
1102 The wx.Image will be created with its data and alpha pointers initialized
1103 to the memory address pointed to by the buffer objects, thus saving the
1104 time needed to copy the image data from the buffer object to the wx.Image.
1105 While this has advantages, it also has the shoot-yourself-in-the-foot
1106 risks associated with sharing a C pointer between two objects.
1107
1108 To help alleviate the risk a reference to the data and alpha buffer
1109 objects are kept with the wx.Image, so that they won't get deleted until
1110 after the wx.Image is deleted. However please be aware that it is not
1111 guaranteed that an object won't move its memory buffer to a new location
1112 when it needs to resize its contents. If that happens then the wx.Image
1113 will end up referring to an invalid memory location and could cause the
1114 application to crash. Therefore care should be taken to not manipulate
1115 the objects used for the data and alpha buffers in a way that would cause
1116 them to change size.
1117 """
1118 image = _core_._ImageFromBuffer(width, height, dataBuffer, alphaBuffer)
1119 image._buffer = dataBuffer
1120 image._alpha = alphaBuffer
1121 return image
1122 }
1123
1124
1125 ///void wxInitAllImageHandlers();
1126
1127 %pythoncode {
1128 def InitAllImageHandlers():
1129 """
1130 The former functionality of InitAllImageHanders is now done internal to
1131 the _core_ extension module and so this function has become a simple NOP.
1132 """
1133 pass
1134 }
1135
1136
1137
1138 %immutable;
1139 const wxImage wxNullImage;
1140 %mutable;
1141
1142 //---------------------------------------------------------------------------
1143
1144 MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME);
1145 MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
1146 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
1147 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
1148 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
1149 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX);
1150 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY);
1151 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
1152 MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY);
1153
1154 // constants used with wxIMAGE_OPTION_RESOLUTIONUNIT
1155 enum wxImageResolution
1156 {
1157 // Resolution not specified
1158 wxIMAGE_RESOLUTION_NONE = 0,
1159
1160 // Resolution specified in inches
1161 wxIMAGE_RESOLUTION_INCHES = 1,
1162
1163 // Resolution specified in centimeters
1164 wxIMAGE_RESOLUTION_CM = 2
1165 };
1166
1167
1168
1169 MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE);
1170 MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL);
1171 MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION);
1172 MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR);
1173
1174 MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT);
1175 MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH);
1176
1177 enum
1178 {
1179 wxPNG_TYPE_COLOUR = 0,
1180 wxPNG_TYPE_GREY = 2,
1181 wxPNG_TYPE_GREY_RED = 3
1182 };
1183
1184 enum
1185 {
1186 wxBMP_24BPP = 24, // default, do not need to set
1187 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
1188 wxBMP_8BPP = 8, // 8bpp, quantized colors
1189 wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
1190 wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
1191 wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
1192 wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
1193 wxBMP_4BPP = 4, // 4bpp, quantized colors
1194 wxBMP_1BPP = 1, // 1bpp, quantized "colors"
1195 wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
1196 };
1197
1198
1199 DocStr(wxBMPHandler,
1200 "A `wx.ImageHandler` for \*.bmp bitmap files.", "");
1201 class wxBMPHandler : public wxImageHandler {
1202 public:
1203 wxBMPHandler();
1204 };
1205
1206 DocStr(wxICOHandler,
1207 "A `wx.ImageHandler` for \*.ico icon files.", "");
1208 class wxICOHandler : public wxBMPHandler {
1209 public:
1210 wxICOHandler();
1211 };
1212
1213 DocStr(wxCURHandler,
1214 "A `wx.ImageHandler` for \*.cur cursor files.", "");
1215 class wxCURHandler : public wxICOHandler {
1216 public:
1217 wxCURHandler();
1218 };
1219
1220 DocStr(wxANIHandler,
1221 "A `wx.ImageHandler` for \*.ani animated cursor files.", "");
1222 class wxANIHandler : public wxCURHandler {
1223 public:
1224 wxANIHandler();
1225 };
1226
1227
1228 //---------------------------------------------------------------------------
1229
1230 DocStr(wxPNGHandler,
1231 "A `wx.ImageHandler` for PNG image files.", "");
1232 class wxPNGHandler : public wxImageHandler {
1233 public:
1234 wxPNGHandler();
1235 };
1236
1237
1238 DocStr(wxGIFHandler,
1239 "A `wx.ImageHandler` for GIF image files.", "");
1240 class wxGIFHandler : public wxImageHandler {
1241 public:
1242 wxGIFHandler();
1243 };
1244
1245
1246 DocStr(wxPCXHandler,
1247 "A `wx.ImageHandler` for PCX imager files.", "");
1248 class wxPCXHandler : public wxImageHandler {
1249 public:
1250 wxPCXHandler();
1251 };
1252
1253
1254 DocStr(wxJPEGHandler,
1255 "A `wx.ImageHandler` for JPEG/JPG image files.", "");
1256 class wxJPEGHandler : public wxImageHandler {
1257 public:
1258 wxJPEGHandler();
1259 };
1260
1261
1262 DocStr(wxPNMHandler,
1263 "A `wx.ImageHandler` for PNM image files.", "");
1264 class wxPNMHandler : public wxImageHandler {
1265 public:
1266 wxPNMHandler();
1267 };
1268
1269 DocStr(wxXPMHandler,
1270 "A `wx.ImageHandler` for XPM image.", "");
1271 class wxXPMHandler : public wxImageHandler {
1272 public:
1273 wxXPMHandler();
1274 };
1275
1276 DocStr(wxTIFFHandler,
1277 "A `wx.ImageHandler` for TIFF image files.", "");
1278 class wxTIFFHandler : public wxImageHandler {
1279 public:
1280 wxTIFFHandler();
1281 };
1282
1283
1284
1285 #if 0
1286 %{
1287 #include <wx/imagiff.h>
1288 %}
1289
1290 DocStr(wxIFFHandler,
1291 "A `wx.ImageHandler` for IFF image files.", "");
1292 class wxIFFHandler : public wxImageHandler {
1293 public:
1294 wxIFFHandler();
1295 };
1296 #endif
1297
1298
1299 %{
1300 #include <wx/imagtga.h>
1301 %}
1302
1303 DocStr(wxTGAHandler,
1304 "A `wx.ImageHandler` for TGA image files.", "");
1305 class wxTGAHandler : public wxImageHandler {
1306 public:
1307 wxTGAHandler();
1308 };
1309
1310
1311 //---------------------------------------------------------------------------
1312
1313 %{
1314 #include <wx/quantize.h>
1315 %}
1316
1317 enum {
1318 wxQUANTIZE_INCLUDE_WINDOWS_COLOURS,
1319 // wxQUANTIZE_RETURN_8BIT_DATA,
1320 wxQUANTIZE_FILL_DESTINATION_IMAGE
1321 };
1322
1323
1324 DocStr(wxQuantize,
1325 "Performs quantization, or colour reduction, on a wxImage.", "");
1326
1327 class wxQuantize /*: public wxObject */
1328 {
1329 public:
1330
1331 %extend {
1332 DocStr(
1333 Quantize,
1334 "Reduce the colours in the source image and put the result into the
1335 destination image, setting the palette in the destination if
1336 needed. Both images may be the same, to overwrite the source image.", "
1337 :todo: Create a version that returns the wx.Palette used.");
1338
1339 static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
1340 int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE)
1341 {
1342 return wxQuantize::Quantize(src, dest,
1343 //NULL, // palette
1344 desiredNoColours,
1345 NULL, // eightBitData
1346 flags);
1347 }
1348 }
1349 };
1350
1351
1352 //---------------------------------------------------------------------------