X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a86960861fb8824b4b39aa62c04c2689a6163f61..3af4da323ab401ad41e2eca2c6afbc2c3d632da6:/wxPython/src/_image.i?ds=sidebyside diff --git a/wxPython/src/_image.i b/wxPython/src/_image.i index d87eae375b..f083ba0d17 100644 --- a/wxPython/src/_image.i +++ b/wxPython/src/_image.i @@ -54,6 +54,11 @@ public: void SetExtension(const wxString& extension); void SetType(long type); void SetMimeType(const wxString& mimetype); + + %property(Extension, GetExtension, SetExtension, doc="See `GetExtension` and `SetExtension`"); + %property(MimeType, GetMimeType, SetMimeType, doc="See `GetMimeType` and `SetMimeType`"); + %property(Name, GetName, SetName, doc="See `GetName` and `SetName`"); + %property(Type, GetType, SetType, doc="See `GetType` and `SetType`"); }; @@ -153,19 +158,6 @@ key value from a RGB tripple.", ""); //--------------------------------------------------------------------------- -%{ - typedef unsigned char* buffer; -%} - -%typemap(in) (buffer data, int DATASIZE) - { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; } - -%typemap(in) (buffer alpha, int ALPHASIZE) - { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; } - -//--------------------------------------------------------------------------- - - DocStr(wxImage, "A platform-independent image class. An image can be created from data, or using `wx.Bitmap.ConvertToImage`, or loaded from a file in a @@ -388,37 +380,6 @@ alpha data must be width*height bytes.", " return new wxImage(width, height, dcopy, acopy, false); } - - // NOTE: We need the junk parameter so the compiler will be able - // differentiate from the two functions above. It isn't used for - // anything else. - %RenameDocCtor( - _ImageFromBuffer, ":see: `wx.ImageFromBuffer`", "", - wxImage(int width, int height, buffer data, int DATASIZE, PyObject* junk)) - { - wxUnusedVar(junk); - if (DATASIZE != width*height*3) { - wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); - return NULL; - } - return new wxImage(width, height, data, true); - } - - %RenameDocCtor( - _ImageFromBufferWithAlpha, ":see: `wx.ImageFromBuffer`", "", - wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE, PyObject* junk)) - { - wxUnusedVar(junk); - 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; - } - return new wxImage(width, height, data, alpha, true); - } } // TODO: wxImage( char** xpmData ); @@ -1027,34 +988,74 @@ range -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees", ""); %pythoncode { def __nonzero__(self): return self.Ok() } + + %property(AlphaBuffer, GetAlphaBuffer, SetAlphaBuffer, doc="See `GetAlphaBuffer` and `SetAlphaBuffer`"); + %property(AlphaData, GetAlphaData, SetAlphaData, doc="See `GetAlphaData` and `SetAlphaData`"); + %property(Data, GetData, SetData, doc="See `GetData` and `SetData`"); + %property(DataBuffer, GetDataBuffer, SetDataBuffer, doc="See `GetDataBuffer` and `SetDataBuffer`"); + %property(Height, GetHeight, doc="See `GetHeight`"); + %property(MaskBlue, GetMaskBlue, doc="See `GetMaskBlue`"); + %property(MaskGreen, GetMaskGreen, doc="See `GetMaskGreen`"); + %property(MaskRed, GetMaskRed, doc="See `GetMaskRed`"); + %property(Size, GetSize, doc="See `GetSize`"); + %property(Width, GetWidth, doc="See `GetWidth`"); }; + +// Make an image from buffer objects. Not that this is here instead of in the +// wxImage class (as a constructor) because there is already another one with +// the exact same signature, so there woudl be ambiguities in the generated +// C++. Doing it as an independent factory function like this accomplishes +// the same thing however. +%newobject _ImageFromBuffer; +%inline %{ + wxImage* _ImageFromBuffer(int width, int height, + buffer data, int DATASIZE, + buffer alpha=NULL, int ALPHASIZE=0) + { + if (DATASIZE != width*height*3) { + wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); + return NULL; + } + if (alpha != NULL) { + if (ALPHASIZE != width*height) { + wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size."); + return NULL; + } + return new wxImage(width, height, data, alpha, true); + } + return new wxImage(width, height, data, true); + } +%} + %pythoncode { def ImageFromBuffer(width, height, dataBuffer, alphaBuffer=None): """ Creates a `wx.Image` from the data in dataBuffer. The dataBuffer - parameter must be a Python object that implements the buffer - interface, such as a string, array, etc. The dataBuffer object is - expected to contain a series of RGB bytes and be width*height*3 - bytes long. A buffer object can optionally be supplied for the - image's alpha channel data, and it is expected to be width*height - bytes long. - - A reference to the data and alpha buffer objects are kept with the - wx.Image, so that they won't get deleted until after the wx.Image - is deleted. However please be aware that it is not guaranteed that - an object won't move its memory buffer to a new location when it - needs to resize its contents. If that happens then the wx.Image - will end up referring to an invalid memory location and could cause - the application to crash. Therefore care should be taken to not - manipulate the objects used for the data and alpha buffers in a - way that would cause them to change size. + parameter must be a Python object that implements the buffer interface, + such as a string, array, etc. The dataBuffer object is expected to + contain a series of RGB bytes and be width*height*3 bytes long. A buffer + object can optionally be supplied for the image's alpha channel data, and + it is expected to be width*height bytes long. + + The wx.Image will be created with its data and alpha pointers initialized + to the memory address pointed to by the buffer objects, thus saving the + time needed to copy the image data from the buffer object to the wx.Image. + While this has advantages, it also has the shoot-yourself-in-the-foot + risks associated with sharing a C pointer between two objects. + + To help alleviate the risk a reference to the data and alpha buffer + objects are kept with the wx.Image, so that they won't get deleted until + after the wx.Image is deleted. However please be aware that it is not + guaranteed that an object won't move its memory buffer to a new location + when it needs to resize its contents. If that happens then the wx.Image + will end up referring to an invalid memory location and could cause the + application to crash. Therefore care should be taken to not manipulate + the objects used for the data and alpha buffers in a way that would cause + them to change size. """ - if alphaBuffer is not None: - image = _ImageFromBufferWithAlpha(width, height, dataBuffer, alphaBuffer, None) - else: - image = _ImageFromBuffer(width, height, dataBuffer, None) + image = _core_._ImageFromBuffer(width, height, dataBuffer, alphaBuffer) image._buffer = dataBuffer image._alpha = alphaBuffer return image