[cairo-commit] 2 commits - boilerplate/cairo-boilerplate.c src/cairo.h src/cairo-png.c src/cairo-surface.c src/cairo-types-private.h test/any2ppm.c test/mime-data.c test/pdf-mime-data.c util/cairo-trace

Chris Wilson ickle at kemper.freedesktop.org
Fri Nov 7 11:35:53 PST 2008


 boilerplate/cairo-boilerplate.c |    2 ++
 src/cairo-png.c                 |    3 ++-
 src/cairo-surface.c             |    9 ++++++---
 src/cairo-types-private.h       |    1 +
 src/cairo.h                     |   11 ++++++-----
 test/any2ppm.c                  |   14 +++++++++-----
 test/mime-data.c                |    3 ++-
 test/pdf-mime-data.c            |    4 +++-
 util/cairo-trace/trace.c        |    6 ++++--
 9 files changed, 35 insertions(+), 18 deletions(-)

New commits:
commit cd2e18ddc65959a736fc7b7f6bbd3e76af0495a9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 7 18:35:39 2008 +0000

    [test] Fix-up rgb byte packing
    
    Another embarrassing, but thankfully, trivial bug.

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 50f9f39..b12b6d6 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -990,6 +990,8 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file)
 	    for (x = 0; x < width; x++) {
 		if (! freadn (buf, 3, file))
 		    goto FAIL;
+		*(uint32_t *) buf =
+		    (buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0);
 		buf += 4;
 	    }
 	    break;
diff --git a/test/any2ppm.c b/test/any2ppm.c
index 94450b2..85c1bdb 100644
--- a/test/any2ppm.c
+++ b/test/any2ppm.c
@@ -184,26 +184,30 @@ write_ppm (cairo_surface_t *surface, int fd)
 
     len = sprintf (buf, "%s %d %d 255\n", format_str, width, height);
     for (j = 0; j < height; j++) {
-	const unsigned char *row = data + stride * j;
+	const unsigned int *row = (unsigned int *) (data + stride * j);
 
 	switch ((int) format) {
 	case CAIRO_FORMAT_ARGB32:
 	    len = _write (fd,
 			  buf, sizeof (buf), len,
-			  row, 4 * width);
+			  (unsigned char *) row, 4 * width);
 	    break;
 	case CAIRO_FORMAT_RGB24:
 	    for (i = 0; i < width; i++) {
+		unsigned char rgb[3];
+		unsigned int p = *row++;
+		rgb[0] = (p & 0xff0000) >> 16;
+		rgb[1] = (p & 0x00ff00) >> 8;
+		rgb[2] = (p & 0x0000ff) >> 0;
 		len = _write (fd,
 			      buf, sizeof (buf), len,
-			      row, 3);
-		row += 4;
+			      rgb, 3);
 	    }
 	    break;
 	case CAIRO_FORMAT_A8:
 	    len = _write (fd,
 			  buf, sizeof (buf), len,
-			  row, width);
+			  (unsigned char *) row, width);
 	    break;
 	}
 	if (len < 0)
commit 2554d1759835a174b89107808d81d044c3e2e098
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 7 13:26:46 2008 +0000

    [surface] Pass a separate closure for the mime-type destroy notifier.
    
    A limitation of the current API was that the destroy notifier was called
    on the mime-data block. This prevents the user from passing in a pointer
    to a managed block, for example a mime-data block belonging to a
    ref-counted object. We can overcome this by allowing the user to specify
    the closure to be used with the destroy notifier.

diff --git a/src/cairo-png.c b/src/cairo-png.c
index a130ba2..e8f61b5 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -662,7 +662,8 @@ read_png (struct png_read_closure_t *png_closure)
 					  CAIRO_MIME_TYPE_PNG,
 					  mime_data,
 					  mime_data_length,
-					  free);
+					  free,
+					  mime_data);
     if (status) {
 	free (mime_data);
 	cairo_surface_destroy (surface);
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 9df75ca..c419bd5 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -640,8 +640,8 @@ _cairo_mime_data_destroy (void *ptr)
     if (! _cairo_reference_count_dec_and_test (&mime_data->ref_count))
 	return;
 
-    if (mime_data->destroy && mime_data->data)
-	mime_data->destroy (mime_data->data);
+    if (mime_data->destroy && mime_data->closure)
+	mime_data->destroy (mime_data->closure);
 
     free (mime_data);
 }
