+
+
+
+ PyObject* GetDataBuffer() {
+ unsigned char* data = self->GetData();
+ int len = self->GetWidth() * self->GetHeight() * 3;
+ return PyBuffer_FromReadWriteMemory(data, len);
+ }
+ void SetDataBuffer(PyObject* data) {
+ unsigned char* buffer;
+ int size;
+
+ if (!PyArg_Parse(data, "w#", &buffer, &size))
+ return;
+
+ if (size != self->GetWidth() * self->GetHeight() * 3) {
+ PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
+ return;
+ }
+ self->SetData(buffer);
+ }
+
+
+
+ PyObject* GetAlphaData() {
+ unsigned char* data = self->GetAlpha();
+ if (! data) {
+ RETURN_NONE();
+ } else {
+ int len = self->GetWidth() * self->GetHeight();
+ return PyString_FromStringAndSize((char*)data, len);
+ }
+ }
+ void SetAlphaData(PyObject* data) {
+ unsigned char* dataPtr;
+
+ if (! PyString_Check(data)) {
+ PyErr_SetString(PyExc_TypeError, "Expected string object");
+ return /* NULL */ ;
+ }
+
+ size_t len = self->GetWidth() * self->GetHeight();
+ dataPtr = (unsigned char*) malloc(len);
+ memcpy(dataPtr, PyString_AsString(data), len);
+ self->SetAlpha(dataPtr);
+ // wxImage takes ownership of dataPtr...
+ }
+
+
+
+ PyObject* GetAlphaBuffer() {
+ unsigned char* data = self->GetAlpha();
+ int len = self->GetWidth() * self->GetHeight();
+ return PyBuffer_FromReadWriteMemory(data, len);
+ }
+ void SetAlphaBuffer(PyObject* data) {
+ unsigned char* buffer;
+ int size;
+
+ if (!PyArg_Parse(data, "w#", &buffer, &size))
+ return;
+
+ if (size != self->GetWidth() * self->GetHeight()) {
+ PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
+ return;
+ }
+ self->SetAlpha(buffer);
+ }