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 //---------------------------------------------------------------------------
62 class wxImageHistogram /* : public wxImageHistogramBase */
67 DocStr(MakeKey, "Get the key in the histogram for the given RGB values", "");
68 static unsigned long MakeKey(byte r,
73 bool, FindFirstUnusedColour(byte *OUTPUT,
78 byte startB = 0 ) const,
79 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
80 "Find first colour that is not used in the image and has higher RGB
81 values than startR, startG, startB. Returns a tuple consisting of a
82 success flag and rgb values.", "");
86 "Returns the pixel count for the given key. Use `MakeKey` to create a
87 key value from a RGB tripple.", "");
88 unsigned long GetCount(unsigned long key) {
89 wxImageHistogramEntry e = (*self)[key];
94 "Returns the pixel count for the given RGB values.", "");
95 unsigned long GetCountRGB(byte r,
98 unsigned long key = wxImageHistogram::MakeKey(r, g, b);
99 wxImageHistogramEntry e = (*self)[key];
103 DocStr(GetCountColour,
104 "Returns the pixel count for the given `wx.Colour` value.", "");
105 unsigned long GetCountColour(const wxColour& colour) {
106 unsigned long key = wxImageHistogram::MakeKey(colour.Red(),
109 wxImageHistogramEntry e = (*self)[key];
117 //---------------------------------------------------------------------------
120 typedef unsigned char* buffer;
123 %typemap(in) (buffer data, int DATASIZE)
124 { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; }
126 %typemap(in) (buffer alpha, int ALPHASIZE)
127 { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; }
129 //---------------------------------------------------------------------------
133 "A platform-independent image class. An image can be created from
134 data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a
135 variety of formats. Functions are available to set and get image
136 bits, so it can be used for basic image manipulation.
138 A wx.Image cannot be drawn directly to a `wx.DC`. Instead, a
139 platform-specific `wx.Bitmap` object must be created from it using the
140 `wx.BitmapFromImage` constructor. This bitmap can then be drawn in a
141 device context, using `wx.DC.DrawBitmap`.
143 One colour value of the image may be used as a mask colour which will
144 lead to the automatic creation of a `wx.Mask` object associated to the
147 wx.Image supports alpha channel data, that is in addition to a byte
148 for the red, green and blue colour components for each pixel it also
149 stores a byte representing the pixel opacity. An alpha value of 0
150 corresponds to a transparent pixel (null opacity) while a value of 255
151 means that the pixel is 100% opaque.
153 Unlike RGB data, not all images have an alpha channel and before using
154 `GetAlpha` you should check if this image contains an alpha channel
155 with `HasAlpha`. Note that currently only images loaded from PNG files
156 with transparency information will have an alpha channel.", "");
159 // Pull the nested class out to the top level for SWIG's sake
160 #define wxImage_RGBValue wxImage::RGBValue
161 #define wxImage_HSVValue wxImage::HSVValue
164 class wxImage_RGBValue
167 wxImage_RGBValue(byte r=0, byte g=0, byte b=0);
173 class wxImage_HSVValue
176 wxImage_HSVValue(double h=0.0, double s=0.0, double v=0.0);
183 class wxImage : public wxObject {
185 %typemap(out) wxImage*; // turn off this typemap
188 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
189 "Loads an image from a file.",
191 :param name: Name of the file from which to load the image.
193 :param type: May be one of the following:
195 ==================== =======================================
196 wx.BITMAP_TYPE_BMP Load a Windows bitmap file.
197 wx.BITMAP_TYPE_GIF Load a GIF bitmap file.
198 wx.BITMAP_TYPE_JPEG Load a JPEG bitmap file.
199 wx.BITMAP_TYPE_PNG Load a PNG bitmap file.
200 wx.BITMAP_TYPE_PCX Load a PCX bitmap file.
201 wx.BITMAP_TYPE_PNM Load a PNM bitmap file.
202 wx.BITMAP_TYPE_TIF Load a TIFF bitmap file.
203 wx.BITMAP_TYPE_XPM Load a XPM bitmap file.
204 wx.BITMAP_TYPE_ICO Load a Windows icon file (ICO).
205 wx.BITMAP_TYPE_CUR Load a Windows cursor file (CUR).
206 wx.BITMAP_TYPE_ANI Load a Windows animated cursor file (ANI).
207 wx.BITMAP_TYPE_ANY Will try to autodetect the format.
208 ==================== =======================================
210 :param index: Index of the image to load in the case that the
211 image file contains multiple images. This is only used by GIF,
212 ICO and TIFF handlers. The default value (-1) means to choose
213 the default image and is interpreted as the first image (the
214 one with index=0) by the GIF and TIFF handler and as the
215 largest and most colourful one by the ICO handler.
217 :see: `wx.ImageFromMime`, `wx.ImageFromStream`, `wx.ImageFromStreamMime`,
218 `wx.EmptyImage`, `wx.ImageFromBitmap`, `wx.ImageFromData`,
219 `wx.ImageFromDataWithAlpha`
224 // Alternate constructors
226 wxImage(const wxString& name, const wxString& mimetype, int index = -1),
227 "Loads an image from a file, using a MIME type string (such as
228 'image/jpeg') to specify image type.", "
234 wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1),
235 "Loads an image from an input stream, or any readable Python file-like
242 wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ),
243 "Loads an image from an input stream, or any readable Python file-like
244 object, specifying the image format with a MIME type string.", "
247 ImageFromStreamMime);
252 "Construct an empty image of a given size, optionally setting all
256 wxImage(int width=0, int height=0, bool clear = true))
258 if (width > 0 && height > 0)
259 return new wxImage(width, height, clear);
265 MustHaveApp(wxImage(const wxBitmap &bitmap));
269 "Construct an Image from a `wx.Bitmap`.", "
272 wxImage(const wxBitmap &bitmap))
274 return new wxImage(bitmap.ConvertToImage());
279 "Construct an Image from a buffer of RGB bytes. Accepts either a
280 string or a buffer object holding the data and the length of the data
281 must be width*height*3.", "
284 wxImage(int width, int height, buffer data, int DATASIZE))
286 if (DATASIZE != width*height*3) {
287 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
291 // Copy the source data so the wxImage can clean it up later
292 buffer copy = (buffer)malloc(DATASIZE);
294 wxPyBLOCK_THREADS(PyErr_NoMemory());
297 memcpy(copy, data, DATASIZE);
298 return new wxImage(width, height, copy, false);
303 ImageFromDataWithAlpha,
304 "Construct an Image from a buffer of RGB bytes with an Alpha channel.
305 Accepts either a string or a buffer object holding the data and the
306 length of the data must be width*height*3 bytes, and the length of the
307 alpha data must be width*height bytes.", "
310 wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE))
312 if (DATASIZE != width*height*3) {
313 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
316 if (ALPHASIZE != width*height) {
317 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
321 // Copy the source data so the wxImage can clean it up later
322 buffer dcopy = (buffer)malloc(DATASIZE);
324 wxPyBLOCK_THREADS(PyErr_NoMemory());
327 memcpy(dcopy, data, DATASIZE);
329 buffer acopy = (buffer)malloc(ALPHASIZE);
331 wxPyBLOCK_THREADS(PyErr_NoMemory());
334 memcpy(acopy, alpha, ALPHASIZE);
336 return new wxImage(width, height, dcopy, acopy, false);
340 // TODO: wxImage( char** xpmData );
342 // Turn it back on again
343 %typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); }
347 void , Create( int width, int height, bool clear=true ),
348 "Creates a fresh image. If clear is ``True``, the new image will be
349 initialized to black. Otherwise, the image data will be uninitialized.", "");
353 "Destroys the image data.", "");
357 wxImage , Scale( int width, int height ),
358 "Returns a scaled version of the image. This is also useful for scaling
359 bitmaps in general as the only other way to scale bitmaps is to blit a
360 `wx.MemoryDC` into another `wx.MemoryDC`.", "
365 wxImage , ShrinkBy( int xFactor , int yFactor ) const ,
366 "Return a version of the image scaled smaller by the given factors.", "");
369 wxImage& , Rescale(int width, int height),
370 "Changes the size of the image in-place by scaling it: after a call to
371 this function, the image will have the given width and height.
373 Returns the (modified) image itself.", "
378 // resizes the image in place
380 wxImage& , Resize( const wxSize& size, const wxPoint& pos,
381 int r = -1, int g = -1, int b = -1 ),
382 "Changes the size of the image in-place without scaling it, by adding
383 either a border with the given colour or cropping as necessary. The
384 image is pasted into a new image with the given size and background
385 colour at the position pos relative to the upper left of the new
386 image. If red = green = blue = -1 then use either the current mask
387 colour if set or find, use, and set a suitable mask colour for any
390 Returns the (modified) image itself.", "
396 void , SetRGB( int x, int y, byte r, byte g, byte b ),
397 "Sets the pixel at the given coordinate. This routine performs
398 bounds-checks for the coordinate so it can be considered a safe way to
399 manipulate the data, but in some cases this might be too slow so that
400 the data will have to be set directly. In that case you will have to
401 get access to the image data using the `GetData` method.", "");
405 void, SetRGB( const wxRect& rect,
406 byte r, byte g, byte b ),
407 "Sets the colour of the pixels within the given rectangle. This routine
408 performs bounds-checks for the rectangle so it can be considered a
409 safe way to manipulate the data.", "",
413 byte , GetRed( int x, int y ),
414 "Returns the red intensity at the given coordinate.", "");
417 byte , GetGreen( int x, int y ),
418 "Returns the green intensity at the given coordinate.", "");
421 byte , GetBlue( int x, int y ),
422 "Returns the blue intensity at the given coordinate.", "");
426 void , SetAlpha(int x, int y, byte alpha),
427 "Sets the alpha value for the given pixel. This function should only be
428 called if the image has alpha channel data, use `HasAlpha` to check
432 byte , GetAlpha(int x, int y),
433 "Returns the alpha value for the given pixel. This function may only be
434 called for the images with alpha channel, use `HasAlpha` to check for
437 The returned value is the *opacity* of the image, i.e. the value of 0
438 corresponds to the fully transparent pixels while the value of 255 to
439 the fully opaque pixels.", "");
443 "Returns true if this image has alpha channel, false otherwise.", "
445 :see: `GetAlpha`, `SetAlpha`");
450 "Initializes the image alpha channel data. It is an error to call it if
451 the image already has alpha data. If it doesn't, alpha data will be by
452 default initialized to all pixels being fully opaque. But if the image
453 has a a mask colour, all mask pixels will be completely transparent.", "");
457 bool , IsTransparent(int x, int y,
458 byte threshold = wxIMAGE_ALPHA_THRESHOLD) const,
459 "Returns ``True`` if this pixel is masked or has an alpha value less
460 than the spcified threshold.", "");
463 // find first colour that is not used in the image and has higher
464 // RGB values than <startR,startG,startB>
466 bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
467 byte startR = 0, byte startG = 0, byte startB = 0 ) const,
468 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
469 "Find first colour that is not used in the image and has higher RGB
470 values than startR, startG, startB. Returns a tuple consisting of a
471 success flag and rgb values.", "");
475 bool , ConvertAlphaToMask(byte threshold = wxIMAGE_ALPHA_THRESHOLD),
476 "If the image has alpha channel, this method converts it to mask. All
477 pixels with alpha value less than ``threshold`` are replaced with the
478 mask colour and the alpha channel is removed. The mask colour is
479 chosen automatically using `FindFirstUnusedColour`.
481 If the image image doesn't have alpha channel, ConvertAlphaToMask does
486 bool , ConvertColourToAlpha( byte r, byte g, byte b ),
487 "This method converts an image where the original alpha information is
488 only available as a shades of a colour (actually shades of grey)
489 typically when you draw anti-aliased text into a bitmap. The DC
490 drawing routines draw grey values on the black background although
491 they actually mean to draw white with differnt alpha values. This
492 method reverses it, assuming a black (!) background and white text.
493 The method will then fill up the whole image with the colour given.", "");
498 bool , SetMaskFromImage(const wxImage & mask,
499 byte mr, byte mg, byte mb),
500 "Sets the image's mask so that the pixels that have RGB value of
501 ``(mr,mg,mb)`` in ``mask`` will be masked in this image. This is done
502 by first finding an unused colour in the image, setting this colour as
503 the mask colour and then using this colour to draw all pixels in the
504 image who corresponding pixel in mask has given RGB value.
506 Returns ``False`` if ``mask`` does not have same dimensions as the
507 image or if there is no unused colour left. Returns ``True`` if the
508 mask was successfully applied.
510 Note that this method involves computing the histogram, which is
511 computationally intensive operation.", "");
514 // void DoFloodFill (wxCoord x, wxCoord y,
515 // const wxBrush & fillBrush,
516 // const wxColour& testColour,
517 // int style = wxFLOOD_SURFACE,
518 // int LogicalFunction = wxCOPY /* currently unused */ ) ;
521 static bool , CanRead( const wxString& filename ),
522 "Returns True if the image handlers can read this file.", "");
525 static int , GetImageCount( const wxString& filename, long type = wxBITMAP_TYPE_ANY ),
526 "If the image file contains more than one image and the image handler
527 is capable of retrieving these individually, this function will return
528 the number of available images.", "");
532 bool , LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
533 "Loads an image from a file. If no handler type is provided, the
534 library will try to autodetect the format.", "");
537 bool , LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ),
538 "Loads an image from a file, specifying the image type with a MIME type
544 bool , SaveFile( const wxString& name, int type ),
545 "Saves an image in the named file.", "");
549 bool , SaveFile( const wxString& name, const wxString& mimetype ),
550 "Saves an image in the named file.", "",
555 static bool , CanRead( wxInputStream& stream ),
556 "Returns True if the image handlers can read an image file from the
557 data currently on the input stream, or a readable Python file-like
563 bool , LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ),
564 "Loads an image from an input stream or a readable Python file-like
565 object. If no handler type is provided, the library will try to
566 autodetect the format.", "",
571 bool , LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ),
572 "Loads an image from an input stream or a readable Python file-like
573 object, using a MIME type string to specify the image file format.", "",
579 "Returns true if image data is present.", "");
583 "Gets the width of the image in pixels.", "");
587 "Gets the height of the image in pixels.", "");
592 "Returns the size of the image in pixels.", "");
594 wxSize size(self->GetWidth(), self->GetHeight());
601 wxImage , GetSubImage(const wxRect& rect),
602 "Returns a sub image of the current one as long as the rect belongs
603 entirely to the image.", "");
607 wxImage , Size( const wxSize& size, const wxPoint& pos,
608 int r = -1, int g = -1, int b = -1 ) const,
609 "Returns a resized version of this image without scaling it by adding
610 either a border with the given colour or cropping as necessary. The
611 image is pasted into a new image with the given size and background
612 colour at the position ``pos`` relative to the upper left of the new
613 image. If red = green = blue = -1 then use either the current mask
614 colour if set or find, use, and set a suitable mask colour for any
615 newly exposed areas.", "
622 "Returns an identical copy of the image.", "");
625 void , Paste( const wxImage &image, int x, int y ),
626 "Pastes ``image`` into this instance and takes care of the mask colour
627 and any out of bounds problems.", "");
630 //unsigned char *GetData();
631 //void SetData( unsigned char *data );
635 "Returns a string containing a copy of the RGB bytes of the image.", "");
638 buffer data = self->GetData();
639 int len = self->GetWidth() * self->GetHeight() * 3;
641 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
645 "Resets the Image's RGB data from a buffer of RGB bytes. Accepts
646 either a string or a buffer object holding the data and the length of
647 the data must be width*height*3.", "");
648 void SetData(buffer data, int DATASIZE)
650 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
651 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
654 buffer copy = (buffer)malloc(DATASIZE);
656 wxPyBLOCK_THREADS(PyErr_NoMemory());
659 memcpy(copy, data, DATASIZE);
660 self->SetData(copy, false);
661 // wxImage takes ownership of copy...
665 DocStr(GetDataBuffer,
666 "Returns a writable Python buffer object that is pointing at the RGB
667 image data buffer inside the wx.Image. You need to ensure that you do
668 not use this buffer object after the image has been destroyed.", "");
669 PyObject* GetDataBuffer()
671 buffer data = self->GetData();
672 int len = self->GetWidth() * self->GetHeight() * 3;
674 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
678 DocStr(SetDataBuffer,
679 "Sets the internal image data pointer to point at a Python buffer
680 object. This can save making an extra copy of the data but you must
681 ensure that the buffer object lives longer than the wx.Image does.", "");
682 void SetDataBuffer(buffer data, int DATASIZE)
684 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
685 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
688 self->SetData(data, true);
694 "Returns a string containing a copy of the alpha bytes of the image.", "");
695 PyObject* GetAlphaData() {
696 buffer data = self->GetAlpha();
700 int len = self->GetWidth() * self->GetHeight();
702 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
708 "Resets the Image's alpha data from a buffer of bytes. Accepts either
709 a string or a buffer object holding the data and the length of the
710 data must be width*height.", "");
711 void SetAlphaData(buffer alpha, int ALPHASIZE)
713 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
714 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
717 buffer acopy = (buffer)malloc(ALPHASIZE);
719 wxPyBLOCK_THREADS(PyErr_NoMemory());
722 memcpy(acopy, alpha, ALPHASIZE);
723 self->SetAlpha(acopy, false);
724 // wxImage takes ownership of acopy...
729 DocStr(GetDataBuffer,
730 "Returns a writable Python buffer object that is pointing at the Alpha
731 data buffer inside the wx.Image. You need to ensure that you do not
732 use this buffer object after the image has been destroyed.", "");
733 PyObject* GetAlphaBuffer()
735 buffer data = self->GetAlpha();
736 int len = self->GetWidth() * self->GetHeight();
738 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
743 DocStr(SetDataBuffer,
744 "Sets the internal image alpha pointer to point at a Python buffer
745 object. This can save making an extra copy of the data but you must
746 ensure that the buffer object lives as long as the wx.Image does.", "");
747 void SetAlphaBuffer(buffer alpha, int ALPHASIZE)
749 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
750 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
753 self->SetAlpha(alpha, true);
760 void , SetMaskColour( byte r, byte g, byte b ),
761 "Sets the mask colour for this image (and tells the image to use the
766 /*bool*/ void , GetOrFindMaskColour( byte *OUTPUT,
768 byte *OUTPUT ) const,
769 "GetOrFindMaskColour() -> (r,g,b)",
770 "Get the current mask colour or find a suitable colour.", "");
775 "Gets the red component of the mask colour.", "");
778 byte , GetMaskGreen(),
779 "Gets the green component of the mask colour.", "");
782 byte , GetMaskBlue(),
783 "Gets the blue component of the mask colour.", "");
786 void , SetMask( bool mask = true ),
787 "Specifies whether there is a mask or not. The area of the mask is
788 determined by the current mask colour.", "");
792 "Returns ``True`` if there is a mask active, ``False`` otherwise.", "");
796 wxImage , Rotate(double angle, const wxPoint & centre_of_rotation,
797 bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ,
798 "Rotates the image about the given point, by ``angle`` radians. Passing
799 ``True`` to ``interpolating`` results in better image quality, but is
800 slower. If the image has a mask, then the mask colour is used for the
801 uncovered pixels in the rotated image background. Otherwise, black
802 will be used as the fill colour.
804 Returns the rotated image, leaving this image intact.", "");
807 wxImage , Rotate90( bool clockwise = true ) ,
808 "Returns a copy of the image rotated 90 degrees in the direction
809 indicated by ``clockwise``.", "");
812 wxImage , Mirror( bool horizontally = true ) ,
813 "Returns a mirrored copy of the image. The parameter ``horizontally``
814 indicates the orientation.", "");
818 void , Replace( byte r1, byte g1, byte b1,
819 byte r2, byte g2, byte b2 ),
820 "Replaces the colour specified by ``(r1,g1,b1)`` by the colour
821 ``(r2,g2,b2)``.", "");
825 wxImage , ConvertToMono( byte r, byte g, byte b ) const,
826 "Returns monochromatic version of the image. The returned image has
827 white colour where the original has ``(r,g,b)`` colour and black
828 colour everywhere else.", "");
832 void , SetOption(const wxString& name, const wxString& value),
833 "Sets an image handler defined option. For example, when saving as a
834 JPEG file, the option ``wx.IMAGE_OPTION_QUALITY`` is used, which is a
835 number between 0 and 100 (0 is terrible, 100 is very good).", "
837 ================================= ===
838 wx.IMAGE_OPTION_BMP_FORMAT
839 wx.IMAGE_OPTION_CUR_HOTSPOT_X
840 wx.IMAGE_OPTION_CUR_HOTSPOT_Y
841 wx.IMAGE_OPTION_RESOLUTION
842 wx.IMAGE_OPTION_RESOLUTIONX
843 wx.IMAGE_OPTION_RESOLUTIONY
844 wx.IMAGE_OPTION_RESOLUTIONUNIT
845 wx.IMAGE_OPTION_QUALITY
846 wx.IMAGE_OPTION_BITSPERSAMPLE
847 wx.IMAGE_OPTION_SAMPLESPERPIXEL
848 wx.IMAGE_OPTION_COMPRESSION
849 wx.IMAGE_OPTION_IMAGEDESCRIPTOR
850 wx.IMAGE_OPTION_PNG_FORMAT
851 wx.IMAGE_OPTION_PNG_BITDEPTH
852 ================================= ===
854 :see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOptionInt`");
857 void, SetOption(const wxString& name, int value),
858 "Sets an image option as an integer.", "
860 :see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOption`",
864 wxString , GetOption(const wxString& name) const,
865 "Gets the value of an image handler option.", "
867 :see: `HasOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
870 int , GetOptionInt(const wxString& name) const,
871 "Gets the value of an image handler option as an integer. If the given
872 option is not present, the function returns 0.", "
874 :see: `HasOption`, `GetOption`, `SetOptionInt`, `SetOption`");
877 bool , HasOption(const wxString& name) const,
878 "Returns true if the given option is present.", "
880 :see: `GetOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
883 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
884 unsigned long ComputeHistogram( wxImageHistogram& h );
886 static void AddHandler( wxImageHandler *handler );
887 static void InsertHandler( wxImageHandler *handler );
888 static bool RemoveHandler( const wxString& name );
891 static wxString , GetImageExtWildcard(),
892 "Iterates all registered wxImageHandler objects, and returns a string
893 containing file extension masks suitable for passing to file open/save
898 MustHaveApp(ConvertToBitmap);
899 MustHaveApp(ConvertToMonoBitmap);
902 wxBitmap ConvertToBitmap(int depth=-1) {
903 wxBitmap bitmap(*self, depth);
907 wxBitmap ConvertToMonoBitmap( byte red,
910 wxImage mono = self->ConvertToMono( red, green, blue );
911 wxBitmap bitmap( mono, 1 );
918 void , RotateHue(double angle),
919 "Rotates the hue of each pixel of the image. Hue is a double in the
920 range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees", "");
922 static wxImage_HSVValue RGBtoHSV(wxImage_RGBValue rgb);
923 static wxImage_RGBValue HSVtoRGB(wxImage_HSVValue hsv);
925 %pythoncode { def __nonzero__(self): return self.Ok() }
930 ///void wxInitAllImageHandlers();
933 def InitAllImageHandlers():
935 The former functionality of InitAllImageHanders is now done internal to
936 the _core_ extension module and so this function has become a simple NOP.
943 // See also wxPy_ReinitStockObjects in helpers.cpp
945 const wxImage wxNullImage;
948 //---------------------------------------------------------------------------
950 MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME);
951 MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
952 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
953 MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
954 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
955 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX);
956 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY);
957 MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
958 MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY);
962 wxIMAGE_RESOLUTION_INCHES = 1,
963 wxIMAGE_RESOLUTION_CM = 2
967 MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE);
968 MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL);
969 MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION);
970 MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR);
972 MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT);
973 MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH);
977 wxPNG_TYPE_COLOUR = 0,
979 wxPNG_TYPE_GREY_RED = 3
984 wxBMP_24BPP = 24, // default, do not need to set
985 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
986 wxBMP_8BPP = 8, // 8bpp, quantized colors
987 wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
988 wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
989 wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
990 wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
991 wxBMP_4BPP = 4, // 4bpp, quantized colors
992 wxBMP_1BPP = 1, // 1bpp, quantized "colors"
993 wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
998 "A `wx.ImageHandler` for \*.bmp bitmap files.", "");
999 class wxBMPHandler : public wxImageHandler {
1004 DocStr(wxICOHandler,
1005 "A `wx.ImageHandler` for \*.ico icon files.", "");
1006 class wxICOHandler : public wxBMPHandler {
1011 DocStr(wxCURHandler,
1012 "A `wx.ImageHandler` for \*.cur cursor files.", "");
1013 class wxCURHandler : public wxICOHandler {
1018 DocStr(wxANIHandler,
1019 "A `wx.ImageHandler` for \*.ani animated cursor files.", "");
1020 class wxANIHandler : public wxCURHandler {
1026 //---------------------------------------------------------------------------
1028 DocStr(wxPNGHandler,
1029 "A `wx.ImageHandler` for PNG image files.", "");
1030 class wxPNGHandler : public wxImageHandler {
1036 DocStr(wxGIFHandler,
1037 "A `wx.ImageHandler` for GIF image files.", "");
1038 class wxGIFHandler : public wxImageHandler {
1044 DocStr(wxPCXHandler,
1045 "A `wx.ImageHandler` for PCX imager files.", "");
1046 class wxPCXHandler : public wxImageHandler {
1052 DocStr(wxJPEGHandler,
1053 "A `wx.ImageHandler` for JPEG/JPG image files.", "");
1054 class wxJPEGHandler : public wxImageHandler {
1060 DocStr(wxPNMHandler,
1061 "A `wx.ImageHandler` for PNM image files.", "");
1062 class wxPNMHandler : public wxImageHandler {
1067 DocStr(wxXPMHandler,
1068 "A `wx.ImageHandler` for XPM image.", "");
1069 class wxXPMHandler : public wxImageHandler {
1074 DocStr(wxTIFFHandler,
1075 "A `wx.ImageHandler` for TIFF image files.", "");
1076 class wxTIFFHandler : public wxImageHandler {
1083 DocStr(wxIFFHandler,
1084 "A `wx.ImageHandler` for IFF image files.", "");
1085 class wxIFFHandler : public wxImageHandler {
1091 //---------------------------------------------------------------------------
1094 #include <wx/quantize.h>
1098 wxQUANTIZE_INCLUDE_WINDOWS_COLOURS,
1099 // wxQUANTIZE_RETURN_8BIT_DATA,
1100 wxQUANTIZE_FILL_DESTINATION_IMAGE
1105 "Performs quantization, or colour reduction, on a wxImage.", "");
1107 class wxQuantize /*: public wxObject */
1114 "Reduce the colours in the source image and put the result into the
1115 destination image, setting the palette in the destination if
1116 needed. Both images may be the same, to overwrite the source image.", "
1117 :todo: Create a version that returns the wx.Palette used.");
1119 static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
1120 int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE)
1122 return wxQuantize::Quantize(src, dest,
1125 NULL, // eightBitData
1132 //---------------------------------------------------------------------------