1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for wxImage and such
7 // Created: 25-Sept-2000
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 #include "wx/wxPython/pyistream.h"
22 //---------------------------------------------------------------------------
25 wxIMAGE_ALPHA_TRANSPARENT,
26 wxIMAGE_ALPHA_THRESHOLD,
31 //---------------------------------------------------------------------------
34 DocStr(wxImageHandler,
35 "This is the base class for implementing image file loading/saving, and
36 image creation from data. It is used within `wx.Image` and is not
37 normally seen by the application.", "");
38 class wxImageHandler : public wxObject {
40 // wxImageHandler(); Abstract Base Class
42 wxString GetExtension();
44 wxString GetMimeType();
46 //bool LoadFile(wxImage* image, wxInputStream& stream);
47 //bool SaveFile(wxImage* image, wxOutputStream& stream);
48 //virtual int GetImageCount( wxInputStream& stream );
49 //bool CanRead( wxInputStream& stream );
51 bool CanRead( const wxString& name );
53 void SetName(const wxString& name);
54 void SetExtension(const wxString& extension);
55 void SetType(long type);
56 void SetMimeType(const wxString& mimetype);
60 //---------------------------------------------------------------------------
63 DocStr(wxPyImageHandler,
64 "This is the base class for implementing image file loading/saving, and
65 image creation from data, all written in Python. To create a custom
66 image handler derive a new class from wx.PyImageHandler and provide
67 the following methods::
69 def DoCanRead(self, stream) --> bool
70 '''Check if this handler can read the image on the stream'''
72 def LoadFile(self, image, stream, verbose, index) --> bool
73 '''Load image data from the stream and load it into image.'''
75 def SaveFile(self, image, stream, verbose) --> bool
76 '''Save the iamge data in image to the stream using
77 this handler's image file format.'''
79 def GetImageCount(self, stream) --> int
80 '''If this image format can hold more than one image,
81 how many does the image on the stream have?'''
83 To activate your handler create an instance of it and pass it to
84 `wx.Image_AddHandler`. Be sure to call `SetName`, `SetType`, and
85 `SetExtension` from your constructor.
88 class wxPyImageHandler: public wxImageHandler {
90 %pythonAppend wxPyImageHandler() "self._SetSelf(self)"
92 void _SetSelf(PyObject *self);
96 //---------------------------------------------------------------------------
99 class wxImageHistogram /* : public wxImageHistogramBase */
104 DocStr(MakeKey, "Get the key in the histogram for the given RGB values", "");
105 static unsigned long MakeKey(byte r,
110 bool, FindFirstUnusedColour(byte *OUTPUT,
115 byte startB = 0 ) const,
116 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
117 "Find first colour that is not used in the image and has higher RGB
118 values than startR, startG, startB. Returns a tuple consisting of a
119 success flag and rgb values.", "");
123 "Returns the pixel count for the given key. Use `MakeKey` to create a
124 key value from a RGB tripple.", "");
125 unsigned long GetCount(unsigned long key) {
126 wxImageHistogramEntry e = (*self)[key];
131 "Returns the pixel count for the given RGB values.", "");
132 unsigned long GetCountRGB(byte r,
135 unsigned long key = wxImageHistogram::MakeKey(r, g, b);
136 wxImageHistogramEntry e = (*self)[key];
140 DocStr(GetCountColour,
141 "Returns the pixel count for the given `wx.Colour` value.", "");
142 unsigned long GetCountColour(const wxColour& colour) {
143 unsigned long key = wxImageHistogram::MakeKey(colour.Red(),
146 wxImageHistogramEntry e = (*self)[key];
154 //---------------------------------------------------------------------------
157 typedef unsigned char* buffer;
160 %typemap(in) (buffer data, int DATASIZE)
161 { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; }
163 %typemap(in) (buffer alpha, int ALPHASIZE)
164 { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; }
166 //---------------------------------------------------------------------------
170 "A platform-independent image class. An image can be created from
171 data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a
172 variety of formats. Functions are available to set and get image
173 bits, so it can be used for basic image manipulation.
175 A wx.Image cannot be drawn directly to a `wx.DC`. Instead, a
176 platform-specific `wx.Bitmap` object must be created from it using the
177 `wx.BitmapFromImage` constructor. This bitmap can then be drawn in a
178 device context, using `wx.DC.DrawBitmap`.
180 One colour value of the image may be used as a mask colour which will
181 lead to the automatic creation of a `wx.Mask` object associated to the
184 wx.Image supports alpha channel data, that is in addition to a byte
185 for the red, green and blue colour components for each pixel it also
186 stores a byte representing the pixel opacity. An alpha value of 0
187 corresponds to a transparent pixel (null opacity) while a value of 255
188 means that the pixel is 100% opaque.
190 Unlike RGB data, not all images have an alpha channel and before using
191 `GetAlpha` you should check if this image contains an alpha channel
192 with `HasAlpha`. Note that currently only images loaded from PNG files
193 with transparency information will have an alpha channel.", "");
197 // Pull the nested class out to the top level for SWIG's sake
198 #define wxImage_RGBValue wxImage::RGBValue
199 #define wxImage_HSVValue wxImage::HSVValue
202 DocStr(wxImage_RGBValue,
203 "An object that contains values for red, green and blue which represent
204 the value of a color. It is used by `wx.Image.HSVtoRGB` and
205 `wx.Image.RGBtoHSV`, which converts between HSV color space and RGB
207 class wxImage_RGBValue
211 wxImage_RGBValue(byte r=0, byte g=0, byte b=0),
219 DocStr(wxImage_HSVValue,
220 "An object that contains values for hue, saturation and value which
221 represent the value of a color. It is used by `wx.Image.HSVtoRGB` and
222 `wx.Image.RGBtoHSV`, which +converts between HSV color space and RGB
224 class wxImage_HSVValue
228 wxImage_HSVValue(double h=0.0, double s=0.0, double v=0.0),
236 class wxImage : public wxObject {
238 %typemap(out) wxImage*; // turn off this typemap
241 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
242 "Loads an image from a file.",
244 :param name: Name of the file from which to load the image.
246 :param type: May be one of the following:
248 ==================== =======================================
249 wx.BITMAP_TYPE_BMP Load a Windows bitmap file.
250 wx.BITMAP_TYPE_GIF Load a GIF bitmap file.
251 wx.BITMAP_TYPE_JPEG Load a JPEG bitmap file.
252 wx.BITMAP_TYPE_PNG Load a PNG bitmap file.
253 wx.BITMAP_TYPE_PCX Load a PCX bitmap file.
254 wx.BITMAP_TYPE_PNM Load a PNM bitmap file.
255 wx.BITMAP_TYPE_TIF Load a TIFF bitmap file.
256 wx.BITMAP_TYPE_XPM Load a XPM bitmap file.
257 wx.BITMAP_TYPE_ICO Load a Windows icon file (ICO).
258 wx.BITMAP_TYPE_CUR Load a Windows cursor file (CUR).
259 wx.BITMAP_TYPE_ANI Load a Windows animated cursor file (ANI).
260 wx.BITMAP_TYPE_ANY Will try to autodetect the format.
261 ==================== =======================================
263 :param index: Index of the image to load in the case that the
264 image file contains multiple images. This is only used by GIF,
265 ICO and TIFF handlers. The default value (-1) means to choose
266 the default image and is interpreted as the first image (the
267 one with index=0) by the GIF and TIFF handler and as the
268 largest and most colourful one by the ICO handler.
270 :see: `wx.ImageFromMime`, `wx.ImageFromStream`, `wx.ImageFromStreamMime`,
271 `wx.EmptyImage`, `wx.ImageFromBitmap`, `wx.ImageFromData`,
272 `wx.ImageFromDataWithAlpha`
277 // Alternate constructors
279 wxImage(const wxString& name, const wxString& mimetype, int index = -1),
280 "Loads an image from a file, using a MIME type string (such as
281 'image/jpeg') to specify image type.", "
287 wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1),
288 "Loads an image from an input stream, or any readable Python file-like
295 wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ),
296 "Loads an image from an input stream, or any readable Python file-like
297 object, specifying the image format with a MIME type string.", "
300 ImageFromStreamMime);
305 "Construct an empty image of a given size, optionally setting all
309 wxImage(int width=0, int height=0, bool clear = true))
311 if (width > 0 && height > 0)
312 return new wxImage(width, height, clear);
318 MustHaveApp(wxImage(const wxBitmap &bitmap));
322 "Construct an Image from a `wx.Bitmap`.", "
325 wxImage(const wxBitmap &bitmap))
327 return new wxImage(bitmap.ConvertToImage());
332 "Construct an Image from a buffer of RGB bytes. Accepts either a
333 string or a buffer object holding the data and the length of the data
334 must be width*height*3.", "
337 wxImage(int width, int height, buffer data, int DATASIZE))
339 if (DATASIZE != width*height*3) {
340 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
344 // Copy the source data so the wxImage can clean it up later
345 buffer copy = (buffer)malloc(DATASIZE);
347 wxPyBLOCK_THREADS(PyErr_NoMemory());
350 memcpy(copy, data, DATASIZE);
351 return new wxImage(width, height, copy, false);
356 ImageFromDataWithAlpha,
357 "Construct an Image from a buffer of RGB bytes with an Alpha channel.
358 Accepts either a string or a buffer object holding the data and the
359 length of the data must be width*height*3 bytes, and the length of the
360 alpha data must be width*height bytes.", "
363 wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE))
365 if (DATASIZE != width*height*3) {
366 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
369 if (ALPHASIZE != width*height) {
370 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
374 // Copy the source data so the wxImage can clean it up later
375 buffer dcopy = (buffer)malloc(DATASIZE);
377 wxPyBLOCK_THREADS(PyErr_NoMemory());
380 memcpy(dcopy, data, DATASIZE);
382 buffer acopy = (buffer)malloc(ALPHASIZE);
384 wxPyBLOCK_THREADS(PyErr_NoMemory());
387 memcpy(acopy, alpha, ALPHASIZE);
389 return new wxImage(width, height, dcopy, acopy, false);
393 // TODO: wxImage( char** xpmData );
395 // Turn it back on again
396 %typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); }
400 void , Create( int width, int height, bool clear=true ),
401 "Creates a fresh image. If clear is ``True``, the new image will be
402 initialized to black. Otherwise, the image data will be uninitialized.", "");
406 "Destroys the image data.", "");
410 wxImage , Scale( int width, int height ),
411 "Returns a scaled version of the image. This is also useful for scaling
412 bitmaps in general as the only other way to scale bitmaps is to blit a
413 `wx.MemoryDC` into another `wx.MemoryDC`.", "
418 wxImage , ShrinkBy( int xFactor , int yFactor ) const ,
419 "Return a version of the image scaled smaller by the given factors.", "");
422 wxImage& , Rescale(int width, int height),
423 "Changes the size of the image in-place by scaling it: after a call to
424 this function, the image will have the given width and height.
426 Returns the (modified) image itself.", "
431 // resizes the image in place
433 wxImage& , Resize( const wxSize& size, const wxPoint& pos,
434 int r = -1, int g = -1, int b = -1 ),
435 "Changes the size of the image in-place without scaling it, by adding
436 either a border with the given colour or cropping as necessary. The
437 image is pasted into a new image with the given size and background
438 colour at the position pos relative to the upper left of the new
439 image. If red = green = blue = -1 then use either the current mask
440 colour if set or find, use, and set a suitable mask colour for any
443 Returns the (modified) image itself.", "
449 void , SetRGB( int x, int y, byte r, byte g, byte b ),
450 "Sets the pixel at the given coordinate. This routine performs
451 bounds-checks for the coordinate so it can be considered a safe way to
452 manipulate the data, but in some cases this might be too slow so that
453 the data will have to be set directly. In that case you will have to
454 get access to the image data using the `GetData` method.", "");
458 void, SetRGB( const wxRect& rect,
459 byte r, byte g, byte b ),
460 "Sets the colour of the pixels within the given rectangle. This routine
461 performs bounds-checks for the rectangle so it can be considered a
462 safe way to manipulate the data.", "",
466 byte , GetRed( int x, int y ),
467 "Returns the red intensity at the given coordinate.", "");
470 byte , GetGreen( int x, int y ),
471 "Returns the green intensity at the given coordinate.", "");
474 byte , GetBlue( int x, int y ),
475 "Returns the blue intensity at the given coordinate.", "");
479 void , SetAlpha(int x, int y, byte alpha),
480 "Sets the alpha value for the given pixel. This function should only be
481 called if the image has alpha channel data, use `HasAlpha` to check
485 byte , GetAlpha(int x, int y),
486 "Returns the alpha value for the given pixel. This function may only be
487 called for the images with alpha channel, use `HasAlpha` to check for
490 The returned value is the *opacity* of the image, i.e. the value of 0
491 corresponds to the fully transparent pixels while the value of 255 to
492 the fully opaque pixels.", "");
496 "Returns true if this image has alpha channel, false otherwise.", "
498 :see: `GetAlpha`, `SetAlpha`");
503 "Initializes the image alpha channel data. It is an error to call it if
504 the image already has alpha data. If it doesn't, alpha data will be by
505 default initialized to all pixels being fully opaque. But if the image
506 has a a mask colour, all mask pixels will be completely transparent.", "");
510 bool , IsTransparent(int x, int y,
511 byte threshold = wxIMAGE_ALPHA_THRESHOLD) const,
512 "Returns ``True`` if this pixel is masked or has an alpha value less
513 than the spcified threshold.", "");
516 // find first colour that is not used in the image and has higher
517 // RGB values than <startR,startG,startB>
519 bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
520 byte startR = 0, byte startG = 0, byte startB = 0 ) const,
521 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
522 "Find first colour that is not used in the image and has higher RGB
523 values than startR, startG, startB. Returns a tuple consisting of a
524 success flag and rgb values.", "");
528 bool , ConvertAlphaToMask(byte threshold = wxIMAGE_ALPHA_THRESHOLD),
529 "If the image has alpha channel, this method converts it to mask. All
530 pixels with alpha value less than ``threshold`` are replaced with the
531 mask colour and the alpha channel is removed. The mask colour is
532 chosen automatically using `FindFirstUnusedColour`.
534 If the image image doesn't have alpha channel, ConvertAlphaToMask does
539 bool , ConvertColourToAlpha( byte r, byte g, byte b ),
540 "This method converts an image where the original alpha information is
541 only available as a shades of a colour (actually shades of grey)
542 typically when you draw anti-aliased text into a bitmap. The DC
543 drawing routines draw grey values on the black background although
544 they actually mean to draw white with differnt alpha values. This
545 method reverses it, assuming a black (!) background and white text.
546 The method will then fill up the whole image with the colour given.", "");
551 bool , SetMaskFromImage(const wxImage & mask,
552 byte mr, byte mg, byte mb),
553 "Sets the image's mask so that the pixels that have RGB value of
554 ``(mr,mg,mb)`` in ``mask`` will be masked in this image. This is done
555 by first finding an unused colour in the image, setting this colour as
556 the mask colour and then using this colour to draw all pixels in the
557 image who corresponding pixel in mask has given RGB value.
559 Returns ``False`` if ``mask`` does not have same dimensions as the
560 image or if there is no unused colour left. Returns ``True`` if the
561 mask was successfully applied.
563 Note that this method involves computing the histogram, which is
564 computationally intensive operation.", "");
567 // void DoFloodFill (wxCoord x, wxCoord y,
568 // const wxBrush & fillBrush,
569 // const wxColour& testColour,
570 // int style = wxFLOOD_SURFACE,
571 // int LogicalFunction = wxCOPY /* currently unused */ ) ;
574 static bool , CanRead( const wxString& filename ),
575 "Returns True if the image handlers can read this file.", "");
578 static int , GetImageCount( const wxString& filename, long type = wxBITMAP_TYPE_ANY ),
579 "If the image file contains more than one image and the image handler
580 is capable of retrieving these individually, this function will return
581 the number of available images.", "");
585 bool , LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
586 "Loads an image from a file. If no handler type is provided, the
587 library will try to autodetect the format.", "");
590 bool , LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ),
591 "Loads an image from a file, specifying the image type with a MIME type
597 bool , SaveFile( const wxString& name, int type ),
598 "Saves an image in the named file.", "");
602 bool , SaveFile( const wxString& name, const wxString& mimetype ),
603 "Saves an image in the named file.", "",
608 static bool , CanRead( wxInputStream& stream ),
609 "Returns True if the image handlers can read an image file from the
610 data currently on the input stream, or a readable Python file-like
616 bool , LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
617 "Loads an image from an input stream or a readable Python file-like
618 object. If no handler type is provided, the library will try to
619 autodetect the format.", "",
624 bool , LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ),
625 "Loads an image from an input stream or a readable Python file-like
626 object, using a MIME type string to specify the image file format.", "",
632 "Returns true if image data is present.", "");
636 "Gets the width of the image in pixels.", "");
640 "Gets the height of the image in pixels.", "");
645 "Returns the size of the image in pixels.", "");
647 wxSize size(self->GetWidth(), self->GetHeight());
654 wxImage , GetSubImage(const wxRect& rect),
655 "Returns a sub image of the current one as long as the rect belongs
656 entirely to the image.", "");
660 wxImage , Size( const wxSize& size, const wxPoint& pos,
661 int r = -1, int g = -1, int b = -1 ) const,
662 "Returns a resized version of this image without scaling it by adding
663 either a border with the given colour or cropping as necessary. The
664 image is pasted into a new image with the given size and background
665 colour at the position ``pos`` relative to the upper left of the new
666 image. If red = green = blue = -1 then use either the current mask
667 colour if set or find, use, and set a suitable mask colour for any
668 newly exposed areas.", "
675 "Returns an identical copy of the image.", "");
678 void , Paste( const wxImage &image, int x, int y ),
679 "Pastes ``image`` into this instance and takes care of the mask colour
680 and any out of bounds problems.", "");
683 //unsigned char *GetData();
684 //void SetData( unsigned char *data );
688 "Returns a string containing a copy of the RGB bytes of the image.", "");
691 buffer data = self->GetData();
692 int len = self->GetWidth() * self->GetHeight() * 3;
694 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
698 "Resets the Image's RGB data from a buffer of RGB bytes. Accepts
699 either a string or a buffer object holding the data and the length of
700 the data must be width*height*3.", "");
701 void SetData(buffer data, int DATASIZE)
703 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
704 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
707 buffer copy = (buffer)malloc(DATASIZE);
709 wxPyBLOCK_THREADS(PyErr_NoMemory());
712 memcpy(copy, data, DATASIZE);
713 self->SetData(copy, false);
714 // wxImage takes ownership of copy...
718 DocStr(GetDataBuffer,
719 "Returns a writable Python buffer object that is pointing at the RGB
720 image data buffer inside the wx.Image. You need to ensure that you do
721 not use this buffer object after the image has been destroyed.", "");
722 PyObject* GetDataBuffer()
724 buffer data = self->GetData();
725 int len = self->GetWidth() * self->GetHeight() * 3;
727 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
731 DocStr(SetDataBuffer,
732 "Sets the internal image data pointer to point at a Python buffer
733 object. This can save making an extra copy of the data but you must
734 ensure that the buffer object lives longer than the wx.Image does.", "");
735 void SetDataBuffer(buffer data, int DATASIZE)
737 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
738 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
741 self->SetData(data, true);
747 "Returns a string containing a copy of the alpha bytes of the image.", "");
748 PyObject* GetAlphaData() {
749 buffer data = self->GetAlpha();
753 int len = self->GetWidth() * self->GetHeight();
755 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
761 "Resets the Image's alpha data from a buffer of bytes. Accepts either
762 a string or a buffer object holding the data and the length of the
763 data must be width*height.", "");
764 void SetAlphaData(buffer alpha, int ALPHASIZE)
766 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
767 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
770 buffer acopy = (buffer)malloc(ALPHASIZE);
772 wxPyBLOCK_THREADS(PyErr_NoMemory());
775 memcpy(acopy, alpha, ALPHASIZE);
776 self->SetAlpha(acopy, false);
777 // wxImage takes ownership of acopy...
782 DocStr(GetDataBuffer,
783 "Returns a writable Python buffer object that is pointing at the Alpha
784 data buffer inside the wx.Image. You need to ensure that you do not
785 use this buffer object after the image has been destroyed.", "");
786 PyObject* GetAlphaBuffer()
788 buffer data = self->GetAlpha();
789 int len = self->GetWidth() * self->GetHeight();
791 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
796 DocStr(SetDataBuffer,
797 "Sets the internal image alpha pointer to point at a Python buffer
798 object. This can save making an extra copy of the data but you must
799 ensure that the buffer object lives as long as the wx.Image does.", "");
800 void SetAlphaBuffer(buffer alpha, int ALPHASIZE)
802 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
803 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
806 self->SetAlpha(alpha, true);
813 void , SetMaskColour( byte r, byte g, byte b ),
814 "Sets the mask colour for this image (and tells the image to use the
819 /*bool*/ void , GetOrFindMaskColour( byte *OUTPUT,
821 byte *OUTPUT ) const,
822 "GetOrFindMaskColour() -> (r,g,b)",
823 "Get the current mask colour or find a suitable colour.", "");
828 "Gets the red component of the mask colour.", "");
831 byte , GetMaskGreen(),
832 "Gets the green component of the mask colour.", "");
835 byte , GetMaskBlue(),
836 "Gets the blue component of the mask colour.", "");
839 void , SetMask( bool mask = true ),
840 "Specifies whether there is a mask or not. The area of the mask is
841 determined by the current mask colour.", "");
845 "Returns ``True`` if there is a mask active, ``False`` otherwise.", "");
849 wxImage , Rotate(double angle, const wxPoint & centre_of_rotation,
850 bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ,
851 "Rotates the image about the given point, by ``angle`` radians. Passing
852 ``True`` to ``interpolating`` results in better image quality, but is
853 slower. If the image has a mask, then the mask colour is used for the
854 uncovered pixels in the rotated image background. Otherwise, black
855 will be used as the fill colour.
857 Returns the rotated image, leaving this image intact.", "");
860 wxImage , Rotate90( bool clockwise = true ) ,
861 "Returns a copy of the image rotated 90 degrees in the direction
862 indicated by ``clockwise``.", "");
865 wxImage , Mirror( bool horizontally = true ) ,
866 "Returns a mirrored copy of the image. The parameter ``horizontally``
867 indicates the orientation.", "");
871 void , Replace( byte r1, byte g1, byte b1,
872 byte r2, byte g2, byte b2 ),
873 "Replaces the colour specified by ``(r1,g1,b1)`` by the colour
874 ``(r2,g2,b2)``.", "");
877 wxImage , ConvertToGreyscale( double lr = 0.299,
879 double lb = 0.114 ) const,
880 "Convert to greyscale image. Uses the luminance component (Y) of the
881 image. The luma value (YUV) is calculated using (R * lr) + (G * lg) + (B * lb),
882 defaults to ITU-T BT.601", "");
886 wxImage , ConvertToMono( byte r, byte g, byte b ) const,
887 "Returns monochromatic version of the image. The returned image has
888 white colour where the original has ``(r,g,b)`` colour and black
889 colour everywhere else.", "");
893 void , SetOption(const wxString& name, const wxString& value),
894 "Sets an image handler defined option. For example, when saving as a
895 JPEG file, the option ``wx.IMAGE_OPTION_QUALITY`` is used, which is a
896 number between 0 and 100 (0 is terrible, 100 is very good).", "
898 ================================= ===
899 wx.IMAGE_OPTION_BMP_FORMAT
900 wx.IMAGE_OPTION_CUR_HOTSPOT_X
901 wx.IMAGE_OPTION_CUR_HOTSPOT_Y
902 wx.IMAGE_OPTION_RESOLUTION
903 wx.IMAGE_OPTION_RESOLUTIONX
904 wx.IMAGE_OPTION_RESOLUTIONY
905 wx.IMAGE_OPTION_RESOLUTIONUNIT
906 wx.IMAGE_OPTION_QUALITY
907 wx.IMAGE_OPTION_BITSPERSAMPLE
908 wx.IMAGE_OPTION_SAMPLESPERPIXEL
909 wx.IMAGE_OPTION_COMPRESSION
910 wx.IMAGE_OPTION_IMAGEDESCRIPTOR
911 wx.IMAGE_OPTION_PNG_FORMAT
912 wx.IMAGE_OPTION_PNG_BITDEPTH
913 ================================= ===
915 :see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOptionInt`");
918 void, SetOption(const wxString& name, int value),
919 "Sets an image option as an integer.", "
921 :see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOption`",
925 wxString , GetOption(const wxString& name) const,
926 "Gets the value of an image handler option.", "
928 :see: `HasOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
931 int , GetOptionInt(const wxString& name) const,
932 "Gets the value of an image handler option as an integer. If the given
933 option is not present, the function returns 0.", "
935 :see: `HasOption`, `GetOption`, `SetOptionInt`, `SetOption`");
938 bool , HasOption(const wxString& name) const,
939 "Returns true if the given option is present.", "
941 :see: `GetOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
944 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
945 unsigned long ComputeHistogram( wxImageHistogram& h );
947 static void AddHandler( wxImageHandler *handler );
948 static void InsertHandler( wxImageHandler *handler );
949 static bool RemoveHandler( const wxString& name );
952 static wxString , GetImageExtWildcard(),
953 "Iterates all registered wxImageHandler objects, and returns a string
954 containing file extension masks suitable for passing to file open/save
959 MustHaveApp(ConvertToBitmap);
960 MustHaveApp(ConvertToMonoBitmap);
963 wxBitmap ConvertToBitmap(int depth=-1) {
964 wxBitmap bitmap(*self, depth);
968 wxBitmap ConvertToMonoBitmap( byte red,
971 wxImage mono = self->ConvertToMono( red, green, blue );
972 wxBitmap bitmap( mono, 1 );
979 void , RotateHue(double angle),
980 "Rotates the hue of each pixel of the image. Hue is a double in the
981 range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees", "");
984 static wxImage_HSVValue , RGBtoHSV(wxImage_RGBValue rgb),
985 "Converts a color in RGB color space to HSV color space.", "");
988 static wxImage_RGBValue , HSVtoRGB(wxImage_HSVValue hsv),
989 "Converts a color in HSV color space to RGB color space.", "");
992 %pythoncode { def __nonzero__(self): return self.Ok() }
997 ///void wxInitAllImageHandlers();
1000 def InitAllImageHandlers():
1002 The former functionality of InitAllImageHanders is now done internal to
1003 the _core_ extension module and so this function has become a simple NOP.
1010 // See also wxPy_ReinitStockObjects in helpers.cpp
1012 const wxImage wxNullImage;
1015 //---------------------------------------------------------------------------
1017 MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME);
1018 MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
1019 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
1020 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
1021 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
1022 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX);
1023 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY);
1024 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
1025 MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY);
1029 wxIMAGE_RESOLUTION_INCHES = 1,
1030 wxIMAGE_RESOLUTION_CM = 2
1034 MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE);
1035 MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL);
1036 MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION);
1037 MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR);
1039 MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT);
1040 MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH);
1044 wxPNG_TYPE_COLOUR = 0,
1045 wxPNG_TYPE_GREY = 2,
1046 wxPNG_TYPE_GREY_RED = 3
1051 wxBMP_24BPP = 24, // default, do not need to set
1052 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
1053 wxBMP_8BPP = 8, // 8bpp, quantized colors
1054 wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
1055 wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
1056 wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
1057 wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
1058 wxBMP_4BPP = 4, // 4bpp, quantized colors
1059 wxBMP_1BPP = 1, // 1bpp, quantized "colors"
1060 wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
1064 DocStr(wxBMPHandler,
1065 "A `wx.ImageHandler` for \*.bmp bitmap files.", "");
1066 class wxBMPHandler : public wxImageHandler {
1071 DocStr(wxICOHandler,
1072 "A `wx.ImageHandler` for \*.ico icon files.", "");
1073 class wxICOHandler : public wxBMPHandler {
1078 DocStr(wxCURHandler,
1079 "A `wx.ImageHandler` for \*.cur cursor files.", "");
1080 class wxCURHandler : public wxICOHandler {
1085 DocStr(wxANIHandler,
1086 "A `wx.ImageHandler` for \*.ani animated cursor files.", "");
1087 class wxANIHandler : public wxCURHandler {
1093 //---------------------------------------------------------------------------
1095 DocStr(wxPNGHandler,
1096 "A `wx.ImageHandler` for PNG image files.", "");
1097 class wxPNGHandler : public wxImageHandler {
1103 DocStr(wxGIFHandler,
1104 "A `wx.ImageHandler` for GIF image files.", "");
1105 class wxGIFHandler : public wxImageHandler {
1111 DocStr(wxPCXHandler,
1112 "A `wx.ImageHandler` for PCX imager files.", "");
1113 class wxPCXHandler : public wxImageHandler {
1119 DocStr(wxJPEGHandler,
1120 "A `wx.ImageHandler` for JPEG/JPG image files.", "");
1121 class wxJPEGHandler : public wxImageHandler {
1127 DocStr(wxPNMHandler,
1128 "A `wx.ImageHandler` for PNM image files.", "");
1129 class wxPNMHandler : public wxImageHandler {
1134 DocStr(wxXPMHandler,
1135 "A `wx.ImageHandler` for XPM image.", "");
1136 class wxXPMHandler : public wxImageHandler {
1141 DocStr(wxTIFFHandler,
1142 "A `wx.ImageHandler` for TIFF image files.", "");
1143 class wxTIFFHandler : public wxImageHandler {
1150 DocStr(wxIFFHandler,
1151 "A `wx.ImageHandler` for IFF image files.", "");
1152 class wxIFFHandler : public wxImageHandler {
1158 //---------------------------------------------------------------------------
1161 #include <wx/quantize.h>
1165 wxQUANTIZE_INCLUDE_WINDOWS_COLOURS,
1166 // wxQUANTIZE_RETURN_8BIT_DATA,
1167 wxQUANTIZE_FILL_DESTINATION_IMAGE
1172 "Performs quantization, or colour reduction, on a wxImage.", "");
1174 class wxQuantize /*: public wxObject */
1181 "Reduce the colours in the source image and put the result into the
1182 destination image, setting the palette in the destination if
1183 needed. Both images may be the same, to overwrite the source image.", "
1184 :todo: Create a version that returns the wx.Palette used.");
1186 static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
1187 int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE)
1189 return wxQuantize::Quantize(src, dest,
1192 NULL, // eightBitData
1199 //---------------------------------------------------------------------------