Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f4ba0d

Browse files
committed
Remove usage of raw strides member in _backend_gdk.c
1 parent dbeed94 commit 8f4ba0d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/_backend_gdk.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pixbuf_get_pixels_array(PyObject *self, PyObject *args)
1919
GdkPixbuf *gdk_pixbuf;
2020
PyArrayObject *array;
2121
npy_intp dims[3] = { 0, 0, 3 };
22+
npy_intp strides[3];
2223

2324
if (!PyArg_ParseTuple(args, "O!:pixbuf_get_pixels_array",
2425
&PyGdkPixbuf_Type, &py_pixbuf))
@@ -35,12 +36,18 @@ pixbuf_get_pixels_array(PyObject *self, PyObject *args)
3536
if (gdk_pixbuf_get_has_alpha(gdk_pixbuf))
3637
dims[2] = 4;
3738

38-
array = (PyArrayObject *)PyArray_SimpleNewFromData(3, dims, NPY_UBYTE,
39-
(char *)gdk_pixbuf_get_pixels(gdk_pixbuf));
39+
strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf);
40+
strides[1] = dims[2];
41+
strides[2] = 1;
42+
43+
array = (PyArrayObject*)
44+
PyArray_New(&PyArray_Type, 3, dims, NPY_UBYTE, strides,
45+
(void*)gdk_pixbuf_get_pixels(gdk_pixbuf), 1,
46+
0, NULL);
47+
4048
if (array == NULL)
4149
return NULL;
4250

43-
array->strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf);
4451
/* the array holds a ref to the pixbuf pixels through this wrapper*/
4552
Py_INCREF(py_pixbuf);
4653
array->base = (PyObject *)py_pixbuf;

0 commit comments

Comments
 (0)