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