+ %extend {
+ DocStr(CopyFromBuffer,
+ "Copy data from a RGB buffer object to replace the bitmap pixel data.
+See `wx.BitmapFromBuffer` for more details.", "");
+ void CopyFromBuffer(buffer data, int DATASIZE)
+ {
+ int height=self->GetHeight();
+ int width=self->GetWidth();
+
+ if (DATASIZE != width * height * 3) {
+ wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
+ }
+ wxNativePixelData pixData(*self, wxPoint(0,0), wxSize(width, height));
+ if (! pixData) {
+ // raise an exception...
+ wxPyErr_SetString(PyExc_RuntimeError,
+ "Failed to gain raw access to bitmap data.");
+ return;
+ }
+
+ wxNativePixelData::Iterator p(pixData);
+ for (int y=0; y<height; y++) {
+ wxNativePixelData::Iterator rowStart = p;
+ for (int x=0; x<width; x++) {
+ p.Red() = *(data++);
+ p.Green() = *(data++);
+ p.Blue() = *(data++);
+ ++p;
+ }
+ p = rowStart;
+ p.OffsetY(pixData, 1);
+ }
+ }
+
+ DocStr(CopyFromBufferRGBA,
+ "Copy data from a RGBA buffer object to replace the bitmap pixel data.
+See `wx.BitmapFromBufferRGBA` for more details.", "");
+ void CopyFromBufferRGBA(buffer data, int DATASIZE)
+ {
+ int height=self->GetHeight();
+ int width=self->GetWidth();
+
+ if (DATASIZE != width * height * 4) {
+ wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size.");
+ }
+ wxAlphaPixelData pixData(*self, wxPoint(0,0), wxSize(width, height));
+ if (! pixData) {
+ // raise an exception...
+ wxPyErr_SetString(PyExc_RuntimeError,
+ "Failed to gain raw access to bitmap data.");
+ return;
+ }
+
+ pixData.UseAlpha();
+ wxAlphaPixelData::Iterator p(pixData);
+ for (int y=0; y<height; y++) {
+ wxAlphaPixelData::Iterator rowStart = p;
+ for (int x=0; x<width; x++) {
+ byte a = data[3];
+ p.Red() = wxPy_premultiply(*(data++), a);
+ p.Green() = wxPy_premultiply(*(data++), a);
+ p.Blue() = wxPy_premultiply(*(data++), a);
+ p.Alpha() = a; data++;
+ ++p;
+ }
+ p = rowStart;
+ p.OffsetY(pixData, 1);
+ }
+ }
+ }