]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_image.i
Apply parts of patch #1719888 to fix compilation on Mac and with
[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
f5263701
RD
30// Constants for wxImage::Scale() for determining the level of quality
31enum
32{
33 wxIMAGE_QUALITY_NORMAL = 0,
34 wxIMAGE_QUALITY_HIGH = 1
35};
36
9cbf6f6e 37//---------------------------------------------------------------------------
d14a1e28 38%newgroup
9cbf6f6e 39
d5a7caf6
RD
40DocStr(wxImageHandler,
41"This is the base class for implementing image file loading/saving, and
42image creation from data. It is used within `wx.Image` and is not
43normally seen by the application.", "");
9416aa89 44class wxImageHandler : public wxObject {
cf694132 45public:
1dec68aa 46 // wxImageHandler(); Abstract Base Class
cf694132
RD
47 wxString GetName();
48 wxString GetExtension();
49 long GetType();
50 wxString GetMimeType();
51
52 //bool LoadFile(wxImage* image, wxInputStream& stream);
53 //bool SaveFile(wxImage* image, wxOutputStream& stream);
b5a5d647 54 //virtual int GetImageCount( wxInputStream& stream );
b5a5d647
RD
55
56 bool CanRead( const wxString& name );
3ad84671
RD
57 %Rename(CanReadStream, bool, CanRead( wxInputStream& stream ));
58
cf694132
RD
59 void SetName(const wxString& name);
60 void SetExtension(const wxString& extension);
61 void SetType(long type);
62 void SetMimeType(const wxString& mimetype);
76b8fa1d
RD
63
64 %property(Extension, GetExtension, SetExtension, doc="See `GetExtension` and `SetExtension`");
65 %property(MimeType, GetMimeType, SetMimeType, doc="See `GetMimeType` and `SetMimeType`");
66 %property(Name, GetName, SetName, doc="See `GetName` and `SetName`");
67 %property(Type, GetType, SetType, doc="See `GetType` and `SetType`");
cf694132
RD
68};
69
cf694132 70
d14a1e28 71//---------------------------------------------------------------------------
cf694132 72
02b800ce
RD
73
74DocStr(wxPyImageHandler,
75"This is the base class for implementing image file loading/saving, and
76image creation from data, all written in Python. To create a custom
77image handler derive a new class from wx.PyImageHandler and provide
78the following methods::
79
80 def DoCanRead(self, stream) --> bool
81 '''Check if this handler can read the image on the stream'''
82
83 def LoadFile(self, image, stream, verbose, index) --> bool
84 '''Load image data from the stream and load it into image.'''
85
86 def SaveFile(self, image, stream, verbose) --> bool
87 '''Save the iamge data in image to the stream using
88 this handler's image file format.'''
89
90 def GetImageCount(self, stream) --> int
91 '''If this image format can hold more than one image,
92 how many does the image on the stream have?'''
93
94To activate your handler create an instance of it and pass it to
95`wx.Image_AddHandler`. Be sure to call `SetName`, `SetType`, and
96`SetExtension` from your constructor.
97", "");
98
99class wxPyImageHandler: public wxImageHandler {
100public:
101 %pythonAppend wxPyImageHandler() "self._SetSelf(self)"
102 wxPyImageHandler();
103 void _SetSelf(PyObject *self);
104};
105
106
107//---------------------------------------------------------------------------
108
109
d14a1e28
RD
110class wxImageHistogram /* : public wxImageHistogramBase */
111{
06c0fba4 112public:
d14a1e28 113 wxImageHistogram();
cf694132 114
d07d2bc9 115 DocStr(MakeKey, "Get the key in the histogram for the given RGB values", "");
4187c382
RD
116 static unsigned long MakeKey(byte r,
117 byte g,
118 byte b);
cf694132 119
dd9f7fea 120 DocDeclAStr(
4187c382
RD
121 bool, FindFirstUnusedColour(byte *OUTPUT,
122 byte *OUTPUT,
123 byte *OUTPUT,
124 byte startR = 1,
125 byte startG = 0,
126 byte startB = 0 ) const,
dd9f7fea 127 "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)",
d07d2bc9
RD
128 "Find first colour that is not used in the image and has higher RGB
129values than startR, startG, startB. Returns a tuple consisting of a
130success flag and rgb values.", "");
41c48dbb
RD
131
132 %extend {
133 DocStr(GetCount,
134 "Returns the pixel count for the given key. Use `MakeKey` to create a
135key value from a RGB tripple.", "");
136 unsigned long GetCount(unsigned long key) {
137 wxImageHistogramEntry e = (*self)[key];
138 return e.value;
139 }
140
141 DocStr(GetCountRGB,
142 "Returns the pixel count for the given RGB values.", "");
4187c382
RD
143 unsigned long GetCountRGB(byte r,
144 byte g,
145 byte b) {
41c48dbb
RD
146 unsigned long key = wxImageHistogram::MakeKey(r, g, b);
147 wxImageHistogramEntry e = (*self)[key];
148 return e.value;
149 }
150
151 DocStr(GetCountColour,
152 "Returns the pixel count for the given `wx.Colour` value.", "");
153 unsigned long GetCountColour(const wxColour& colour) {
154 unsigned long key = wxImageHistogram::MakeKey(colour.Red(),
155 colour.Green(),
156 colour.Blue());
157 wxImageHistogramEntry e = (*self)[key];
158 return e.value;
159 }
160 }
161
9b3d3bc4
RD
162};
163
164
cf694132
RD
165//---------------------------------------------------------------------------
166
4187c382
RD
167DocStr(wxImage,
168"A platform-independent image class. An image can be created from
169data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a
170variety of formats. Functions are available to set and get image
171bits, so it can be used for basic image manipulation.
172
173A wx.Image cannot be drawn directly to a `wx.DC`. Instead, a
174platform-specific `wx.Bitmap` object must be created from it using the
175`wx.BitmapFromImage` constructor. This bitmap can then be drawn in a
176device context, using `wx.DC.DrawBitmap`.
177
178One colour value of the image may be used as a mask colour which will
179lead to the automatic creation of a `wx.Mask` object associated to the
180bitmap object.
181
182wx.Image supports alpha channel data, that is in addition to a byte
183for the red, green and blue colour components for each pixel it also
184stores a byte representing the pixel opacity. An alpha value of 0
185corresponds to a transparent pixel (null opacity) while a value of 255
186means that the pixel is 100% opaque.
187
188Unlike RGB data, not all images have an alpha channel and before using
189`GetAlpha` you should check if this image contains an alpha channel
190with `HasAlpha`. Note that currently only images loaded from PNG files
191with transparency information will have an alpha channel.", "");
192
02b800ce 193
978d3d36
VZ
194%{
195// Pull the nested class out to the top level for SWIG's sake
196#define wxImage_RGBValue wxImage::RGBValue
197#define wxImage_HSVValue wxImage::HSVValue
198%}
02b800ce
RD
199
200DocStr(wxImage_RGBValue,
201"An object that contains values for red, green and blue which represent
202the value of a color. It is used by `wx.Image.HSVtoRGB` and
203`wx.Image.RGBtoHSV`, which converts between HSV color space and RGB
204color space.", "");
978d3d36
VZ
205class wxImage_RGBValue
206{
207public:
02b800ce
RD
208 DocCtorStr(
209 wxImage_RGBValue(byte r=0, byte g=0, byte b=0),
210 "Constructor.", "");
978d3d36
VZ
211 byte red;
212 byte green;
213 byte blue;
214};
02b800ce
RD
215
216
217DocStr(wxImage_HSVValue,
218"An object that contains values for hue, saturation and value which
219represent the value of a color. It is used by `wx.Image.HSVtoRGB` and
220`wx.Image.RGBtoHSV`, which +converts between HSV color space and RGB
221color space.", "");
978d3d36
VZ
222class wxImage_HSVValue
223{
224public:
02b800ce
RD
225 DocCtorStr(
226 wxImage_HSVValue(double h=0.0, double s=0.0, double v=0.0),
227 "Constructor.", "");
978d3d36
VZ
228 double hue;
229 double saturation;
230 double value;
231};
232
233
3ecece7e 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 670 DocDeclStr(
6c2dd16f 671 bool , IsOk(),
4187c382 672 "Returns true if image data is present.", "");
6c2dd16f 673 %pythoncode { Ok = IsOk }
4187c382
RD
674
675 DocDeclStr(
676 int , GetWidth(),
677 "Gets the width of the image in pixels.", "");
678
679 DocDeclStr(
680 int , GetHeight(),
681 "Gets the height of the image in pixels.", "");
682
cf694132 683
ba938c3d 684 %extend {
4187c382
RD
685 DocStr(GetSize,
686 "Returns the size of the image in pixels.", "");
ba938c3d
RD
687 wxSize GetSize() {
688 wxSize size(self->GetWidth(), self->GetHeight());
689 return size;
690 }
691 }
692
4187c382
RD
693
694 DocDeclStr(
695 wxImage , GetSubImage(const wxRect& rect),
696 "Returns a sub image of the current one as long as the rect belongs
697entirely to the image.", "");
698
f5bac082 699
4187c382
RD
700 DocDeclStr(
701 wxImage , Size( const wxSize& size, const wxPoint& pos,
702 int r = -1, int g = -1, int b = -1 ) const,
703 "Returns a resized version of this image without scaling it by adding
704either a border with the given colour or cropping as necessary. The
705image is pasted into a new image with the given size and background
706colour at the position ``pos`` relative to the upper left of the new
707image. If red = green = blue = -1 then use either the current mask
708colour if set or find, use, and set a suitable mask colour for any
709newly exposed areas.", "
710
711:see: `Resize`");
712
713
714 DocDeclStr(
715 wxImage , Copy(),
716 "Returns an identical copy of the image.", "");
717
718 DocDeclStr(
719 void , Paste( const wxImage &image, int x, int y ),
720 "Pastes ``image`` into this instance and takes care of the mask colour
721and any out of bounds problems.", "");
f5bac082 722
9d8bd15f 723
1dc2f865
RD
724 //unsigned char *GetData();
725 //void SetData( unsigned char *data );
726
d14a1e28 727 %extend {
d8194e5d
RD
728 DocStr(GetData,
729 "Returns a string containing a copy of the RGB bytes of the image.", "");
730 PyObject* GetData()
731 {
732 buffer data = self->GetData();
d55d6b3f 733 int len = self->GetWidth() * self->GetHeight() * 3;
d14a1e28
RD
734 PyObject* rv;
735 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len));
736 return rv;
d55d6b3f 737 }
d8194e5d
RD
738 DocStr(SetData,
739 "Resets the Image's RGB data from a buffer of RGB bytes. Accepts
740either a string or a buffer object holding the data and the length of
741the data must be width*height*3.", "");
742 void SetData(buffer data, int DATASIZE)
743 {
744 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
745 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
746 return;
747 }
748 buffer copy = (buffer)malloc(DATASIZE);
749 if (copy == NULL) {
750 wxPyBLOCK_THREADS(PyErr_NoMemory());
751 return;
752 }
753 memcpy(copy, data, DATASIZE);
754 self->SetData(copy, false);
755 // wxImage takes ownership of copy...
9cbf6f6e
RD
756 }
757
758
d8194e5d
RD
759 DocStr(GetDataBuffer,
760 "Returns a writable Python buffer object that is pointing at the RGB
4187c382
RD
761image data buffer inside the wx.Image. You need to ensure that you do
762not use this buffer object after the image has been destroyed.", "");
d8194e5d
RD
763 PyObject* GetDataBuffer()
764 {
765 buffer data = self->GetData();
1dc2f865 766 int len = self->GetWidth() * self->GetHeight() * 3;
d14a1e28
RD
767 PyObject* rv;
768 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
769 return rv;
1dc2f865 770 }
1e4a197e 771
d8194e5d
RD
772 DocStr(SetDataBuffer,
773 "Sets the internal image data pointer to point at a Python buffer
4187c382
RD
774object. This can save making an extra copy of the data but you must
775ensure that the buffer object lives longer than the wx.Image does.", "");
d8194e5d
RD
776 void SetDataBuffer(buffer data, int DATASIZE)
777 {
778 if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) {
779 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
780 return;
1e4a197e 781 }
d8194e5d 782 self->SetData(data, true);
1e4a197e
RD
783 }
784
9cbf6f6e
RD
785
786
d8194e5d
RD
787 DocStr(GetAlphaData,
788 "Returns a string containing a copy of the alpha bytes of the image.", "");
9cbf6f6e 789 PyObject* GetAlphaData() {
d8194e5d 790 buffer data = self->GetAlpha();
9cbf6f6e
RD
791 if (! data) {
792 RETURN_NONE();
793 } else {
794 int len = self->GetWidth() * self->GetHeight();
d14a1e28
RD
795 PyObject* rv;
796 wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) );
797 return rv;
9cbf6f6e
RD
798 }
799 }
1dc2f865 800
d8194e5d
RD
801 DocStr(SetAlphaData,
802 "Resets the Image's alpha data from a buffer of bytes. Accepts either
803a string or a buffer object holding the data and the length of the
804data must be width*height.", "");
805 void SetAlphaData(buffer alpha, int ALPHASIZE)
806 {
807 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
808 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
809 return;
1dc2f865 810 }
d8194e5d
RD
811 buffer acopy = (buffer)malloc(ALPHASIZE);
812 if (acopy == NULL) {
813 wxPyBLOCK_THREADS(PyErr_NoMemory());
814 return;
815 }
816 memcpy(acopy, alpha, ALPHASIZE);
817 self->SetAlpha(acopy, false);
818 // wxImage takes ownership of acopy...
1dc2f865 819 }
9cbf6f6e
RD
820
821
d8194e5d 822
a8696086 823 DocStr(GetAlphaBuffer,
d8194e5d 824 "Returns a writable Python buffer object that is pointing at the Alpha
4187c382
RD
825data buffer inside the wx.Image. You need to ensure that you do not
826use this buffer object after the image has been destroyed.", "");
d8194e5d
RD
827 PyObject* GetAlphaBuffer()
828 {
829 buffer data = self->GetAlpha();
9cbf6f6e 830 int len = self->GetWidth() * self->GetHeight();
d14a1e28
RD
831 PyObject* rv;
832 wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) );
833 return rv;
9cbf6f6e 834 }
9cbf6f6e 835
d8194e5d 836
a8696086 837 DocStr(SetAlphaBuffer,
d8194e5d 838 "Sets the internal image alpha pointer to point at a Python buffer
4187c382
RD
839object. This can save making an extra copy of the data but you must
840ensure that the buffer object lives as long as the wx.Image does.", "");
d8194e5d
RD
841 void SetAlphaBuffer(buffer alpha, int ALPHASIZE)
842 {
843 if (ALPHASIZE != self->GetWidth() * self->GetHeight()) {
844 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
845 return;
9cbf6f6e 846 }
d8194e5d 847 self->SetAlpha(alpha, true);
9cbf6f6e 848 }
1dc2f865 849 }
cf694132 850
4187c382
RD
851
852
853 DocDeclStr(
854 void , SetMaskColour( byte r, byte g, byte b ),
855 "Sets the mask colour for this image (and tells the image to use the
856mask).", "");
857
f5bac082
RD
858
859 DocDeclAStr(
4187c382
RD
860 /*bool*/ void , GetOrFindMaskColour( byte *OUTPUT,
861 byte *OUTPUT,
862 byte *OUTPUT ) const,
f5bac082
RD
863 "GetOrFindMaskColour() -> (r,g,b)",
864 "Get the current mask colour or find a suitable colour.", "");
865
866
4187c382
RD
867 DocDeclStr(
868 byte , GetMaskRed(),
869 "Gets the red component of the mask colour.", "");
870
871 DocDeclStr(
872 byte , GetMaskGreen(),
873 "Gets the green component of the mask colour.", "");
874
875 DocDeclStr(
876 byte , GetMaskBlue(),
877 "Gets the blue component of the mask colour.", "");
878
879 DocDeclStr(
880 void , SetMask( bool mask = true ),
881 "Specifies whether there is a mask or not. The area of the mask is
882determined by the current mask colour.", "");
883
884 DocDeclStr(
885 bool , HasMask(),
886 "Returns ``True`` if there is a mask active, ``False`` otherwise.", "");
887
cf694132 888
4187c382
RD
889 DocDeclStr(
890 wxImage , Rotate(double angle, const wxPoint & centre_of_rotation,
891 bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ,
892 "Rotates the image about the given point, by ``angle`` radians. Passing
893``True`` to ``interpolating`` results in better image quality, but is
894slower. If the image has a mask, then the mask colour is used for the
895uncovered pixels in the rotated image background. Otherwise, black
896will be used as the fill colour.
897
898Returns the rotated image, leaving this image intact.", "");
899
900 DocDeclStr(
901 wxImage , Rotate90( bool clockwise = true ) ,
902 "Returns a copy of the image rotated 90 degrees in the direction
903indicated by ``clockwise``.", "");
904
905 DocDeclStr(
906 wxImage , Mirror( bool horizontally = true ) ,
907 "Returns a mirrored copy of the image. The parameter ``horizontally``
908indicates the orientation.", "");
909
f6bcfd97 910
4187c382
RD
911 DocDeclStr(
912 void , Replace( byte r1, byte g1, byte b1,
913 byte r2, byte g2, byte b2 ),
914 "Replaces the colour specified by ``(r1,g1,b1)`` by the colour
915``(r2,g2,b2)``.", "");
e054c6ad
RD
916
917 DocDeclStr(
918 wxImage , ConvertToGreyscale( double lr = 0.299,
919 double lg = 0.587,
920 double lb = 0.114 ) const,
921 "Convert to greyscale image. Uses the luminance component (Y) of the
922image. The luma value (YUV) is calculated using (R * lr) + (G * lg) + (B * lb),
923defaults to ITU-T BT.601", "");
4187c382 924
f6bcfd97 925
4187c382
RD
926 DocDeclStr(
927 wxImage , ConvertToMono( byte r, byte g, byte b ) const,
928 "Returns monochromatic version of the image. The returned image has
929white colour where the original has ``(r,g,b)`` colour and black
930colour everywhere else.", "");
931
6c0168c9 932
4187c382
RD
933 DocDeclStr(
934 void , SetOption(const wxString& name, const wxString& value),
935 "Sets an image handler defined option. For example, when saving as a
936JPEG file, the option ``wx.IMAGE_OPTION_QUALITY`` is used, which is a
937number between 0 and 100 (0 is terrible, 100 is very good).", "
938
e47ce385 939 ================================= ===
4187c382
RD
940 wx.IMAGE_OPTION_BMP_FORMAT
941 wx.IMAGE_OPTION_CUR_HOTSPOT_X
942 wx.IMAGE_OPTION_CUR_HOTSPOT_Y
943 wx.IMAGE_OPTION_RESOLUTION
944 wx.IMAGE_OPTION_RESOLUTIONX
945 wx.IMAGE_OPTION_RESOLUTIONY
946 wx.IMAGE_OPTION_RESOLUTIONUNIT
947 wx.IMAGE_OPTION_QUALITY
948 wx.IMAGE_OPTION_BITSPERSAMPLE
949 wx.IMAGE_OPTION_SAMPLESPERPIXEL
950 wx.IMAGE_OPTION_COMPRESSION
951 wx.IMAGE_OPTION_IMAGEDESCRIPTOR
952 wx.IMAGE_OPTION_PNG_FORMAT
953 wx.IMAGE_OPTION_PNG_BITDEPTH
e47ce385 954 ================================= ===
4187c382
RD
955
956:see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOptionInt`");
957
958 DocDeclStrName(
959 void, SetOption(const wxString& name, int value),
960 "Sets an image option as an integer.", "
961
962:see: `HasOption`, `GetOption`, `GetOptionInt`, `SetOption`",
963 SetOptionInt);
964
965 DocDeclStr(
966 wxString , GetOption(const wxString& name) const,
967 "Gets the value of an image handler option.", "
968
969:see: `HasOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
970
971 DocDeclStr(
972 int , GetOptionInt(const wxString& name) const,
973 "Gets the value of an image handler option as an integer. If the given
974option is not present, the function returns 0.", "
975
976:see: `HasOption`, `GetOption`, `SetOptionInt`, `SetOption`");
977
978 DocDeclStr(
979 bool , HasOption(const wxString& name) const,
980 "Returns true if the given option is present.", "
981
982:see: `GetOption`, `GetOptionInt`, `SetOption`, `SetOptionInt`");
983
6c0168c9 984
f6bcfd97 985 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
9cbf6f6e 986 unsigned long ComputeHistogram( wxImageHistogram& h );
f6bcfd97 987
96bfd053
RD
988 static void AddHandler( wxImageHandler *handler );
989 static void InsertHandler( wxImageHandler *handler );
990 static bool RemoveHandler( const wxString& name );
df5f8f4e
RD
991 %extend {
992 static PyObject* GetHandlers() {
993 wxList& list = wxImage::GetHandlers();
994 return wxPy_ConvertList(&list);
995 }
996 }
4187c382
RD
997
998 DocDeclStr(
999 static wxString , GetImageExtWildcard(),
1000 "Iterates all registered wxImageHandler objects, and returns a string
1001containing file extension masks suitable for passing to file open/save
1002dialog boxes.", "");
1003
1004
b96c7a38 1005
ab1f7d2a
RD
1006MustHaveApp(ConvertToBitmap);
1007MustHaveApp(ConvertToMonoBitmap);
be43ef04 1008
d14a1e28 1009 %extend {
12523ae4
RD
1010 wxBitmap ConvertToBitmap(int depth=-1) {
1011 wxBitmap bitmap(*self, depth);
b96c7a38
RD
1012 return bitmap;
1013 }
1014
4187c382
RD
1015 wxBitmap ConvertToMonoBitmap( byte red,
1016 byte green,
1017 byte blue ) {
b96c7a38
RD
1018 wxImage mono = self->ConvertToMono( red, green, blue );
1019 wxBitmap bitmap( mono, 1 );
1020 return bitmap;
1021 }
1022 }
1fded56b 1023
978d3d36
VZ
1024
1025 DocDeclStr(
1026 void , RotateHue(double angle),
1027 "Rotates the hue of each pixel of the image. Hue is a double in the
1028range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees", "");
1029
02b800ce
RD
1030 DocDeclStr(
1031 static wxImage_HSVValue , RGBtoHSV(wxImage_RGBValue rgb),
1032 "Converts a color in RGB color space to HSV color space.", "");
1033
1034 DocDeclStr(
1035 static wxImage_RGBValue , HSVtoRGB(wxImage_HSVValue hsv),
1036 "Converts a color in HSV color space to RGB color space.", "");
1037
978d3d36 1038
6c2dd16f 1039 %pythoncode { def __nonzero__(self): return self.IsOk() }
76b8fa1d
RD
1040
1041 %property(AlphaBuffer, GetAlphaBuffer, SetAlphaBuffer, doc="See `GetAlphaBuffer` and `SetAlphaBuffer`");
1042 %property(AlphaData, GetAlphaData, SetAlphaData, doc="See `GetAlphaData` and `SetAlphaData`");
1043 %property(Data, GetData, SetData, doc="See `GetData` and `SetData`");
1044 %property(DataBuffer, GetDataBuffer, SetDataBuffer, doc="See `GetDataBuffer` and `SetDataBuffer`");
1045 %property(Height, GetHeight, doc="See `GetHeight`");
1046 %property(MaskBlue, GetMaskBlue, doc="See `GetMaskBlue`");
1047 %property(MaskGreen, GetMaskGreen, doc="See `GetMaskGreen`");
1048 %property(MaskRed, GetMaskRed, doc="See `GetMaskRed`");
76b8fa1d 1049 %property(Width, GetWidth, doc="See `GetWidth`");
2dda3864 1050
cf694132
RD
1051};
1052
926bb76c 1053
bf7df69e
RD
1054
1055// Make an image from buffer objects. Not that this is here instead of in the
1056// wxImage class (as a constructor) because there is already another one with
1057// the exact same signature, so there woudl be ambiguities in the generated
1058// C++. Doing it as an independent factory function like this accomplishes
1059// the same thing however.
1060%newobject _ImageFromBuffer;
1061%inline %{
1062 wxImage* _ImageFromBuffer(int width, int height,
1063 buffer data, int DATASIZE,
1064 buffer alpha=NULL, int ALPHASIZE=0)
1065 {
1066 if (DATASIZE != width*height*3) {
1067 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
1068 return NULL;
1069 }
1070 if (alpha != NULL) {
1071 if (ALPHASIZE != width*height) {
1072 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
1073 return NULL;
1074 }
1075 return new wxImage(width, height, data, alpha, true);
1076 }
1077 return new wxImage(width, height, data, true);
1078 }
1079%}
1080
a8696086
RD
1081%pythoncode {
1082def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None):
1083 """
1084 Creates a `wx.Image` from the data in dataBuffer. The dataBuffer
bf64693b
RD
1085 parameter must be a Python object that implements the buffer interface,
1086 such as a string, array, etc. The dataBuffer object is expected to
1087 contain a series of RGB bytes and be width*height*3 bytes long. A buffer
1088 object can optionally be supplied for the image's alpha channel data, and
1089 it is expected to be width*height bytes long.
a8696086 1090
bf7df69e
RD
1091 The wx.Image will be created with its data and alpha pointers initialized
1092 to the memory address pointed to by the buffer objects, thus saving the
1093 time needed to copy the image data from the buffer object to the wx.Image.
1094 While this has advantages, it also has the shoot-yourself-in-the-foot
1095 risks associated with sharing a C pointer between two objects.
1096
1097 To help alleviate the risk a reference to the data and alpha buffer
1098 objects are kept with the wx.Image, so that they won't get deleted until
1099 after the wx.Image is deleted. However please be aware that it is not
1100 guaranteed that an object won't move its memory buffer to a new location
1101 when it needs to resize its contents. If that happens then the wx.Image
1102 will end up referring to an invalid memory location and could cause the
1103 application to crash. Therefore care should be taken to not manipulate
1104 the objects used for the data and alpha buffers in a way that would cause
1105 them to change size.
a8696086 1106 """
bf7df69e 1107 image = _core_._ImageFromBuffer(width, height, dataBuffer, alphaBuffer)
a8696086
RD
1108 image._buffer = dataBuffer
1109 image._alpha = alphaBuffer
1110 return image
1111}
1112
f74ff5ef 1113
a3150741
RD
1114///void wxInitAllImageHandlers();
1115
1116%pythoncode {
1117 def InitAllImageHandlers():
1118 """
1119 The former functionality of InitAllImageHanders is now done internal to
1120 the _core_ extension module and so this function has become a simple NOP.
1121 """
1122 pass
1123}
1124
cf694132 1125
f74ff5ef 1126
d14a1e28
RD
1127%immutable;
1128const wxImage wxNullImage;
1129%mutable;
cf694132 1130
d14a1e28 1131//---------------------------------------------------------------------------
f74ff5ef 1132
655e17cf 1133MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME);
d14a1e28
RD
1134MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT);
1135MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X);
1136MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y);
1137MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION);
655e17cf
RD
1138MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX);
1139MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY);
be43ef04 1140MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT);
97185340 1141MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY);
f74ff5ef 1142
a7c987f9
RD
1143// constants used with wxIMAGE_OPTION_RESOLUTIONUNIT
1144enum wxImageResolution
d14a1e28 1145{
a7c987f9
RD
1146 // Resolution not specified
1147 wxIMAGE_RESOLUTION_NONE = 0,
1148
1149 // Resolution specified in inches
d14a1e28 1150 wxIMAGE_RESOLUTION_INCHES = 1,
a7c987f9
RD
1151
1152 // Resolution specified in centimeters
d14a1e28
RD
1153 wxIMAGE_RESOLUTION_CM = 2
1154};
f74ff5ef
RD
1155
1156
a7c987f9 1157
655e17cf
RD
1158MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE);
1159MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL);
1160MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION);
1161MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR);
1162
9df51bd0
RD
1163MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT);
1164MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH);
1165
1166enum
1167{
1168 wxPNG_TYPE_COLOUR = 0,
1169 wxPNG_TYPE_GREY = 2,
1170 wxPNG_TYPE_GREY_RED = 3
1171};
1172
d14a1e28
RD
1173enum
1174{
1175 wxBMP_24BPP = 24, // default, do not need to set
1176 //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
1177 wxBMP_8BPP = 8, // 8bpp, quantized colors
1178 wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
1179 wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
1180 wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
1181 wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
1182 wxBMP_4BPP = 4, // 4bpp, quantized colors
1183 wxBMP_1BPP = 1, // 1bpp, quantized "colors"
1184 wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
1185};
f74ff5ef
RD
1186
1187
d5a7caf6
RD
1188DocStr(wxBMPHandler,
1189"A `wx.ImageHandler` for \*.bmp bitmap files.", "");
d14a1e28
RD
1190class wxBMPHandler : public wxImageHandler {
1191public:
1192 wxBMPHandler();
1193};
cf694132 1194
d5a7caf6
RD
1195DocStr(wxICOHandler,
1196"A `wx.ImageHandler` for \*.ico icon files.", "");
d14a1e28
RD
1197class wxICOHandler : public wxBMPHandler {
1198public:
1199 wxICOHandler();
1200};
f74ff5ef 1201
d5a7caf6
RD
1202DocStr(wxCURHandler,
1203"A `wx.ImageHandler` for \*.cur cursor files.", "");
d14a1e28
RD
1204class wxCURHandler : public wxICOHandler {
1205public:
1206 wxCURHandler();
1207};
f74ff5ef 1208
d5a7caf6
RD
1209DocStr(wxANIHandler,
1210"A `wx.ImageHandler` for \*.ani animated cursor files.", "");
d14a1e28
RD
1211class wxANIHandler : public wxCURHandler {
1212public:
1213 wxANIHandler();
1214};
06c0fba4 1215
0a651eb8 1216
d14a1e28 1217//---------------------------------------------------------------------------
0a651eb8 1218
d5a7caf6
RD
1219DocStr(wxPNGHandler,
1220"A `wx.ImageHandler` for PNG image files.", "");
d14a1e28
RD
1221class wxPNGHandler : public wxImageHandler {
1222public:
1223 wxPNGHandler();
1224};
0a651eb8 1225
0a651eb8 1226
d5a7caf6
RD
1227DocStr(wxGIFHandler,
1228"A `wx.ImageHandler` for GIF image files.", "");
d14a1e28
RD
1229class wxGIFHandler : public wxImageHandler {
1230public:
1231 wxGIFHandler();
1232};
0a651eb8
RD
1233
1234
d5a7caf6
RD
1235DocStr(wxPCXHandler,
1236"A `wx.ImageHandler` for PCX imager files.", "");
d14a1e28
RD
1237class wxPCXHandler : public wxImageHandler {
1238public:
1239 wxPCXHandler();
1240};
926bb76c 1241
926bb76c 1242
d5a7caf6
RD
1243DocStr(wxJPEGHandler,
1244"A `wx.ImageHandler` for JPEG/JPG image files.", "");
d14a1e28
RD
1245class wxJPEGHandler : public wxImageHandler {
1246public:
1247 wxJPEGHandler();
1248};
926bb76c 1249
926bb76c 1250
d5a7caf6
RD
1251DocStr(wxPNMHandler,
1252"A `wx.ImageHandler` for PNM image files.", "");
d14a1e28
RD
1253class wxPNMHandler : public wxImageHandler {
1254public:
1255 wxPNMHandler();
1256};
1257
d5a7caf6
RD
1258DocStr(wxXPMHandler,
1259"A `wx.ImageHandler` for XPM image.", "");
d14a1e28
RD
1260class wxXPMHandler : public wxImageHandler {
1261public:
1262 wxXPMHandler();
1263};
1264
d5a7caf6
RD
1265DocStr(wxTIFFHandler,
1266"A `wx.ImageHandler` for TIFF image files.", "");
d14a1e28
RD
1267class wxTIFFHandler : public wxImageHandler {
1268public:
1269 wxTIFFHandler();
1270};
1271
1272
8f514ab4
RD
1273
1274#if 0
1275%{
1276#include <wx/imagiff.h>
1277%}
1278
d5a7caf6
RD
1279DocStr(wxIFFHandler,
1280"A `wx.ImageHandler` for IFF image files.", "");
d14a1e28
RD
1281class wxIFFHandler : public wxImageHandler {
1282public:
1283 wxIFFHandler();
1284};
1285#endif
926bb76c 1286
8f514ab4 1287
8f514ab4
RD
1288%{
1289#include <wx/imagtga.h>
1290%}
1291
1292DocStr(wxTGAHandler,
1293"A `wx.ImageHandler` for TGA image files.", "");
1294class wxTGAHandler : public wxImageHandler {
1295public:
1296 wxTGAHandler();
1297};
8f514ab4
RD
1298
1299
be43ef04
RD
1300//---------------------------------------------------------------------------
1301
1302%{
1303#include <wx/quantize.h>
1304%}
1305
1306enum {
1307 wxQUANTIZE_INCLUDE_WINDOWS_COLOURS,
1308// wxQUANTIZE_RETURN_8BIT_DATA,
1309 wxQUANTIZE_FILL_DESTINATION_IMAGE
1310};
1311
1312
1313DocStr(wxQuantize,
1314 "Performs quantization, or colour reduction, on a wxImage.", "");
1315
1316class wxQuantize /*: public wxObject */
1317{
1318public:
1319
1320 %extend {
1321 DocStr(
1322 Quantize,
1323 "Reduce the colours in the source image and put the result into the
39101468 1324destination image, setting the palette in the destination if
be43ef04
RD
1325needed. Both images may be the same, to overwrite the source image.", "
1326:todo: Create a version that returns the wx.Palette used.");
1327
1328 static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236,
1329 int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE)
1330 {
1331 return wxQuantize::Quantize(src, dest,
1332 //NULL, // palette
1333 desiredNoColours,
1334 NULL, // eightBitData
1335 flags);
1336 }
1337 }
1338};
1339
1340
cf694132 1341//---------------------------------------------------------------------------