[cairo-commit] Branch '1.8' - 2 commits - src/cairo-pattern.c test/any2ppm.c

Chris Wilson ickle at kemper.freedesktop.org
Wed Jun 3 14:50:01 PDT 2009


 src/cairo-pattern.c |    2 +-
 test/any2ppm.c      |   30 +++++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 8 deletions(-)

New commits:
commit a52f4cea1f94a6dc363c98f96327d700503b4d08
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 3 22:48:31 2009 +0100

    [test] Ensure ppm are in correct byte orientation.
    
    Correct the image conversion failures on big-endian architectures.

diff --git a/test/any2ppm.c b/test/any2ppm.c
index 94450b2..3b590d9 100644
--- a/test/any2ppm.c
+++ b/test/any2ppm.c
@@ -160,7 +160,24 @@ write_ppm (cairo_surface_t *surface, int fd)
     int width, height, stride;
     int i, j;
 
+    data = cairo_image_surface_get_data (surface);
+    height = cairo_image_surface_get_height (surface);
+    width = cairo_image_surface_get_width (surface);
+    stride = cairo_image_surface_get_stride (surface);
     format = cairo_image_surface_get_format (surface);
+    if (format == CAIRO_FORMAT_ARGB32) {
+	/* see if we can convert to a standard ppm type and trim a few bytes */
+	const unsigned char *alpha = data;
+	for (j = height; j--; alpha += stride) {
+	    for (i = 0; i < width; i++) {
+		if ((*(unsigned int *) (alpha+4*i) & 0xff000000) != 0xff000000)
+		    goto done;
+	    }
+	}
+	format = CAIRO_FORMAT_RGB24;
+ done: ;
+    }
+
     switch (format) {
     case CAIRO_FORMAT_ARGB32:
 	/* XXX need true alpha for svg */
@@ -177,11 +194,6 @@ write_ppm (cairo_surface_t *surface, int fd)
 	return "unhandled image format";
     }
 
-    data = cairo_image_surface_get_data (surface);
-    height = cairo_image_surface_get_height (surface);
-    width = cairo_image_surface_get_width (surface);
-    stride = cairo_image_surface_get_stride (surface);
-
     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;
@@ -194,10 +206,14 @@ write_ppm (cairo_surface_t *surface, int fd)
 	    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:
commit 018275c95303c823bea0b52e95cb77c9cbe52090
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jun 3 20:17:59 2009 +0100

    [pattern] Typo in document
    
    Remove extraneous markup from program-listing.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=20441

diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 81fa62a..bd3ed93 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1094,7 +1094,7 @@ cairo_pattern_get_matrix (cairo_pattern_t *pattern, cairo_matrix_t *matrix)
  *
  * <informalexample><programlisting>
  * cairo_set_source_surface (cr, image, x, y);
- * cairo_pattern_set_filter (cairo_get_source (cr), %CAIRO_FILTER_NEAREST);
+ * cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
  * </programlisting></informalexample>
  **/
 void


More information about the cairo-commit mailing list