From 2cacc373c98225f30029c2066acb18b62d1fd9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Seppa=CC=88nen?= Date: Fri, 17 Oct 2014 23:28:41 +0300 Subject: [PATCH 1/2] Remove usage of raw strides member in _backend_gdk.c --- src/_backend_gdk.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/_backend_gdk.c b/src/_backend_gdk.c index 9ccc3c5f0acb..c36489b4dcf1 100644 --- a/src/_backend_gdk.c +++ b/src/_backend_gdk.c @@ -17,6 +17,7 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args) GdkPixbuf *gdk_pixbuf; PyArrayObject *array; npy_intp dims[3] = { 0, 0, 3 }; + npy_intp strides[3]; if (!PyArg_ParseTuple(args, "O!:pixbuf_get_pixels_array", &PyGdkPixbuf_Type, &py_pixbuf)) return NULL; @@ -32,12 +33,18 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args) if (gdk_pixbuf_get_has_alpha(gdk_pixbuf)) dims[2] = 4; - array = (PyArrayObject *)PyArray_SimpleNewFromData( - 3, dims, PyArray_UBYTE, (char *)gdk_pixbuf_get_pixels(gdk_pixbuf)); + strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf); + strides[1] = dims[2]; + strides[2] = 1; + + array = (PyArrayObject*) + PyArray_New(&PyArray_Type, 3, dims, NPY_UBYTE, strides, + (void*)gdk_pixbuf_get_pixels(gdk_pixbuf), 1, + 0, NULL); + if (array == NULL) return NULL; - array->strides[0] = gdk_pixbuf_get_rowstride(gdk_pixbuf); /* the array holds a ref to the pixbuf pixels through this wrapper*/ Py_INCREF(py_pixbuf); array->base = (PyObject *)py_pixbuf; From b77b28a909ebb7e0d797a0266f61baf2d905b7f6 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 17 Oct 2014 17:15:00 -0400 Subject: [PATCH 2/2] Fix _backend_gdk.c --- src/_backend_gdk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_backend_gdk.c b/src/_backend_gdk.c index c36489b4dcf1..b0e1a3f812fd 100644 --- a/src/_backend_gdk.c +++ b/src/_backend_gdk.c @@ -40,14 +40,14 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args) array = (PyArrayObject*) PyArray_New(&PyArray_Type, 3, dims, NPY_UBYTE, strides, (void*)gdk_pixbuf_get_pixels(gdk_pixbuf), 1, - 0, NULL); + NPY_ARRAY_WRITEABLE, NULL); if (array == NULL) return NULL; /* the array holds a ref to the pixbuf pixels through this wrapper*/ Py_INCREF(py_pixbuf); - array->base = (PyObject *)py_pixbuf; + PyArray_SetBaseObject(array, (PyObject *)py_pixbuf); return PyArray_Return(array); }