Skip to content

Commit c6f24d3

Browse files
committed
Merge pull request matplotlib#3665 from jkseppan/fix-gdk-strides
BUG : Remove usage of raw strides member in _backend_gdk.c
2 parents 52b31c0 + b77b28a commit c6f24d3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/_backend_gdk.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args)
1717
GdkPixbuf *gdk_pixbuf;
1818
PyArrayObject *array;
1919
npy_intp dims[3] = { 0, 0, 3 };
20+
npy_intp strides[3];
2021

2122
if (!PyArg_ParseTuple(args, "O!:pixbuf_get_pixels_array", &PyGdkPixbuf_Type, &py_pixbuf))
2223
return NULL;
@@ -32,15 +33,21 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args)
3233
if (gdk_pixbuf_get_has_alpha(gdk_pixbuf))
3334
dims[2] = 4;
3435

35-
array = (PyArrayObject *)PyArray_SimpleNewFromData(
36-
3, dims, PyArray_UBYTE, (char *)gdk_pixbuf_get_pixels(gdk_pixbuf));
36+
strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf);
37+
strides[1] = dims[2];
38+
strides[2] = 1;
39+
40+
array = (PyArrayObject*)
41+
PyArray_New(&PyArray_Type, 3, dims, NPY_UBYTE, strides,
42+
(void*)gdk_pixbuf_get_pixels(gdk_pixbuf), 1,
43+
NPY_ARRAY_WRITEABLE, NULL);
44+
3745
if (array == NULL)
3846
return NULL;
3947

40-
array->strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf);
4148
/* the array holds a ref to the pixbuf pixels through this wrapper*/
4249
Py_INCREF(py_pixbuf);
43-
array->base = (PyObject *)py_pixbuf;
50+
PyArray_SetBaseObject(array, (PyObject *)py_pixbuf);
4451
return PyArray_Return(array);
4552
}
4653

0 commit comments

Comments
 (0)