]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_bitmap.i
d43ad7c762d2ca8f2705ea5d4daecf88f998fa91
[wxWidgets.git] / wxPython / src / _bitmap.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _bitmap.i
3 // Purpose: SWIG interface for wxBitmap and wxMask
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 7-July-1997
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15 %{
16 #include <wx/rawbmp.h>
17 %}
18
19
20 // Turn off the aquisition of the Global Interpreter Lock for this file
21 %threadWrapperOff
22
23 //---------------------------------------------------------------------------
24
25 %{
26 #include <wx/image.h>
27
28 static char** ConvertListOfStrings(PyObject* listOfStrings) {
29 char** cArray = NULL;
30 int count;
31
32 if (!PyList_Check(listOfStrings)) {
33 PyErr_SetString(PyExc_TypeError, "Expected a list of strings.");
34 return NULL;
35 }
36 count = PyList_Size(listOfStrings);
37 cArray = new char*[count];
38
39 for(int x=0; x<count; x++) {
40 // TODO: Need some validation and error checking here
41 cArray[x] = PyString_AsString(PyList_GET_ITEM(listOfStrings, x));
42 }
43 return cArray;
44 }
45
46 %}
47
48 //---------------------------------------------------------------------------
49
50 // TODO: When the API stabalizes and is available on other platforms, add
51 // wrappers for the new wxBitmap, wxRawBitmap, wxDIB stuff...
52
53 DocStr(wxBitmap,
54 "The wx.Bitmap class encapsulates the concept of a platform-dependent
55 bitmap. It can be either monochrome or colour, and either loaded from
56 a file or created dynamically. A bitmap can be selected into a memory
57 device context (instance of `wx.MemoryDC`). This enables the bitmap to
58 be copied to a window or memory device context using `wx.DC.Blit`, or
59 to be used as a drawing surface.", "
60
61 The BMP and XMP image file formats are supported on all platforms by
62 wx.Bitmap. Other formats are automatically loaded by `wx.Image` and
63 converted to a wx.Bitmap, so any image file format supported by
64 `wx.Image` can be used.
65
66 :todo: Add wrappers and support for raw bitmap data access. Can this
67 be be put into Python without losing the speed benefits of the
68 teplates and iterators in rawbmp.h?
69
70 :todo: Find a way to do very efficient PIL Image <--> wx.Bitmap
71 converstions.
72
73 :see: `wx.EmptyBitmap`, `wx.BitmapFromIcon`, `wx.BitmapFromImage`,
74 `wx.BitmapFromXPMData`, `wx.BitmapFromBits`, `wx.BitmapFromBuffer`,
75 `wx.BitmapFromBufferRGBA`, `wx.Image`
76 ");
77
78
79 MustHaveApp(wxBitmap);
80
81 class wxBitmap : public wxGDIObject
82 {
83 public:
84 DocCtorStr(
85 wxBitmap(const wxString& name, wxBitmapType type=wxBITMAP_TYPE_ANY),
86 "Loads a bitmap from a file.",
87 "
88 :param name: Name of the file to load the bitmap from.
89 :param type: The type of image to expect. Can be one of the following
90 constants (assuming that the neccessary `wx.Image` handlers are
91 loaded):
92
93 * wx.BITMAP_TYPE_ANY
94 * wx.BITMAP_TYPE_BMP
95 * wx.BITMAP_TYPE_ICO
96 * wx.BITMAP_TYPE_CUR
97 * wx.BITMAP_TYPE_XBM
98 * wx.BITMAP_TYPE_XPM
99 * wx.BITMAP_TYPE_TIF
100 * wx.BITMAP_TYPE_GIF
101 * wx.BITMAP_TYPE_PNG
102 * wx.BITMAP_TYPE_JPEG
103 * wx.BITMAP_TYPE_PNM
104 * wx.BITMAP_TYPE_PCX
105 * wx.BITMAP_TYPE_PICT
106 * wx.BITMAP_TYPE_ICON
107 * wx.BITMAP_TYPE_ANI
108 * wx.BITMAP_TYPE_IFF
109
110 :see: Alternate constructors `wx.EmptyBitmap`, `wx.BitmapFromIcon`,
111 `wx.BitmapFromImage`, `wx.BitmapFromXPMData`,
112 `wx.BitmapFromBits`
113 ");
114
115 ~wxBitmap();
116
117 DocCtorStrName(
118 wxBitmap(int width, int height, int depth=-1),
119 "Creates a new bitmap of the given size. A depth of -1 indicates the
120 depth of the current screen or visual. Some platforms only support 1
121 for monochrome and -1 for the current display depth.", "",
122 EmptyBitmap);
123
124 DocCtorStrName(
125 wxBitmap(const wxIcon& icon),
126 "Create a new bitmap from a `wx.Icon` object.", "",
127 BitmapFromIcon);
128
129 DocCtorStrName(
130 wxBitmap(const wxImage& image, int depth=-1),
131 "Creates bitmap object from a `wx.Image`. This has to be done to
132 actually display a `wx.Image` as you cannot draw an image directly on
133 a window. The resulting bitmap will use the provided colour depth (or
134 that of the current screen colour depth if depth is -1) which entails
135 that a colour reduction may have to take place.", "",
136 BitmapFromImage);
137
138
139 %extend {
140 %RenameDocCtor(
141 BitmapFromXPMData,
142 "Construct a Bitmap from a list of strings formatted as XPM data.", "",
143 wxBitmap(PyObject* listOfStrings))
144 {
145 char** cArray = NULL;
146 wxBitmap* bmp;
147
148 cArray = ConvertListOfStrings(listOfStrings);
149 if (! cArray)
150 return NULL;
151 bmp = new wxBitmap(cArray);
152 delete [] cArray;
153 return bmp;
154 }
155
156
157 %RenameDocCtor(
158 BitmapFromBits,
159 "Creates a bitmap from an array of bits. You should only use this
160 function for monochrome bitmaps (depth 1) in portable programs: in
161 this case the bits parameter should contain an XBM image. For other
162 bit depths, the behaviour is platform dependent.", "",
163 wxBitmap(PyObject* bits, int width, int height, int depth=1 ))
164 {
165 char* buf;
166 Py_ssize_t length;
167 PyString_AsStringAndSize(bits, &buf, &length);
168 return new wxBitmap(buf, width, height, depth);
169 }
170 }
171
172
173 // wxGDIImage methods
174 #ifdef __WXMSW__
175 long GetHandle();
176 %extend {
177 void SetHandle(long handle) { self->SetHandle((WXHANDLE)handle); }
178 }
179 #endif
180
181 bool Ok();
182
183 DocDeclStr(
184 int , GetWidth(),
185 "Gets the width of the bitmap in pixels.", "");
186
187
188 DocDeclStr(
189 int , GetHeight(),
190 "Gets the height of the bitmap in pixels.", "");
191
192
193 DocDeclStr(
194 int , GetDepth(),
195 "Gets the colour depth of the bitmap. A value of 1 indicates a
196 monochrome bitmap.", "");
197
198
199
200 %extend {
201 DocStr(GetSize, "Get the size of the bitmap.", "");
202 wxSize GetSize() {
203 wxSize size(self->GetWidth(), self->GetHeight());
204 return size;
205 }
206 }
207
208
209 DocDeclStr(
210 virtual wxImage , ConvertToImage() const,
211 "Creates a platform-independent image from a platform-dependent
212 bitmap. This preserves mask information so that bitmaps and images can
213 be converted back and forth without loss in that respect.", "");
214
215
216
217 DocDeclStr(
218 virtual wxMask* , GetMask() const,
219 "Gets the associated mask (if any) which may have been loaded from a
220 file or explpicitly set for the bitmap.
221
222 :see: `SetMask`, `wx.Mask`
223 ", "");
224
225 // MSW only? wxBitmap GetMaskBitmap() const;
226
227 %disownarg(wxMask*);
228 DocDeclStr(
229 virtual void , SetMask(wxMask* mask),
230 "Sets the mask for this bitmap.
231
232 :see: `GetMask`, `wx.Mask`
233 ", "");
234 %cleardisown(wxMask*);
235
236 %extend {
237 DocStr(SetMaskColour,
238 "Create a Mask based on a specified colour in the Bitmap.", "");
239 void SetMaskColour(const wxColour& colour) {
240 wxMask *mask = new wxMask(*self, colour);
241 self->SetMask(mask);
242 }
243 }
244
245
246 DocDeclStr(
247 virtual wxBitmap , GetSubBitmap(const wxRect& rect) const,
248 "Returns a sub-bitmap of the current one as long as the rect belongs
249 entirely to the bitmap. This function preserves bit depth and mask
250 information.", "");
251
252
253 DocDeclStr(
254 virtual bool , SaveFile(const wxString &name, wxBitmapType type,
255 wxPalette *palette = NULL),
256 "Saves a bitmap in the named file. See `__init__` for a description of
257 the ``type`` parameter.", "");
258
259
260 DocDeclStr(
261 virtual bool , LoadFile(const wxString &name, wxBitmapType type),
262 "Loads a bitmap from a file. See `__init__` for a description of the
263 ``type`` parameter.", "");
264
265
266
267 virtual wxPalette *GetPalette() const;
268 #ifdef __WXMSW__
269 virtual void SetPalette(const wxPalette& palette);
270 #endif
271
272
273 virtual bool CopyFromIcon(const wxIcon& icon);
274
275 DocDeclStr(
276 virtual void , SetHeight(int height),
277 "Set the height property (does not affect the existing bitmap data).", "");
278
279
280 DocDeclStr(
281 virtual void , SetWidth(int width),
282 "Set the width property (does not affect the existing bitmap data).", "");
283
284
285 DocDeclStr(
286 virtual void , SetDepth(int depth),
287 "Set the depth property (does not affect the existing bitmap data).", "");
288
289
290 %extend {
291 DocStr(SetSize, "Set the bitmap size (does not affect the existing bitmap data).", "");
292 void SetSize(const wxSize& size) {
293 self->SetWidth(size.x);
294 self->SetHeight(size.y);
295 }
296 }
297
298 #ifdef __WXMSW__
299 bool CopyFromCursor(const wxCursor& cursor);
300
301 // WXWIN_COMPATIBILITY_2_4
302 #if 0
303 int GetQuality();
304 void SetQuality(int q);
305 %pythoncode { GetQuality = wx._deprecated(GetQuality) }
306 %pythoncode { SetQuality = wx._deprecated(SetQuality) }
307 #endif
308 #endif
309
310 %pythoncode { def __nonzero__(self): return self.Ok() }
311
312 %extend {
313 bool __eq__(const wxBitmap* other) { return other ? (*self == *other) : false; }
314 bool __ne__(const wxBitmap* other) { return other ? (*self != *other) : true; }
315 }
316 };
317
318
319 //---------------------------------------------------------------------------
320 // Factory functions for creating wxBitmaps from Python buffer objects. They
321 // use the Abstract Pixel API to be able to set RGB and A bytes directly into
322 // the wxBitmap's pixel buffer.
323
324 %{
325 // See http://tinyurl.com/e5adr for what premultiplying alpha means. It
326 // appears to me that the other platforms are already doing it, so I'll just
327 // automatically do it for wxMSW here.
328 #ifdef __WXMSW__
329 #define wxPy_premultiply(p, a) ((p) * (a) / 256)
330 #define wxPy_unpremultiply(p, a) ((a) ? ((p) * 256 / (a)) : (p))
331 #else
332 #define wxPy_premultiply(p, a) (p)
333 #define wxPy_unpremultiply(p, a) (p)
334 #endif
335 %}
336
337
338 %newobject _BitmapFromBufferAlpha;
339 %newobject _BitmapFromBuffer;
340 %inline %{
341 wxBitmap* _BitmapFromBufferAlpha(int width, int height,
342 buffer data, int DATASIZE,
343 buffer alpha, int ALPHASIZE)
344 {
345 if (DATASIZE != width*height*3) {
346 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
347 return NULL;
348 }
349
350 if (ALPHASIZE != width*height) {
351 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
352 return NULL;
353 }
354
355 wxBitmap* bmp = new wxBitmap(width, height, 32);
356 wxAlphaPixelData pixData(*bmp, wxPoint(0,0), wxSize(width,height));
357 if (! pixData) {
358 // raise an exception...
359 wxPyErr_SetString(PyExc_RuntimeError,
360 "Failed to gain raw access to bitmap data.");
361 return NULL;
362 }
363
364 pixData.UseAlpha();
365 wxAlphaPixelData::Iterator p(pixData);
366 for (int y=0; y<height; y++) {
367 wxAlphaPixelData::Iterator rowStart = p;
368 for (int x=0; x<width; x++) {
369 byte a = *(alpha++);
370 p.Red() = wxPy_premultiply(*(data++), a);
371 p.Green() = wxPy_premultiply(*(data++), a);
372 p.Blue() = wxPy_premultiply(*(data++), a);
373 p.Alpha() = a;
374 ++p;
375 }
376 p = rowStart;
377 p.OffsetY(pixData, 1);
378 }
379 return bmp;
380 }
381
382 wxBitmap* _BitmapFromBuffer(int width, int height, buffer data, int DATASIZE)
383 {
384 if (DATASIZE != width*height*3) {
385 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
386 return NULL;
387 }
388
389 wxBitmap* bmp = new wxBitmap(width, height, 24);
390 wxNativePixelData pixData(*bmp, wxPoint(0,0), wxSize(width,height));
391 if (! pixData) {
392 // raise an exception...
393 wxPyErr_SetString(PyExc_RuntimeError,
394 "Failed to gain raw access to bitmap data.");
395 return NULL;
396 }
397
398 wxNativePixelData::Iterator p(pixData);
399 for (int y=0; y<height; y++) {
400 wxNativePixelData::Iterator rowStart = p;
401 for (int x=0; x<width; x++) {
402 p.Red() = *(data++);
403 p.Green() = *(data++);
404 p.Blue() = *(data++);
405 ++p;
406 }
407 p = rowStart;
408 p.OffsetY(pixData, 1);
409 }
410 return bmp;
411 }
412 %}
413
414
415 %pythoncode {
416 def BitmapFromBuffer(width, height, dataBuffer, alphaBuffer=None):
417 """
418 Creates a `wx.Bitmap` from the data in dataBuffer. The dataBuffer
419 parameter must be a Python object that implements the buffer
420 interface, such as a string, array, etc. The dataBuffer object is
421 expected to contain a series of RGB bytes and be width*height*3
422 bytes long. A buffer object can optionally be supplied for the
423 image's alpha channel data, and it is expected to be width*height
424 bytes long. On Windows the RGB values are 'premultiplied' by the
425 alpha values. (The other platforms do the multiplication
426 themselves.)
427
428 Unlike `wx.ImageFromBuffer` the bitmap created with this function
429 does not share the memory buffer with the buffer object. This is
430 because the native pixel buffer format varies on different
431 platforms, and so instead an efficient as possible copy of the
432 data is made from the buffer objects to the bitmap's native pixel
433 buffer. For direct access to a bitmap's pixel buffer see
434 `wx.NativePixelData` and `wx.AlphaPixelData`.
435
436 :see: `wx.Bitmap`, `wx.BitmapFromBufferRGBA`, `wx.NativePixelData`,
437 `wx.AlphaPixelData`, `wx.ImageFromBuffer`
438 """
439 if alphaBuffer is not None:
440 return _gdi_._BitmapFromBufferAlpha(width, height, dataBuffer, alphaBuffer)
441 else:
442 return _gdi_._BitmapFromBuffer(width, height, dataBuffer)
443 }
444
445
446
447 %newobject _BitmapFromBufferRGBA;
448 %inline %{
449 wxBitmap* _BitmapFromBufferRGBA(int width, int height, buffer data, int DATASIZE)
450 {
451 if (DATASIZE != width*height*4) {
452 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
453 return NULL;
454 }
455
456 wxBitmap* bmp = new wxBitmap(width, height, 32);
457 wxAlphaPixelData pixData(*bmp, wxPoint(0,0), wxSize(width,height));
458 if (! pixData) {
459 // raise an exception...
460 wxPyErr_SetString(PyExc_RuntimeError,
461 "Failed to gain raw access to bitmap data.");
462 return NULL;
463 }
464
465 pixData.UseAlpha();
466 wxAlphaPixelData::Iterator p(pixData);
467 for (int y=0; y<height; y++) {
468 wxAlphaPixelData::Iterator rowStart = p;
469 for (int x=0; x<width; x++) {
470 byte a = data[3];
471 p.Red() = wxPy_premultiply(*(data++), a);
472 p.Green() = wxPy_premultiply(*(data++), a);
473 p.Blue() = wxPy_premultiply(*(data++), a);
474 p.Alpha() = a; data++;
475 ++p;
476 }
477 p = rowStart;
478 p.OffsetY(pixData, 1);
479 }
480 return bmp;
481 }
482 %}
483
484 %pythoncode {
485 def BitmapFromBufferRGBA(width, height, dataBuffer):
486 """
487 Creates a `wx.Bitmap` from the data in dataBuffer. The dataBuffer
488 parameter must be a Python object that implements the buffer
489 interface, such as a string, array, etc. The dataBuffer object is
490 expected to contain a series of RGBA bytes (red, green, blue and
491 alpha) and be width*height*4 bytes long. On Windows the RGB
492 values are 'premultiplied' by the alpha values. (The other
493 platforms do the multiplication themselves.)
494
495 Unlike `wx.ImageFromBuffer` the bitmap created with this function
496 does not share the memory buffer with the buffer object. This is
497 because the native pixel buffer format varies on different
498 platforms, and so instead an efficient as possible copy of the
499 data is made from the buffer object to the bitmap's native pixel
500 buffer. For direct access to a bitmap's pixel buffer see
501 `wx.NativePixelData` and `wx.AlphaPixelData`.
502
503 :see: `wx.Bitmap`, `wx.BitmapFromBuffer`, `wx.NativePixelData`,
504 `wx.AlphaPixelData`, `wx.ImageFromBuffer`
505 """
506 return _gdi_._BitmapFromBufferRGBA(width, height, dataBuffer)
507 }
508
509
510 //---------------------------------------------------------------------------
511
512 class wxPixelDataBase
513 {
514 public:
515 // origin of the rectangular region we represent
516 wxPoint GetOrigin() const { return m_ptOrigin; }
517
518 // width and height of the region we represent
519 int GetWidth() const { return m_width; }
520 int GetHeight() const { return m_height; }
521
522 wxSize GetSize() const { return wxSize(m_width, m_height); }
523
524 // the distance between two rows
525 int GetRowStride() const { return m_stride; }
526
527 };
528
529
530 // Both wxNativePixelData and wxAlphaPixelData have the same interface, so
531 // make a macro to declare them both.
532
533 %define PIXELDATA(PixelData)
534 %{
535 typedef PixelData##::Iterator PixelData##_Accessor;
536 %}
537 class PixelData##_Accessor;
538 class PixelData : public wxPixelDataBase
539 {
540 public:
541 %nokwargs PixelData;
542
543 PixelData(wxBitmap& bmp);
544 PixelData(wxBitmap& bmp, const wxRect& rect);
545 PixelData(wxBitmap& bmp, const wxPoint& pt, const wxSize& sz);
546
547 ~PixelData();
548
549 PixelData##_Accessor GetPixels() const;
550 void UseAlpha();
551
552 %extend {
553 bool __nonzero__() { return self->operator bool(); }
554 }
555
556 %pythoncode {
557 def __iter__(self):
558 """Create and return an iterator object for this pixel data object."""
559 return self.PixelIterator(self)
560
561 class PixelIterator(object):
562 """
563 Sequential iterator which returns pixel accessor objects starting at the
564 the top-left corner, and going row-by-row until the bottom-right
565 corner is reached.
566 """
567
568 class PixelAccessor(object):
569 """
570 This class is what is returned by the iterator and allows the pixel
571 to be Get or Set.
572 """
573 def __init__(self, data, pixels, x, y):
574 self.data = data
575 self.pixels = pixels
576 self.x = x
577 self.y = y
578 def Set(self, *args, **kw):
579 self.pixels.MoveTo(self.data, self.x, self.y)
580 return self.pixels.Set(*args, **kw)
581 def Get(self):
582 self.pixels.MoveTo(self.data, self.x, self.y)
583 return self.pixels.Get()
584
585 def __init__(self, pixelData):
586 self.x = self.y = 0
587 self.w = pixelData.GetWidth()
588 self.h = pixelData.GetHeight()
589 self.data = pixelData
590 self.pixels = pixelData.GetPixels()
591
592 def __iter__(self):
593 return self
594
595 def next(self):
596 if self.y >= self.h:
597 raise StopIteration
598 p = self.PixelAccessor(self.data, self.pixels, self.x, self.y)
599 self.x += 1
600 if self.x >= self.w:
601 self.x = 0
602 self.y += 1
603 return p
604 }
605 };
606
607
608
609 class PixelData##_Accessor
610 {
611 public:
612 %nokwargs PixelData##_Accessor;
613
614 PixelData##_Accessor(PixelData& data);
615 PixelData##_Accessor(wxBitmap& bmp, PixelData& data);
616 PixelData##_Accessor();
617
618 ~PixelData##_Accessor();
619
620 void Reset(const PixelData& data);
621 bool IsOk() const;
622
623 %extend {
624 // PixelData##_Accessor& nextPixel() { return ++(*self); }
625 void nextPixel() { ++(*self); }
626 }
627
628 void Offset(const PixelData& data, int x, int y);
629 void OffsetX(const PixelData& data, int x);
630 void OffsetY(const PixelData& data, int y);
631 void MoveTo(const PixelData& data, int x, int y);
632
633 // NOTE: For now I'm not wrapping the Red, Green, Blue and Alpha functions
634 // because I can't hide the premultiplying needed on wxMSW if only the
635 // individual components are wrapped. Instead I've added the Set and Get
636 // functions and put the premultiplying in there.
637
638 // %extend {
639 // byte _get_Red() { return self->Red(); }
640 // byte _get_Green() { return self->Green(); }
641 // byte _get_Blue() { return self->Blue(); }
642
643 // void _set_Red(byte val) { self->Red() = val; }
644 // void _set_Green(byte val) { self->Green() = val; }
645 // void _set_Blue(byte val) { self->Blue() = val; }
646 // }
647
648 // %pythoncode {
649 // Red = property(_get_Red, _set_Red)
650 // Green = property(_get_Green, _set_Green)
651 // Blue = property(_get_Blue, _set_Blue)
652 // }
653 };
654 %enddef
655
656
657 %pythonAppend wxAlphaPixelData::wxAlphaPixelData "self.UseAlpha()"
658
659 // Make the classes
660 PIXELDATA(wxNativePixelData)
661 PIXELDATA(wxAlphaPixelData)
662
663
664 // Add in a few things that are different between the wxNativePixelData and
665 // wxAlphaPixelData and the iterator classes and so are not included in our
666 // macro...
667
668 %extend wxNativePixelData_Accessor {
669 void Set(byte red, byte green, byte blue) {
670 self->Red() = red;
671 self->Green() = green;
672 self->Blue() = blue;
673 }
674
675 PyObject* Get() {
676 PyObject* rv = PyTuple_New(3);
677 PyTuple_SetItem(rv, 0, PyInt_FromLong(self->Red()));
678 PyTuple_SetItem(rv, 1, PyInt_FromLong(self->Green()));
679 PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue()));
680 return rv;
681 }
682 }
683
684 %extend wxAlphaPixelData_Accessor {
685 // byte _get_Alpha() { return self->Alpha(); }
686 // void _set_Alpha(byte val) { self->Alpha() = val; }
687
688 // %pythoncode {
689 // Alpha = property(_get_Alpha, _set_Alpha)
690 // }
691
692 void Set(byte red, byte green, byte blue, byte alpha) {
693 self->Red() = wxPy_premultiply(red, alpha);
694 self->Green() = wxPy_premultiply(green, alpha);
695 self->Blue() = wxPy_premultiply(blue, alpha);
696 self->Alpha() = alpha;
697 }
698
699 PyObject* Get() {
700 PyObject* rv = PyTuple_New(4);
701 int red = self->Red();
702 int green = self->Green();
703 int blue = self->Blue();
704 int alpha = self->Alpha();
705
706 PyTuple_SetItem(rv, 0, PyInt_FromLong( wxPy_unpremultiply(red, alpha) ));
707 PyTuple_SetItem(rv, 1, PyInt_FromLong( wxPy_unpremultiply(green, alpha) ));
708 PyTuple_SetItem(rv, 2, PyInt_FromLong( wxPy_unpremultiply(blue, alpha) ));
709 PyTuple_SetItem(rv, 3, PyInt_FromLong( alpha ));
710 return rv;
711 }
712 }
713
714
715 //---------------------------------------------------------------------------
716
717 DocStr(wxMask,
718 "This class encapsulates a monochrome mask bitmap, where the masked
719 area is black and the unmasked area is white. When associated with a
720 bitmap and drawn in a device context, the unmasked area of the bitmap
721 will be drawn, and the masked area will not be drawn.
722
723 A mask may be associated with a `wx.Bitmap`. It is used in
724 `wx.DC.DrawBitmap` or `wx.DC.Blit` when the source device context is a
725 `wx.MemoryDC` with a `wx.Bitmap` selected into it that contains a
726 mask.", "");
727
728 MustHaveApp(wxMask);
729
730 class wxMask : public wxObject {
731 public:
732
733 DocStr(wxMask,
734 "Constructs a mask from a `wx.Bitmap` and a `wx.Colour` in that bitmap
735 that indicates the transparent portions of the mask. In other words,
736 the pixels in ``bitmap`` that match ``colour`` will be the transparent
737 portions of the mask. If no ``colour`` or an invalid ``colour`` is
738 passed then BLACK is used.
739
740 :see: `wx.Bitmap`, `wx.Colour`", "");
741
742 %extend {
743 wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) {
744 if ( !colour.Ok() )
745 return new wxMask(bitmap, *wxBLACK);
746 else
747 return new wxMask(bitmap, colour);
748 }
749 }
750
751 ~wxMask();
752 };
753
754 %pythoncode { MaskColour = wx._deprecated(Mask, "wx.MaskColour is deprecated, use `wx.Mask` instead.") }
755
756 //---------------------------------------------------------------------------
757 //---------------------------------------------------------------------------
758 %threadWrapperOn