- %name(EmptyImage) wxImage(int width=0, int height=0, bool clear = True) {
- if (width > 0 && height > 0)
- return new wxImage(width, height, clear);
- else
- return new wxImage;
- }
-
- %name(ImageFromBitmap) wxImage(const wxBitmap &bitmap) {
- return new wxImage(bitmap.ConvertToImage());
- }
-
- %name(ImageFromData) wxImage(int width, int height, unsigned char* data) {
- // Copy the source data so the wxImage can clean it up later
- unsigned char* copy = (unsigned char*)malloc(width*height*3);
- if (copy == NULL) {
- PyErr_NoMemory();
- return NULL;
+ %RenameDocCtor(
+ EmptyImage,
+ "Construct an empty image of a given size, optionally setting all
+pixels to black.", "",
+ wxImage(int width=0, int height=0, bool clear = true))
+ {
+ if (width > 0 && height > 0)
+ return new wxImage(width, height, clear);
+ else
+ return new wxImage;
+ }
+
+
+ MustHaveApp(wxImage(const wxBitmap &bitmap));
+
+ %RenameDocCtor(
+ ImageFromBitmap,
+ "Construct an Image from a `wx.Bitmap`.", "",
+ wxImage(const wxBitmap &bitmap))
+ {
+ return new wxImage(bitmap.ConvertToImage());
+ }
+
+ %RenameDocCtor(
+ ImageFromData,
+ "Construct an Image from a buffer of RGB bytes. Accepts either a
+string or a buffer object holding the data and the length of the data
+must be width*height*3.", "",
+ wxImage(int width, int height, buffer data, int DATASIZE))
+ {
+ if (DATASIZE != width*height*3) {
+ wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
+ return NULL;
+ }
+
+ // Copy the source data so the wxImage can clean it up later
+ buffer copy = (buffer)malloc(DATASIZE);
+ if (copy == NULL) {
+ wxPyBLOCK_THREADS(PyErr_NoMemory());
+ return NULL;
+ }
+ memcpy(copy, data, DATASIZE);
+ return new wxImage(width, height, copy, false);
+ }
+
+
+ %RenameDocCtor(
+ ImageFromDataWithAlpha,
+ "Construct an Image from a buffer of RGB bytes with an Alpha channel.
+Accepts either a string or a buffer object holding the data and the
+length of the data must be width*height*3.", "",
+ wxImage(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;
+ }
+
+ // Copy the source data so the wxImage can clean it up later
+ buffer dcopy = (buffer)malloc(DATASIZE);
+ if (dcopy == NULL) {
+ wxPyBLOCK_THREADS(PyErr_NoMemory());
+ return NULL;
+ }
+ memcpy(dcopy, data, DATASIZE);
+
+ buffer acopy = (buffer)malloc(ALPHASIZE);
+ if (acopy == NULL) {
+ wxPyBLOCK_THREADS(PyErr_NoMemory());
+ return NULL;
+ }
+ memcpy(acopy, alpha, ALPHASIZE);
+
+ return new wxImage(width, height, dcopy, acopy, false);