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