+ %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);