Small tweak and tests to allow using objects supporting only the old buffer interface to be used as buffer sources.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73872 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2013-04-27 02:49:08 +00:00
parent 9448b458a9
commit 5a958ff03b
4 changed files with 28 additions and 4 deletions

View File

@@ -290,8 +290,7 @@ methods which accept any object supporting the buffer protocol. These
are methods which allow you to set the raw RGB or Alpha data in the
image in one step. As a consequence of using the new APIs the objects
passed must also implement the new buffer interface in order to be
compatible. Apparently arrays from the stock array module do not
support the new protocol, but everything else I've tried so far do.
compatible.
GetData and GetAlpha now return a copy of the image data as a
bytearray object instead of a string object. This means that since

View File

@@ -52,7 +52,6 @@ public:
return ptr;
}
void* m_ptr;
Py_ssize_t m_len;
};

View File

@@ -23,7 +23,8 @@
%ConvertToTypeCode
// Code to test a PyObject for compatibility
if (!sipIsErr) {
if (PyObject_CheckBuffer(sipPy))
if (PyObject_CheckBuffer(sipPy) // New buffer interface
|| PyObject_CheckReadBuffer(sipPy)) // or old buffer interface
return TRUE;
return FALSE;
}

View File

@@ -174,6 +174,31 @@ class BitmapTests(wtc.WidgetTestCase):
self.assertTrue(bmp.IsOk())
def test_bitmapBufferFactory4(self):
# The array.array object does not support the new buffer protocol,
# (at least as of 2.7) so this test shows if we can support the old
# one too.
import array
w = h = 10
buf = array.array('B', [123] * (w*h*4))
bmp = wx.Bitmap.FromBufferRGBA(w, h, buf)
self.assertTrue(bmp.IsOk())
def test_bitmapBufferFactory5(self):
# The array.array object does not support the new buffer protocol,
# (at least as of 2.7) so this test shows if we can support the old
# one too.
import array
w = h = 10
buf = array.array('B', [10, 20, 30] * (w*h))
bmp = wx.Bitmap.FromBuffer(w, h, buf)
self.assertTrue(bmp.IsOk())
img = bmp.ConvertToImage()
self.assertEqual( (img.GetRed(1,2), img.GetGreen(1,2), img.GetBlue(1,2)),
(10,20,30) )
def test_bitmapEmptyFactory1(self):
w = h = 10
bmp = wx.Bitmap.FromRGBA(w, h)