mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +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 .helper import assert_image_equal, hopper
|
||||
|
||||
|
||||
def test_sanity():
|
||||
@pytest.mark.parametrize("data_type", ("bytes", "memoryview"))
|
||||
def test_sanity(data_type):
|
||||
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)
|
||||
|
|
|
@ -116,12 +116,11 @@ _dealloc(ImagingDecoderObject *decoder) {
|
|||
|
||||
static PyObject *
|
||||
_decode(ImagingDecoderObject *decoder, PyObject *args) {
|
||||
UINT8 *buffer;
|
||||
Py_ssize_t bufsize;
|
||||
Py_buffer buffer;
|
||||
int status;
|
||||
ImagingSectionCookie cookie;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "y#", &buffer, &bufsize)) {
|
||||
if (!PyArg_ParseTuple(args, "y*", &buffer)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -129,7 +128,7 @@ _decode(ImagingDecoderObject *decoder, PyObject *args) {
|
|||
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) {
|
||||
ImagingSectionLeave(&cookie);
|
||||
|
|
Loading…
Reference in New Issue
Block a user