--- /tmp/pycairo-surface.c 2006-07-02 23:58:14.000000000 -0300 +++ pycairo-surface.c 2007-02-22 03:52:29.000000000 -0300 @@ -624,6 +624,34 @@ return buf; } +/* return a Python buffer object containing the ImageSurface data. + */ +static PyObject * +image_surface_get_data (PycairoImageSurface *o) +{ + PyObject *buf; + unsigned char *data; + uint8_t *buffer; + int height, stride, length; + cairo_surface_t *surface = o->surface; + cairo_format_t format = cairo_image_surface_get_format (surface); + + data = cairo_image_surface_get_data (surface); + height = cairo_image_surface_get_height (surface); + stride = cairo_image_surface_get_stride (surface); + + buf = PyBuffer_New(height * stride); + if (buf != NULL) { + if (PyObject_AsWriteBuffer(buf, (void **)&buffer, &length)) { + Py_DECREF(buf); + return NULL; + } + memcpy (buffer, data, length); + } + return buf; +} + + static PyMethodDef image_surface_methods[] = { #ifdef HAVE_NUMPY {"create_for_array",(PyCFunction)image_surface_create_for_array, @@ -639,6 +667,7 @@ {"get_height", (PyCFunction)image_surface_get_height, METH_NOARGS}, {"get_width", (PyCFunction)image_surface_get_width, METH_NOARGS}, {"get_stride", (PyCFunction)image_surface_get_stride, METH_NOARGS}, + {"get_data", (PyCFunction)image_surface_get_data, METH_NOARGS}, {"get_data_as_rgba",(PyCFunction)image_surface_get_data_as_rgba, METH_NOARGS}, {NULL, NULL, 0, NULL},