[cairo-commit] pycairo/cairo pycairo-surface.c,1.80,1.81

Steve Chaplin commit at pdx.freedesktop.org
Mon Nov 20 17:46:10 PST 2006


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory kemper:/tmp/cvs-serv29414/cairo

Modified Files:
	pycairo-surface.c 
Log Message:
'SC'

Index: pycairo-surface.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-surface.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- pycairo-surface.c	20 Nov 2006 11:20:59 -0000	1.80
+++ pycairo-surface.c	21 Nov 2006 01:46:07 -0000	1.81
@@ -544,7 +544,7 @@
 static PyObject *
 image_surface_get_data (PycairoImageSurface *o)
 {
-    return PyBuffer_FromReadWriteObject(o, 0, Py_END_OF_BUFFER);
+    return PyBuffer_FromReadWriteObject((PyObject *)o, 0, Py_END_OF_BUFFER);
 }
 
 static PyObject *
@@ -571,65 +571,8 @@
     return PyInt_FromLong (cairo_image_surface_get_stride (o->surface));
 }
 
-/* This was modified from cairo/src/cairo-png.c unpremultiply_data() */
-/* ARGB32 (native-endian, premultiplied) => RGBA */
-static void
-_argb32_to_unpremultiplied_rgba (uint8_t *data, int length)
-{
-    unsigned int i;
-
-    for (i = 0; i < length; i += 4) {
-        uint8_t *b = &data[i];
-        uint32_t pixel;
-        uint8_t  alpha;
-
-	memcpy (&pixel, b, sizeof (uint32_t));
-	alpha = (pixel & 0xff000000) >> 24;
-        if (alpha == 0) {
-	    b[0] = b[1] = b[2] = b[3] = 0;
-	} else {
-            b[0] = (((pixel & 0xff0000) >> 16) * 255 + alpha / 2) / alpha;
-            b[1] = (((pixel & 0x00ff00) >>  8) * 255 + alpha / 2) / alpha;
-            b[2] = (((pixel & 0x0000ff) >>  0) * 255 + alpha / 2) / alpha;
-	    b[3] = alpha;
-	}
-    }
-}
-
-/* return a Python buffer object containing the ImageSurface data in RGBA
- * format.
- */
-static PyObject *
-image_surface_get_data_as_rgba (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);
-
-    if (format != CAIRO_FORMAT_ARGB32) {
-	PyErr_SetString(PyExc_TypeError, "ImageSurface.to_rgba() can only be "
-			"called on a cairo.FORMAT_ARGB32 surface");
-	return NULL;
-    }
-    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);
-	_argb32_to_unpremultiplied_rgba (buffer, length);
-    }
-    return buf;
-}
 
+/* Buffer interface functions, used by ImageSurface.get_data() */
 static int
 image_surface_buffer_getreadbuf (PycairoImageSurface *o, int segment,
 				 const void **ptr)
@@ -699,8 +642,6 @@
     {"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_as_rgba",(PyCFunction)image_surface_get_data_as_rgba,
-                                                                 METH_NOARGS},
     {NULL, NULL, 0, NULL},
 };
 



More information about the cairo-commit mailing list