Skip to content

Commit

Permalink
Added ability to pass memoryview object to ImageDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Feb 10, 2023
1 parent 4ab4bfe commit c7aceff
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,24 @@ _dealloc(ImagingDecoderObject *decoder) {

static PyObject *
_decode(ImagingDecoderObject *decoder, PyObject *args) {
PyObject *input_object, *memview = NULL;
Py_buffer *memview_buf;
UINT8 *buffer;
Py_ssize_t bufsize;
int status;
ImagingSectionCookie cookie;

if (!PyArg_ParseTuple(args, "y#", &buffer, &bufsize)) {
if (!PyArg_ParseTuple(args, "O", &input_object)) {
return NULL;
}

if (PyMemoryView_Check(input_object)) {
memview = PyMemoryView_FromObject(input_object);
memview_buf = PyMemoryView_GET_BUFFER(memview);
buffer = memview_buf->buf;
bufsize = memview_buf->len;
}
else if (!PyArg_ParseTuple(args, "y#", &buffer, &bufsize)) {
return NULL;
}

Expand All @@ -135,6 +147,7 @@ _decode(ImagingDecoderObject *decoder, PyObject *args) {
ImagingSectionLeave(&cookie);
}

Py_XDECREF(memview);
return Py_BuildValue("ii", status, decoder->state.errcode);
}

Expand Down

0 comments on commit c7aceff

Please sign in to comment.