@@ -655,6 +655,7 @@ _cairo_mime_data_destroy (void *ptr)
  * @destroy: a #cairo_destroy_func_t which will be called when the
  * surface is destroyed or when new image data is attached using the
  * same mime type.
+ * @closure: the data to be passed to the @destroy notifier
  *
  * Attach an image in the format @mime_type to @surface. To remove
  * the data from a surface, call this function with same mime type
@@ -670,7 +671,8 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
                              const char			*mime_type,
                              const unsigned char	*data,
                              unsigned int		 length,
-			     cairo_destroy_func_t	 destroy)
+			     cairo_destroy_func_t	 destroy,
+			     void			*closure)
 {
     cairo_status_t status;
     cairo_mime_data_t *mime_data;
@@ -692,6 +694,7 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 	mime_data->data = (unsigned char *) data;
 	mime_data->length = length;
 	mime_data->destroy = destroy;
+	mime_data->closure = closure;
     } else
 	mime_data = NULL;
 
diff --git a/src/cairo-types-private.h b/src/cairo-types-private.h
index 30180b0..77f8184 100644
--- a/src/cairo-types-private.h
+++ b/src/cairo-types-private.h
@@ -349,6 +349,7 @@ struct _cairo_mime_data {
     unsigned char *data;
     unsigned int length;
     cairo_destroy_func_t destroy;
+    void *closure;
 };
 
 #endif /* CAIRO_TYPES_PRIVATE_H */
diff --git a/src/cairo.h b/src/cairo.h
index cbc109f..27d56f5 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -1957,11 +1957,12 @@ cairo_surface_get_mime_data (cairo_surface_t		*surface,
                              unsigned int		*length);
 
 cairo_public cairo_status_t
-cairo_surface_set_mime_data (cairo_surface_t		 *surface,
-                             const char			 *mime_type,
-                             const unsigned char         *data,
-                             unsigned int                 length,
-			     cairo_destroy_func_t	  destroy);
+cairo_surface_set_mime_data (cairo_surface_t		*surface,
+                             const char			*mime_type,
+                             const unsigned char	*data,
+                             unsigned int		 length,
+			     cairo_destroy_func_t	 destroy,
+			     void			*closure);
 
 cairo_public void
 cairo_surface_get_font_options (cairo_surface_t      *surface,
diff --git a/test/mime-data.c b/test/mime-data.c
index 87fe74c..ec855f8 100644
--- a/test/mime-data.c
+++ b/test/mime-data.c
@@ -96,7 +96,8 @@ paint_file (cairo_t *cr,
     image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 200, 50);
 
     status = cairo_surface_set_mime_data (image, mime_type,
-					  mime_data, mime_length, free);
+					  mime_data, mime_length,
+					  free, mime_data);
     if (status) {
 	cairo_surface_destroy (image);
 	return cairo_test_status_from_status (ctx, status);
diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c
index c949335..233374d 100644
--- a/test/pdf-mime-data.c
+++ b/test/pdf-mime-data.c
@@ -106,7 +106,9 @@ preamble (cairo_test_context_t *ctx)
 	return test_status;
     }
 
-    cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JPEG, data, len, free);
+    cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JPEG,
+				 data, len,
+				 free, data);
     width = cairo_image_surface_get_width (image);
     height = cairo_image_surface_get_height (image);
 
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index df2ec5c..03f7c5e 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -2771,7 +2771,8 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
                              const char			*mime_type,
                              const unsigned char	*data,
                              unsigned int		 length,
-			     cairo_destroy_func_t	 destroy)
+			     cairo_destroy_func_t	 destroy,
+			     void			*closure)
 {
     if (surface != NULL && _write_lock ()) {
 	_emit_surface (surface);
@@ -2787,7 +2788,8 @@ cairo_surface_set_mime_data (cairo_surface_t		*surface,
 		   surface,
 		   mime_type,
 		   data, length,
-		   destroy);
+		   destroy,
+		   closure);
 }
 
 cairo_status_t


More information about the cairo-commit mailing list