+ DocStr(CopyFromBufferRGBA,
+ "Copy data from a RGBA buffer object to replace the bitmap pixel data.
+See `wxBitmapFromBufferRGBA` 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);
+ }
+ }
+ }
+
+
+ %pythoncode { def __nonzero__(self): return self.IsOk() }
+
+ // TODO: Should these just be removed since the C++ operators are
+ // gone? Or is using IsSameAs for wxPython ok?