mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Merge pull request #6988 from radarhere/memoryview
This commit is contained in:
commit
bfcea9d718
|
@ -100,8 +100,11 @@ class TestImageWinDib:
|
||||||
# Act
|
# Act
|
||||||
# Make one the same as the using tobytes()/frombytes()
|
# Make one the same as the using tobytes()/frombytes()
|
||||||
test_buffer = dib1.tobytes()
|
test_buffer = dib1.tobytes()
|
||||||
dib2.frombytes(test_buffer)
|
for datatype in ("bytes", "memoryview"):
|
||||||
|
if datatype == "memoryview":
|
||||||
|
test_buffer = memoryview(test_buffer)
|
||||||
|
dib2.frombytes(test_buffer)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
# Confirm they're the same
|
# Confirm they're the same
|
||||||
assert dib1.tobytes() == dib2.tobytes()
|
assert dib1.tobytes() == dib2.tobytes()
|
||||||
|
|
|
@ -195,20 +195,21 @@ _releasedc(ImagingDisplayObject *display, PyObject *args) {
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_frombytes(ImagingDisplayObject *display, PyObject *args) {
|
_frombytes(ImagingDisplayObject *display, PyObject *args) {
|
||||||
char *ptr;
|
Py_buffer buffer;
|
||||||
Py_ssize_t bytes;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "y#:frombytes", &ptr, &bytes)) {
|
if (!PyArg_ParseTuple(args, "y*:frombytes", &buffer)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (display->dib->ysize * display->dib->linesize != bytes) {
|
if (display->dib->ysize * display->dib->linesize != buffer.len) {
|
||||||
|
PyBuffer_Release(&buffer);
|
||||||
PyErr_SetString(PyExc_ValueError, "wrong size");
|
PyErr_SetString(PyExc_ValueError, "wrong size");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(display->dib->bits, ptr, bytes);
|
memcpy(display->dib->bits, buffer.buf, buffer.len);
|
||||||
|
|
||||||
|
PyBuffer_Release(&buffer);
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user