@@ -17,6 +17,7 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args)
17
17
GdkPixbuf * gdk_pixbuf ;
18
18
PyArrayObject * array ;
19
19
npy_intp dims [3 ] = { 0 , 0 , 3 };
20
+ npy_intp strides [3 ];
20
21
21
22
if (!PyArg_ParseTuple (args , "O!:pixbuf_get_pixels_array" , & PyGdkPixbuf_Type , & py_pixbuf ))
22
23
return NULL ;
@@ -32,15 +33,21 @@ static PyObject *pixbuf_get_pixels_array(PyObject *self, PyObject *args)
32
33
if (gdk_pixbuf_get_has_alpha (gdk_pixbuf ))
33
34
dims [2 ] = 4 ;
34
35
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
+
37
45
if (array == NULL )
38
46
return NULL ;
39
47
40
- array -> strides [0 ] = gdk_pixbuf_get_rowstride (gdk_pixbuf );
41
48
/* the array holds a ref to the pixbuf pixels through this wrapper*/
42
49
Py_INCREF (py_pixbuf );
43
- array -> base = (PyObject * )py_pixbuf ;
50
+ PyArray_SetBaseObject ( array , (PyObject * )py_pixbuf ) ;
44
51
return PyArray_Return (array );
45
52
}
46
53
0 commit comments