]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_bitmap.i
Fixes for using the staticmethods
[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`, `wx.BitmapFromBits`,
112 `wx.BitmapFromBuffer`, `wx.BitmapFromBufferRGBA`,
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 DocDeclStr(
217 virtual wxMask* , GetMask() const,
218 "Gets the associated mask (if any) which may have been loaded from a
219 file or explpicitly set for the bitmap.
220
221 :see: `SetMask`, `wx.Mask`
222 ", "");
223
224 // MSW only? wxBitmap GetMaskBitmap() const;
225
226 %disownarg(wxMask*);
227 DocDeclStr(
228 virtual void , SetMask(wxMask* mask),
229 "Sets the mask for this bitmap.
230
231 :see: `GetMask`, `wx.Mask`
232 ", "");
233 %cleardisown(wxMask*);
234
235 %extend {
236 DocStr(SetMaskColour,
237 "Create a Mask based on a specified colour in the Bitmap.", "");
238 void SetMaskColour(const wxColour& colour) {
239 wxMask *mask = new wxMask(*self, colour);
240 self->SetMask(mask);
241 }
242 }
243
244
245 DocDeclStr(
246 virtual wxBitmap , GetSubBitmap(const wxRect& rect) const,
247 "Returns a sub-bitmap of the current one as long as the rect belongs
248 entirely to the bitmap. This function preserves bit depth and mask
249 information.", "");
250
251
252 DocDeclStr(
253 virtual bool , SaveFile(const wxString &name, wxBitmapType type,
254 wxPalette *palette = NULL),
255 "Saves a bitmap in the named file. See `__init__` for a description of
256 the ``type`` parameter.", "");
257
258
259 DocDeclStr(
260 virtual bool , LoadFile(const wxString &name, wxBitmapType type),
261 "Loads a bitmap from a file. See `__init__` for a description of the
262 ``type`` parameter.", "");
263
264
265
266 virtual wxPalette *GetPalette() const;
267 #ifdef __WXMSW__
268 virtual void SetPalette(const wxPalette& palette);
269 #endif
270
271
272 virtual bool CopyFromIcon(const wxIcon& icon);
273
274 DocDeclStr(
275 virtual void , SetHeight(int height),
276 "Set the height property (does not affect the existing bitmap data).", "");
277
278
279 DocDeclStr(
280 virtual void , SetWidth(int width),
281 "Set the width property (does not affect the existing bitmap data).", "");
282
283
284 DocDeclStr(
285 virtual void , SetDepth(int depth),
286 "Set the depth property (does not affect the existing bitmap data).", "");
287
288
289 %extend {
290 DocStr(SetSize, "Set the bitmap size (does not affect the existing bitmap data).", "");
291 void SetSize(const wxSize& size) {
292 self->SetWidth(size.x);
293 self->SetHeight(size.y);
294 }
295 }
296
297 #ifdef __WXMSW__
298 bool CopyFromCursor(const wxCursor& cursor);
299
300 // WXWIN_COMPATIBILITY_2_4
301 #if 0
302 int GetQuality();
303 void SetQuality(int q);
304 %pythoncode { GetQuality = wx._deprecated(GetQuality) }
305 %pythoncode { SetQuality = wx._deprecated(SetQuality) }
306 #endif
307 #endif
308
309 %pythoncode { def __nonzero__(self): return self.Ok() }
310
311 %extend {
312 bool __eq__(const wxBitmap* other) { return other ? (*self == *other) : false; }
313 bool __ne__(const wxBitmap* other) { return other ? (*self != *other) : true; }
314 }
315
316 %property(Depth, GetDepth, SetDepth, doc="See `GetDepth` and `SetDepth`");
317 %property(Height, GetHeight, SetHeight, doc="See `GetHeight` and `SetHeight`");
318 %property(Mask, GetMask, SetMask, doc="See `GetMask` and `SetMask`");
319 %property(Palette, GetPalette, doc="See `GetPalette`");
320 %property(Size, GetSize, SetSize, doc="See `GetSize` and `SetSize`");
321 %property(SubBitmap, GetSubBitmap, doc="See `GetSubBitmap`");
322 %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`");
323
324 };
325
326
327 //---------------------------------------------------------------------------
328 // Factory functions for creating wxBitmaps from Python buffer objects. They
329 // use the Abstract Pixel API to be able to set RGB and A bytes directly into
330 // the wxBitmap's pixel buffer.
331
332 %{
333 // See http://tinyurl.com/e5adr for what premultiplying alpha means. It
334 // appears to me that the other platforms are already doing it, so I'll just
335 // automatically do it for wxMSW here.
336 #ifdef __WXMSW__
337 #define wxPy_premultiply(p, a) ((p) * (a) / 0xff)
338 #define wxPy_unpremultiply(p, a) ((a) ? ((p) * 0xff / (a)) : (p))
339 #else
340 #define wxPy_premultiply(p, a) (p)
341 #define wxPy_unpremultiply(p, a) (p)
342 #endif
343 %}
344
345
346 %newobject _BitmapFromBufferAlpha;
347 %newobject _BitmapFromBuffer;
348 %inline %{
349 wxBitmap* _BitmapFromBufferAlpha(int width, int height,
350 buffer data, int DATASIZE,
351 buffer alpha, int ALPHASIZE)
352 {
353 if (DATASIZE != width*height*3) {
354 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
355 return NULL;
356 }
357
358 if (ALPHASIZE != width*height) {
359 wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size.");
360 return NULL;
361 }
362
363 wxBitmap* bmp = new wxBitmap(width, height, 32);
364 wxAlphaPixelData pixData(*bmp, wxPoint(0,0), wxSize(width,height));
365 if (! pixData) {
366 // raise an exception...
367 wxPyErr_SetString(PyExc_RuntimeError,
368 "Failed to gain raw access to bitmap data.");
369 return NULL;
370 }
371
372 pixData.UseAlpha();
373 wxAlphaPixelData::Iterator p(pixData);
374 for (int y=0; y<height; y++) {
375 wxAlphaPixelData::Iterator rowStart = p;
376 for (int x=0; x<width; x++) {
377 byte a = *(alpha++);
378 p.Red() = wxPy_premultiply(*(data++), a);
379 p.Green() = wxPy_premultiply(*(data++), a);
380 p.Blue() = wxPy_premultiply(*(data++), a);
381 p.Alpha() = a;
382 ++p;
383 }
384 p = rowStart;
385 p.OffsetY(pixData, 1);
386 }
387 return bmp;
388 }
389
390 wxBitmap* _BitmapFromBuffer(int width, int height, buffer data, int DATASIZE)
391 {
392 if (DATASIZE != width*height*3) {
393 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
394 return NULL;
395 }
396
397 wxBitmap* bmp = new wxBitmap(width, height, 24);
398 wxNativePixelData pixData(*bmp, wxPoint(0,0), wxSize(width,height));
399 if (! pixData) {
400 // raise an exception...
401 wxPyErr_SetString(PyExc_RuntimeError,
402 "Failed to gain raw access to bitmap data.");
403 return NULL;
404 }
405
406 wxNativePixelData::Iterator p(pixData);
407 for (int y=0; y<height; y++) {
408 wxNativePixelData::Iterator rowStart = p;
409 for (int x=0; x<width; x++) {
410 p.Red() = *(data++);
411 p.Green() = *(data++);
412 p.Blue() = *(data++);
413 ++p;
414 }
415 p = rowStart;
416 p.OffsetY(pixData, 1);
417 }
418 return bmp;
419 }
420 %}
421
422
423 %pythoncode {
424 def BitmapFromBuffer(width, height, dataBuffer, alphaBuffer=None):
425 """
426 Creates a `wx.Bitmap` from the data in dataBuffer. The dataBuffer
427 parameter must be a Python object that implements the buffer
428 interface, such as a string, array, etc. The dataBuffer object is
429 expected to contain a series of RGB bytes and be width*height*3
430 bytes long. A buffer object can optionally be supplied for the
431 image's alpha channel data, and it is expected to be width*height
432 bytes long. On Windows the RGB values are 'premultiplied' by the
433 alpha values. (The other platforms do the multiplication
434 themselves.)
435
436 Unlike `wx.ImageFromBuffer` the bitmap created with this function
437 does not share the memory buffer with the buffer object. This is
438 because the native pixel buffer format varies on different
439 platforms, and so instead an efficient as possible copy of the
440 data is made from the buffer objects to the bitmap's native pixel
441 buffer. For direct access to a bitmap's pixel buffer see
442 `wx.NativePixelData` and `wx.AlphaPixelData`.
443
444 :see: `wx.Bitmap`, `wx.BitmapFromBufferRGBA`, `wx.NativePixelData`,
445 `wx.AlphaPixelData`, `wx.ImageFromBuffer`
446 """
447 if alphaBuffer is not None:
448 return _gdi_._BitmapFromBufferAlpha(width, height, dataBuffer, alphaBuffer)
449 else:
450 return _gdi_._BitmapFromBuffer(width, height, dataBuffer)
451 }
452
453
454
455 %newobject _BitmapFromBufferRGBA;
456 %inline %{
457 wxBitmap* _BitmapFromBufferRGBA(int width, int height, buffer data, int DATASIZE)
458 {
459 if (DATASIZE != width*height*4) {
460 wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
461 return NULL;
462 }
463
464 wxBitmap* bmp = new wxBitmap(width, height, 32);
465 wxAlphaPixelData pixData(*bmp, wxPoint(0,0), wxSize(width,height));
466 if (! pixData) {
467 // raise an exception...
468 wxPyErr_SetString(PyExc_RuntimeError,
469 "Failed to gain raw access to bitmap data.");
470 return NULL;
471 }
472
473 pixData.UseAlpha();
474 wxAlphaPixelData::Iterator p(pixData);
475 for (int y=0; y<height; y++) {
476 wxAlphaPixelData::Iterator rowStart = p;
477 for (int x=0; x<width; x++) {
478 byte a = data[3];
479 p.Red() = wxPy_premultiply(*(data++), a);
480 p.Green() = wxPy_premultiply(*(data++), a);
481 p.Blue() = wxPy_premultiply(*(data++), a);
482 p.Alpha() = a; data++;
483 ++p;
484 }
485 p = rowStart;
486 p.OffsetY(pixData, 1);
487 }
488 return bmp;
489 }
490 %}
491
492 %pythoncode {
493 def BitmapFromBufferRGBA(width, height, dataBuffer):
494 """
495 Creates a `wx.Bitmap` from the data in dataBuffer. The dataBuffer
496 parameter must be a Python object that implements the buffer
497 interface, such as a string, array, etc. The dataBuffer object is
498 expected to contain a series of RGBA bytes (red, green, blue and
499 alpha) and be width*height*4 bytes long. On Windows the RGB
500 values are 'premultiplied' by the alpha values. (The other
501 platforms do the multiplication themselves.)
502
503 Unlike `wx.ImageFromBuffer` the bitmap created with this function
504 does not share the memory buffer with the buffer object. This is
505 because the native pixel buffer format varies on different
506 platforms, and so instead an efficient as possible copy of the
507 data is made from the buffer object to the bitmap's native pixel
508 buffer. For direct access to a bitmap's pixel buffer see
509 `wx.NativePixelData` and `wx.AlphaPixelData`.
510
511 :see: `wx.Bitmap`, `wx.BitmapFromBuffer`, `wx.NativePixelData`,
512 `wx.AlphaPixelData`, `wx.ImageFromBuffer`
513 """
514 return _gdi_._BitmapFromBufferRGBA(width, height, dataBuffer)
515 }
516
517
518 //---------------------------------------------------------------------------
519
520 class wxPixelDataBase
521 {
522 public:
523 // origin of the rectangular region we represent
524 wxPoint GetOrigin() const { return m_ptOrigin; }
525
526 // width and height of the region we represent
527 int GetWidth() const { return m_width; }
528 int GetHeight() const { return m_height; }
529
530 wxSize GetSize() const { return wxSize(m_width, m_height); }
531
532 // the distance between two rows
533 int GetRowStride() const { return m_stride; }
534
535 %property(Height, GetHeight, doc="See `GetHeight`");
536 %property(Origin, GetOrigin, doc="See `GetOrigin`");
537 %property(RowStride, GetRowStride, doc="See `GetRowStride`");
538 %property(Size, GetSize, doc="See `GetSize`");
539 %property(Width, GetWidth, doc="See `GetWidth`");
540 };
541
542
543 // Both wxNativePixelData and wxAlphaPixelData have the same interface, so
544 // make a macro to declare them both.
545
546 %define PIXELDATA(PixelData)
547 %{
548 typedef PixelData##::Iterator PixelData##_Accessor;
549 %}
550 class PixelData##_Accessor;
551 class PixelData : public wxPixelDataBase
552 {
553 public:
554 %nokwargs PixelData;
555
556 PixelData(wxBitmap& bmp);
557 PixelData(wxBitmap& bmp, const wxRect& rect);
558 PixelData(wxBitmap& bmp, const wxPoint& pt, const wxSize& sz);
559
560 ~PixelData();
561
562 PixelData##_Accessor GetPixels() const;
563 void UseAlpha();
564
565 %extend {
566 bool __nonzero__() { return self->operator bool(); }
567 }
568
569 %pythoncode {
570 def __iter__(self):
571 """
572 Create and return an iterator object for this pixel data
573 object. (It's really a generator but I won't tell if you
574 don't tell.)
575 """
576 width = self.GetWidth()
577 height = self.GetHeight()
578 pixels = self.GetPixels()
579
580 # This class is a facade over the pixels object (using the one
581 # in the enclosing scope) that only allows Get() and Set() to
582 # be called.
583 class PixelFacade(object):
584 def Get(self):
585 return pixels.Get()
586 def Set(self, *args, **kw):
587 return pixels.Set(*args, **kw)
588 def __str__(self):
589 return str(self.Get())
590 def __repr__(self):
591 return 'pixel(%d,%d): %s' % (x,y,self.Get())
592 X = property(lambda self: x)
593 Y = property(lambda self: y)
594
595 pf = PixelFacade()
596 for y in xrange(height):
597 for x in xrange(width):
598 # We always generate the same pf instance, but it
599 # accesses the pixels object which we use to iterate
600 # over the pixel buffer.
601 yield pf
602 pixels.nextPixel()
603 pixels.MoveTo(self, 0, y)
604 }
605
606 %property(Pixels, GetPixels, doc="See `GetPixels`");
607 };
608
609
610
611 class PixelData##_Accessor
612 {
613 public:
614 %nokwargs PixelData##_Accessor;
615
616 PixelData##_Accessor(PixelData& data);
617 PixelData##_Accessor(wxBitmap& bmp, PixelData& data);
618 PixelData##_Accessor();
619
620 ~PixelData##_Accessor();
621
622 void Reset(const PixelData& data);
623 bool IsOk() const;
624
625 %extend {
626 // PixelData##_Accessor& nextPixel() { return ++(*self); }
627 void nextPixel() { ++(*self); }
628 }
629
630 void Offset(const PixelData& data, int x, int y);
631 void OffsetX(const PixelData& data, int x);
632 void OffsetY(const PixelData& data, int y);
633 void MoveTo(const PixelData& data, int x, int y);
634
635 // NOTE: For now I'm not wrapping the Red, Green, Blue and Alpha
636 // functions because I can't hide the premultiplying needed on wxMSW
637 // if only the individual components are wrapped, plus it would mean 3
638 // or 4 trips per pixel from Python to C++ instead of just one.
639 // Instead I've added the Set and Get functions and put the
640 // premultiplying in there.
641
642 // %extend {
643 // byte _get_Red() { return self->Red(); }
644 // byte _get_Green() { return self->Green(); }
645 // byte _get_Blue() { return self->Blue(); }
646
647 // void _set_Red(byte val) { self->Red() = val; }
648 // void _set_Green(byte val) { self->Green() = val; }
649 // void _set_Blue(byte val) { self->Blue() = val; }
650 // }
651
652 // %pythoncode {
653 // Red = property(_get_Red, _set_Red)
654 // Green = property(_get_Green, _set_Green)
655 // Blue = property(_get_Blue, _set_Blue)
656 // }
657 };
658 %enddef
659
660
661 %pythonAppend wxAlphaPixelData::wxAlphaPixelData "self.UseAlpha()"
662
663 // Make the classes
664 PIXELDATA(wxNativePixelData)
665 PIXELDATA(wxAlphaPixelData)
666
667
668 // Add in a few things that are different between the wxNativePixelData and
669 // wxAlphaPixelData and the iterator classes and so are not included in our
670 // macro...
671
672 %extend wxNativePixelData_Accessor {
673 void Set(byte red, byte green, byte blue) {
674 self->Red() = red;
675 self->Green() = green;
676 self->Blue() = blue;
677 }
678
679 PyObject* Get() {
680 PyObject* rv = PyTuple_New(3);
681 PyTuple_SetItem(rv, 0, PyInt_FromLong(self->Red()));
682 PyTuple_SetItem(rv, 1, PyInt_FromLong(self->Green()));
683 PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue()));
684 return rv;
685 }
686 }
687
688 %extend wxAlphaPixelData_Accessor {
689 // byte _get_Alpha() { return self->Alpha(); }
690 // void _set_Alpha(byte val) { self->Alpha() = val; }
691
692 // %pythoncode {
693 // Alpha = property(_get_Alpha, _set_Alpha)
694 // }
695
696 void Set(byte red, byte green, byte blue, byte alpha) {
697 self->Red() = wxPy_premultiply(red, alpha);
698 self->Green() = wxPy_premultiply(green, alpha);
699 self->Blue() = wxPy_premultiply(blue, alpha);
700 self->Alpha() = alpha;
701 }
702
703 PyObject* Get() {
704 PyObject* rv = PyTuple_New(4);
705 int red = self->Red();
706 int green = self->Green();
707 int blue = self->Blue();
708 int alpha = self->Alpha();
709
710 PyTuple_SetItem(rv, 0, PyInt_FromLong( wxPy_unpremultiply(red, alpha) ));
711 PyTuple_SetItem(rv, 1, PyInt_FromLong( wxPy_unpremultiply(green, alpha) ));
712 PyTuple_SetItem(rv, 2, PyInt_FromLong( wxPy_unpremultiply(blue, alpha) ));
713 PyTuple_SetItem(rv, 3, PyInt_FromLong( alpha ));
714 return rv;
715 }
716 }
717
718
719 //---------------------------------------------------------------------------
720
721 DocStr(wxMask,
722 "This class encapsulates a monochrome mask bitmap, where the masked
723 area is black and the unmasked area is white. When associated with a
724 bitmap and drawn in a device context, the unmasked area of the bitmap
725 will be drawn, and the masked area will not be drawn.
726
727 A mask may be associated with a `wx.Bitmap`. It is used in
728 `wx.DC.DrawBitmap` or `wx.DC.Blit` when the source device context is a
729 `wx.MemoryDC` with a `wx.Bitmap` selected into it that contains a
730 mask.", "");
731
732 MustHaveApp(wxMask);
733
734 class wxMask : public wxObject {
735 public:
736
737 DocStr(wxMask,
738 "Constructs a mask from a `wx.Bitmap` and a `wx.Colour` in that bitmap
739 that indicates the transparent portions of the mask. In other words,
740 the pixels in ``bitmap`` that match ``colour`` will be the transparent
741 portions of the mask. If no ``colour`` or an invalid ``colour`` is
742 passed then BLACK is used.
743
744 :see: `wx.Bitmap`, `wx.Colour`", "");
745
746 %extend {
747 wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) {
748 if ( !colour.Ok() )
749 return new wxMask(bitmap, *wxBLACK);
750 else
751 return new wxMask(bitmap, colour);
752 }
753 }
754
755 ~wxMask();
756 };
757
758 %pythoncode { MaskColour = wx._deprecated(Mask, "wx.MaskColour is deprecated, use `wx.Mask` instead.") }
759
760 //---------------------------------------------------------------------------
761 //---------------------------------------------------------------------------
762 %threadWrapperOn