X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c1acc12983d95b1e3034d6a9b3b23db3038c694c..e1b1b6be56af94d010d925141b2079c7a65a54ec:/wxPython/src/_bitmap.i?ds=sidebyside diff --git a/wxPython/src/_bitmap.i b/wxPython/src/_bitmap.i index 83fa392e75..fcb37d0a41 100644 --- a/wxPython/src/_bitmap.i +++ b/wxPython/src/_bitmap.i @@ -12,6 +12,9 @@ // Not a %module +%{ +#include +%} //--------------------------------------------------------------------------- @@ -62,6 +65,10 @@ converted to a wx.Bitmap, so any image file format supported by :todo: Find a way to do very efficient PIL Image <--> wx.Bitmap converstions. + +:see: `wx.EmptyBitmap`, `wx.BitmapFromIcon`, `wx.BitmapFromImage`, + `wx.BitmapFromXPMData`, `wx.BitmapFromBits`, `wx.BitmapFromBuffer`, + `wx.BitmapFromBufferRGBA`, `wx.Image` "); @@ -107,7 +114,7 @@ public: wxBitmap(int width, int height, int depth=-1), "Creates a new bitmap of the given size. A depth of -1 indicates the depth of the current screen or visual. Some platforms only support 1 -for monochrome and -1 for the current colour setting.", "", +for monochrome and -1 for the current display depth.", "", EmptyBitmap); DocCtorStrName( @@ -126,35 +133,36 @@ that a colour reduction may have to take place.", "", %extend { - DocStr(wxBitmap(PyObject* listOfStrings), - "Construct a Bitmap from a list of strings formatted as XPM data.", ""); - - %RenameCtor(BitmapFromXPMData, wxBitmap(PyObject* listOfStrings)) - { - char** cArray = NULL; - wxBitmap* bmp; - - cArray = ConvertListOfStrings(listOfStrings); - if (! cArray) - return NULL; - bmp = new wxBitmap(cArray); - delete [] cArray; - return bmp; - } - - DocStr(wxBitmap(PyObject* bits, int width, int height, int depth=1 ), - "Creates a bitmap from an array of bits. You should only use this + %RenameDocCtor( + BitmapFromXPMData, + "Construct a Bitmap from a list of strings formatted as XPM data.", "", + wxBitmap(PyObject* listOfStrings)) + { + char** cArray = NULL; + wxBitmap* bmp; + + cArray = ConvertListOfStrings(listOfStrings); + if (! cArray) + return NULL; + bmp = new wxBitmap(cArray); + delete [] cArray; + return bmp; + } + + + %RenameDocCtor( + BitmapFromBits, + "Creates a bitmap from an array of bits. You should only use this function for monochrome bitmaps (depth 1) in portable programs: in this case the bits parameter should contain an XBM image. For other -bit depths, the behaviour is platform dependent.", ""); - - %RenameCtor(BitmapFromBits, wxBitmap(PyObject* bits, int width, int height, int depth=1 )) - { - char* buf; - int length; - PyString_AsStringAndSize(bits, &buf, &length); - return new wxBitmap(buf, width, height, depth); - } +bit depths, the behaviour is platform dependent.", "", + wxBitmap(PyObject* bits, int width, int height, int depth=1 )) + { + char* buf; + Py_ssize_t length; + PyString_AsStringAndSize(bits, &buf, &length); + return new wxBitmap(buf, width, height, depth); + } } @@ -201,6 +209,7 @@ bitmap. This preserves mask information so that bitmaps and images can be converted back and forth without loss in that respect.", ""); + DocDeclStr( virtual wxMask* , GetMask() const, "Gets the associated mask (if any) which may have been loaded from a @@ -211,13 +220,14 @@ file or explpicitly set for the bitmap. // MSW only? wxBitmap GetMaskBitmap() const; + %disownarg(wxMask*); DocDeclStr( virtual void , SetMask(wxMask* mask), "Sets the mask for this bitmap. :see: `GetMask`, `wx.Mask` ", ""); - + %cleardisown(wxMask*); %extend { DocStr(SetMaskColour, @@ -283,8 +293,14 @@ 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() } @@ -296,6 +312,199 @@ the ``type`` parameter.", ""); }; +//--------------------------------------------------------------------------- +// Factory functions for creating wxBitmaps from Python buffer objects. They +// 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) / 256) +#else +#define wxPy_premultiply(p, a) (p) +#endif +%} + + +%newobject _BitmapFromBufferAlpha; +%newobject _BitmapFromBuffer; +%inline %{ + wxBitmap* _BitmapFromBufferAlpha(int width, int height, + buffer data, int DATASIZE, + buffer alpha, int ALPHASIZE) + { + if (DATASIZE != width*height*3) { + wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); + return NULL; + } + + if (ALPHASIZE != width*height) { + wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size."); + return NULL; + } + + wxBitmap* bmp = new wxBitmap(width, height, 32); + wxAlphaPixelData pixels(*bmp, wxPoint(0,0), wxSize(width,height)); + if (! pixels) { + // raise an exception... + wxPyErr_SetString(PyExc_RuntimeError, + "Failed to gain raw access to bitmap data."); + return NULL; + } + + pixels.UseAlpha(); + wxAlphaPixelData::Iterator p(pixels); + for (int y=0; y