From: Robin Dunn Date: Fri, 25 Aug 2006 03:30:20 +0000 (+0000) Subject: Add wrappers for wxNativePixelData and wxAlphaPixelData X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/777dffec694eae7231e4133e5dc6bbca78045f29 Add wrappers for wxNativePixelData and wxAlphaPixelData git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40811 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/src/_bitmap.i b/wxPython/src/_bitmap.i index fcb37d0a41..2f018e31e9 100644 --- a/wxPython/src/_bitmap.i +++ b/wxPython/src/_bitmap.i @@ -16,6 +16,10 @@ #include %} + +// Turn off the aquisition of the Global Interpreter Lock for this file +%threadWrapperOff + //--------------------------------------------------------------------------- %{ @@ -443,7 +447,7 @@ def BitmapFromBuffer(width, height, dataBuffer, alphaBuffer=None): %newobject _BitmapFromBufferRGBA; %inline %{ - wxBitmap* _BitmapFromBufferRGBA(int width, int height, buffer data, int DATASIZE) + wxBitmap* _BitmapFromBufferRGBA(int width, int height, buffer data, int DATASIZE) { if (DATASIZE != width*height*4) { wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); @@ -458,7 +462,7 @@ def BitmapFromBuffer(width, height, dataBuffer, alphaBuffer=None): "Failed to gain raw access to bitmap data."); return NULL; } - + pixels.UseAlpha(); wxAlphaPixelData::Iterator p(pixels); for (int y=0; yoperator bool(); } + } + + PixelData##_Iterator GetPixels() const; + void UseAlpha(); +}; + + +class PixelData##_Iterator +{ +public: + %nokwargs PixelData##_Iterator; + + PixelData##_Iterator(PixelData& data); + PixelData##_Iterator(wxBitmap& bmp, PixelData& data); + PixelData##_Iterator(); + + ~PixelData##_Iterator(); + + void Reset(const PixelData& data); + bool IsOk() const; + + %extend { + // PixelData##_Iterator& nextPixel() { return ++(*self); } + void nextPixel() { ++(*self); } + } + + void Offset(const PixelData& data, int x, int y); + void OffsetX(const PixelData& data, int x); + void OffsetY(const PixelData& data, int y); + void MoveTo(const PixelData& data, int x, int y); + + %extend { + byte _get_Red() { return self->Red(); } + byte _get_Green() { return self->Green(); } + byte _get_Blue() { return self->Blue(); } + + void _set_Red(byte val) { self->Red() = val; } + void _set_Green(byte val) { self->Green() = val; } + void _set_Blue(byte val) { self->Blue() = val; } + } + + %pythoncode { + Red = property(_get_Red, _set_Red) + Green = property(_get_Green, _set_Green) + Blue = property(_get_Blue, _set_Blue) + } + +}; +%enddef + + +PIXELDATA(wxNativePixelData) +PIXELDATA(wxAlphaPixelData) + + +// Add in a few things that are different between the wxNativePixelData and +// wxAlphaPixelData iterators and so are not included in our macro... + +%extend wxNativePixelData_Iterator { + void Set(byte red, byte green, byte blue) { + self->Red() = red; + self->Green() = green; + self->Blue() = blue; + } + + PyObject* Get() { + PyObject* rv = PyTuple_New(3); + PyTuple_SetItem(rv, 0, PyInt_FromLong(self->Red())); + PyTuple_SetItem(rv, 1, PyInt_FromLong(self->Green())); + PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue())); + return rv; + } +} + +%extend wxAlphaPixelData_Iterator { + byte _get_Alpha() { return self->Alpha(); } + void _set_Alpha(byte val) { self->Alpha() = val; } + + %pythoncode { + Alpha = property(_get_Alpha, _set_Alpha) + } + + void Set(byte red, byte green, byte blue, byte alpha) { + self->Red() = red; + self->Green() = green; + self->Blue() = blue; + self->Alpha() = alpha; + } + + PyObject* Get() { + PyObject* rv = PyTuple_New(4); + PyTuple_SetItem(rv, 0, PyInt_FromLong(self->Red())); + PyTuple_SetItem(rv, 1, PyInt_FromLong(self->Green())); + PyTuple_SetItem(rv, 2, PyInt_FromLong(self->Blue())); + PyTuple_SetItem(rv, 3, PyInt_FromLong(self->Alpha())); + return rv; + } +} + //--------------------------------------------------------------------------- DocStr(wxMask, @@ -548,3 +690,4 @@ passed then BLACK is used. //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- +%threadWrapperOn