[cairo-commit] pycairo/cairo pycairo-surface.c,1.56,1.57

Steve Chaplin commit at pdx.freedesktop.org
Thu Sep 22 05:43:43 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv24805/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.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- pycairo-surface.c	25 Aug 2005 11:48:09 -0000	1.56
+++ pycairo-surface.c	22 Sep 2005 12:43:41 -0000	1.57
@@ -192,7 +192,8 @@
 
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
 static cairo_status_t
-pycairo_write_func (void *closure, unsigned char *data, unsigned int length)
+pycairo_write_func (void *closure, const unsigned char *data,
+		    unsigned int length)
 {
     if (fwrite (data, 1, (size_t) length, (FILE *)closure) != length)
 	return CAIRO_STATUS_WRITE_ERROR;
@@ -388,18 +389,21 @@
 }
 #endif /* HAVE_NUMPY */
 
-#if 0 /* disable until a reference to the buffer is added to the surface */
-/* alternative constructor */
 static PyObject *
 image_surface_create_for_data (PyTypeObject *type, PyObject *args)
 {
     cairo_surface_t *surface;
     cairo_format_t format;
-    char *data;
-    int length, width, height, stride = -1;
+    unsigned char *buffer;
+    int buffer_len, width, height, stride = -1, res;
+    PyObject *obj;
 
-    if (!PyArg_ParseTuple(args, "w#iii|i:Surface.create_for_data",
-			  &data, &length, &format, &width, &height, &stride))
+    if (!PyArg_ParseTuple(args, "Oiii|i:Surface.create_for_data",
+			  &obj, &format, &width, &height, &stride))
+	return NULL;
+
+    res = PyObject_AsWriteBuffer (obj, (void **)&buffer, &buffer_len);
+    if (res == -1)
 	return NULL;
 
     if (width <= 0) {
@@ -411,7 +415,7 @@
 	return NULL;
     }
     /* if stride is missing, calculate it from width */
-    if (stride < 0)
+    if (stride < 0) {
 	switch (format) {
 	case CAIRO_FORMAT_ARGB32:
 	    stride = width * 4;
@@ -426,18 +430,15 @@
 	    stride = (width + 1) / 8;
 	    break;
 	}
-    if (height * stride > length) {
+    }
+    if (height * stride > buffer_len) {
 	PyErr_SetString(PyExc_TypeError, "buffer is not long enough");
 	return NULL;
     }
-
-    surface = cairo_image_surface_create_for_data
-	((unsigned char *)data, format, width, height, stride);
-    return PycairoSurface_FromSurface(surface, &PycairoImageSurface_Type,
-				      NULL);
-    /* FIXME: get surface to hold a reference to buffer */
+    surface = cairo_image_surface_create_for_data (buffer, format, width,
+						   height, stride);
+    return PycairoSurface_FromSurface(surface, &PycairoImageSurface_Type, obj);
 }
-#endif
 
 
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
@@ -501,10 +502,8 @@
     {"create_for_array",(PyCFunction)image_surface_create_for_array,
                                                    METH_VARARGS | METH_CLASS },
 #endif
-#if 0
     {"create_for_data",(PyCFunction)image_surface_create_for_data,
                                                    METH_VARARGS | METH_CLASS },
-#endif
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
     {"create_from_png", (PyCFunction)image_surface_create_from_png,
                                                    METH_O | METH_CLASS },



More information about the cairo-commit mailing list