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

Skip to content

Commit 2cacc37

Browse files
committed
Remove usage of raw strides member in _backend_gdk.c
1 parent 52b31c0 commit 2cacc37

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
@@ -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,12 +33,18 @@ 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+
0, 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);
4350
array->base = (PyObject *)py_pixbuf;

0 commit comments

Comments
 (0)