mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-04 19:10:09 +01:00
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:
@@ -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
|
||||
|
||||
@@ -52,7 +52,6 @@ public:
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
void* m_ptr;
|
||||
Py_ssize_t m_len;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user