mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Added memoryview support to frombytes()
This commit is contained in:
parent
dbcd7372e5
commit
132fb9360b
|
@ -1,10 +1,17 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import assert_image_equal, hopper
|
from .helper import assert_image_equal, hopper
|
||||||
|
|
||||||
|
|
||||||
def test_sanity():
|
@pytest.mark.parametrize("data_type", ("bytes", "memoryview"))
|
||||||
|
def test_sanity(data_type):
|
||||||
im1 = hopper()
|
im1 = hopper()
|
||||||
im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes())
|
|
||||||
|
data = im1.tobytes()
|
||||||
|
if data_type == "memoryview":
|
||||||
|
data = memoryview(data)
|
||||||
|
im2 = Image.frombytes(im1.mode, im1.size, data)
|
||||||
|
|
||||||
assert_image_equal(im1, im2)
|
assert_image_equal(im1, im2)
|
||||||
|
|
|
@ -116,12 +116,11 @@ _dealloc(ImagingDecoderObject *decoder) {
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_decode(ImagingDecoderObject *decoder, PyObject *args) {
|
_decode(ImagingDecoderObject *decoder, PyObject *args) {
|
||||||
UINT8 *buffer;
|
Py_buffer buffer;
|
||||||
Py_ssize_t bufsize;
|
|
||||||
int status;
|
int status;
|
||||||
ImagingSectionCookie cookie;
|
ImagingSectionCookie cookie;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "y#", &buffer, &bufsize)) {
|
if (!PyArg_ParseTuple(args, "y*", &buffer)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +128,7 @@ _decode(ImagingDecoderObject *decoder, PyObject *args) {
|
||||||
ImagingSectionEnter(&cookie);
|
ImagingSectionEnter(&cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = decoder->decode(decoder->im, &decoder->state, buffer, bufsize);
|
status = decoder->decode(decoder->im, &decoder->state, buffer.buf, buffer.len);
|
||||||
|
|
||||||
if (!decoder->pulls_fd) {
|
if (!decoder->pulls_fd) {
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user