X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7012bb9f03e0012c32485655b7af4345b490bf4d..4f84bfb64f80c03c8779a102ec9c87b9f3cc44ea:/wxPython/src/_bitmap.i diff --git a/wxPython/src/_bitmap.i b/wxPython/src/_bitmap.i index f4b5ba82b8..1316e7cd35 100644 --- a/wxPython/src/_bitmap.i +++ b/wxPython/src/_bitmap.i @@ -17,11 +17,28 @@ %} -// Turn off the aquisition of the Global Interpreter Lock for this file +// Turn off the aquisition of the Global Interpreter Lock for the classes and +// functions in this file %threadWrapperOff //--------------------------------------------------------------------------- +%{ +// See http://tinyurl.com/e5adr for what premultiplying alpha means. It +// appears to me that the other platforms are already doing it, so I'll just +// automatically do it for wxMSW here. +#ifdef __WXMSW__ +#define wxPy_premultiply(p, a) ((p) * (a) / 0xff) +#define wxPy_unpremultiply(p, a) ((a) ? ((p) * 0xff / (a)) : (p)) +#else +#define wxPy_premultiply(p, a) (p) +#define wxPy_unpremultiply(p, a) (p) +#endif +%} + +//--------------------------------------------------------------------------- + + %{ #include @@ -178,8 +195,9 @@ bit depths, the behaviour is platform dependent.", "", } #endif - bool Ok(); - + bool IsOk(); + %pythoncode { Ok = IsOk } + DocDeclStr( int , GetWidth(), "Gets the width of the bitmap in pixels.", ""); @@ -296,21 +314,87 @@ the ``type`` parameter.", ""); #ifdef __WXMSW__ bool CopyFromCursor(const wxCursor& cursor); - -// WXWIN_COMPATIBILITY_2_4 - #if 0 - int GetQuality(); - void SetQuality(int q); - %pythoncode { GetQuality = wx._deprecated(GetQuality) } - %pythoncode { SetQuality = wx._deprecated(SetQuality) } - #endif #endif - %pythoncode { def __nonzero__(self): return self.Ok() } + %extend { + DocStr(CopyFromBuffer, + "Copy data from a RGB buffer object to replace the bitmap pixel data. +See `wxBitmapFromBuffer` for more details.", ""); + void CopyFromBuffer(buffer data, int DATASIZE) + { + int height=self->GetHeight(); + int width=self->GetWidth(); + + if (DATASIZE != width * height * 3) { + wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); + } + wxNativePixelData pixData(*self, wxPoint(0,0), wxSize(width, height)); + if (! pixData) { + // raise an exception... + wxPyErr_SetString(PyExc_RuntimeError, + "Failed to gain raw access to bitmap data."); + return; + } + + wxNativePixelData::Iterator p(pixData); + for (int y=0; yGetHeight(); + int width=self->GetWidth(); + + if (DATASIZE != width * height * 4) { + wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); + } + wxAlphaPixelData pixData(*self, wxPoint(0,0), wxSize(width, height)); + if (! pixData) { + // raise an exception... + wxPyErr_SetString(PyExc_RuntimeError, + "Failed to gain raw access to bitmap data."); + return; + } + + pixData.UseAlpha(); + wxAlphaPixelData::Iterator p(pixData); + for (int y=0; yIsSameAs(*other) : false; } + bool __ne__(const wxBitmap* other) { return other ? !self->IsSameAs(*other) : true; } } %property(Depth, GetDepth, SetDepth, doc="See `GetDepth` and `SetDepth`"); @@ -329,19 +413,6 @@ the ``type`` parameter.", ""); // use the Abstract Pixel API to be able to set RGB and A bytes directly into // the wxBitmap's pixel buffer. -%{ -// See http://tinyurl.com/e5adr for what premultiplying alpha means. It -// appears to me that the other platforms are already doing it, so I'll just -// automatically do it for wxMSW here. -#ifdef __WXMSW__ -#define wxPy_premultiply(p, a) ((p) * (a) / 0xff) -#define wxPy_unpremultiply(p, a) ((a) ? ((p) * 0xff / (a)) : (p)) -#else -#define wxPy_premultiply(p, a) (p) -#define wxPy_unpremultiply(p, a) (p) -#endif -%} - %newobject _BitmapFromBufferAlpha; %newobject _BitmapFromBuffer; @@ -745,7 +816,7 @@ passed then BLACK is used. %extend { wxMask(const wxBitmap& bitmap, const wxColour& colour = wxNullColour) { - if ( !colour.Ok() ) + if ( !colour.IsOk() ) return new wxMask(bitmap, *wxBLACK); else return new wxMask(bitmap, colour); @@ -759,4 +830,6 @@ passed then BLACK is used. //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- + +// Turn GIL acquisition back on. %threadWrapperOn