[cairo-commit] src/cairo-pdf-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Thu Sep 20 06:23:04 PDT 2007


 src/cairo-pdf-surface.c |   42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)

New commits:
diff-tree 12b2ab630c2343c7bd7d885cc0e773023e3d8fa8 (from 8a4adcf5f3c893505a53882a0532a220f79f4409)
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Sep 20 22:51:39 2007 +0930

    PDF: Add support for CAIRO_FORMAT_A8 images

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 48b24f2..ba631aa 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1159,13 +1159,15 @@ _cairo_pdf_surface_emit_smask (cairo_pdf
     cairo_status_t status = CAIRO_STATUS_SUCCESS;
     char *alpha, *alpha_compressed;
     unsigned long alpha_size, alpha_compressed_size;
-    uint32_t *pixel;
+    uint32_t *pixel32;
+    uint8_t *pixel8;
     int i, x, y;
     cairo_bool_t opaque;
     uint8_t a;
 
     /* This is the only image format we support, which simplfies things. */
-    assert (image->format == CAIRO_FORMAT_ARGB32);
+    assert (image->format == CAIRO_FORMAT_ARGB32 ||
+	    image->format == CAIRO_FORMAT_A8 );
 
     alpha_size = image->height * image->width;
     alpha = malloc (alpha_size);
@@ -1177,13 +1179,24 @@ _cairo_pdf_surface_emit_smask (cairo_pdf
     opaque = TRUE;
     i = 0;
     for (y = 0; y < image->height; y++) {
-	pixel = (uint32_t *) (image->data + y * image->stride);
+	if (image->format == CAIRO_FORMAT_ARGB32) {
+	    pixel32 = (uint32_t *) (image->data + y * image->stride);
 
-	for (x = 0; x < image->width; x++, pixel++) {
-	    a = (*pixel & 0xff000000) >> 24;
-	    alpha[i++] = a;
-	    if (a != 0xff)
-		opaque = FALSE;
+	    for (x = 0; x < image->width; x++, pixel32++) {
+		a = (*pixel32 & 0xff000000) >> 24;
+		alpha[i++] = a;
+		if (a != 0xff)
+		    opaque = FALSE;
+	    }
+	} else {
+	    pixel8 = (uint8_t *) (image->data + y * image->stride);
+
+	    for (x = 0; x < image->width; x++, pixel8++) {
+		a = *pixel8;
+		alpha[i++] = a;
+		if (a != 0xff)
+		    opaque = FALSE;
+	    }
 	}
     }
 
@@ -1245,7 +1258,9 @@ _cairo_pdf_surface_emit_image (cairo_pdf
      * _cairo_pdf_surface_analyze_operation which only accept source surfaces of
      * CONTENT_COLOR or CONTENT_COLOR_ALPHA.
      */
-    assert (image->format == CAIRO_FORMAT_RGB24 || image->format == CAIRO_FORMAT_ARGB32);
+    assert (image->format == CAIRO_FORMAT_RGB24 ||
+	    image->format == CAIRO_FORMAT_ARGB32 ||
+	    image->format == CAIRO_FORMAT_A8);
 
     rgb_size = image->height * image->width * 3;
     rgb = malloc (rgb_size);
@@ -1276,10 +1291,14 @@ _cairo_pdf_surface_emit_image (cairo_pdf
 		    rgb[i++] = (((*pixel & 0x00ff00) >>  8) * 255 + a / 2) / a;
 		    rgb[i++] = (((*pixel & 0x0000ff) >>  0) * 255 + a / 2) / a;
 		}
-	    } else {
+	    } else if (image->format == CAIRO_FORMAT_RGB24) {
 		rgb[i++] = (*pixel & 0x00ff0000) >> 16;
 		rgb[i++] = (*pixel & 0x0000ff00) >>  8;
 		rgb[i++] = (*pixel & 0x000000ff) >>  0;
+	    } else {
+		rgb[i++] = 0;
+		rgb[i++] = 0;
+		rgb[i++] = 0;
 	    }
 	}
     }
@@ -1291,7 +1310,8 @@ _cairo_pdf_surface_emit_image (cairo_pdf
     }
 
     need_smask = FALSE;
-    if (image->format == CAIRO_FORMAT_ARGB32) {
+    if (image->format == CAIRO_FORMAT_ARGB32 ||
+	image->format == CAIRO_FORMAT_A8) {
 	status = _cairo_pdf_surface_emit_smask (surface, image, &smask);
 	if (status)
 	    goto CLEANUP_COMPRESSED;


More information about the cairo-commit mailing list