[cairo-commit] 2 commits - src/cairo-pdf-surface.c src/cairo-ps-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun Apr 22 20:54:05 PDT 2012


 src/cairo-pdf-surface.c |   41 +++++++++++++++++++++++++++++++----------
 src/cairo-ps-surface.c  |   41 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 68 insertions(+), 14 deletions(-)

New commits:
commit abedc6b46ad283f896e078479174312cb87e6700
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Apr 23 13:20:47 2012 +0930

    ps: support all image types
    
    If the image is not rgb24/argb32/a8/a1, create a new image with the
    same CAIRO_CONTENT and paint image to the new image.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index f667400..d92029d 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -2353,7 +2353,7 @@ _cairo_ps_surface_emit_base85_string (cairo_ps_surface_t    *surface,
 
 static cairo_status_t
 _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
-			      cairo_image_surface_t *image,
+			      cairo_image_surface_t *image_surf,
 			      cairo_operator_t	     op,
 			      cairo_filter_t         filter,
 			      cairo_bool_t           stencil_mask)
@@ -2361,7 +2361,7 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
     cairo_status_t status;
     unsigned char *data;
     unsigned long data_size;
-    cairo_image_surface_t *ps_image = image;
+    cairo_image_surface_t *ps_image;
     int x, y, i, a;
     cairo_image_transparency_t transparency;
     cairo_bool_t use_mask;
@@ -2372,9 +2372,38 @@ _cairo_ps_surface_emit_image (cairo_ps_surface_t    *surface,
     const char *interpolate;
     cairo_ps_compress_t compress;
     const char *compress_filter;
+    cairo_image_surface_t *image;
 
-    if (image->base.status)
-	return image->base.status;
+    if (image_surf->base.status)
+	return image_surf->base.status;
+
+    image  = image_surf;
+    if (image->format != CAIRO_FORMAT_RGB24 &&
+	image->format != CAIRO_FORMAT_ARGB32 &&
+	image->format != CAIRO_FORMAT_A8 &&
+	image->format != CAIRO_FORMAT_A1)
+    {
+	cairo_surface_t *surf;
+	cairo_surface_pattern_t pattern;
+
+	surf = _cairo_image_surface_create_with_content (cairo_surface_get_content (&image_surf->base),
+							 image_surf->width,
+							 image_surf->height);
+	image = (cairo_image_surface_t *) surf;
+	if (surf->status) {
+	    status = surf->status;
+	    goto bail0;
+	}
+
+	_cairo_pattern_init_for_surface (&pattern, &image_surf->base);
+	status = _cairo_surface_paint (surf,
+				       CAIRO_OPERATOR_SOURCE, &pattern.base,
+				       NULL);
+        _cairo_pattern_fini (&pattern.base);
+        if (unlikely (status))
+            goto bail0;
+    }
+    ps_image = image;
 
     switch (filter) {
     default:
@@ -2697,6 +2726,10 @@ bail1:
     if (!use_mask && ps_image != image)
 	cairo_surface_destroy (&ps_image->base);
 
+bail0:
+    if (image != image_surf)
+	cairo_surface_destroy (&image->base);
+
     return status;
 }
 
commit 33f9e433eef13a2b39a8213c6997399f3a5896a8
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Mon Apr 23 13:07:18 2012 +0930

    pdf: support all image types
    
    If the image is not rgb24/argb32/a8/a1, create a new image with the
    same CAIRO_CONTENT and paint image to the new image.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index a0a20e8..3b65167 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -2323,7 +2323,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t	*surface,
  * can be used to reference the data in image_ret. */
 static cairo_status_t
 _cairo_pdf_surface_emit_image (cairo_pdf_surface_t     *surface,
-                               cairo_image_surface_t   *image,
+                               cairo_image_surface_t   *image_surf,
                                cairo_pdf_resource_t    *image_res,
 			       cairo_filter_t           filter,
 			       cairo_bool_t             stencil_mask)
@@ -2337,16 +2337,34 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t     *surface,
     cairo_bool_t need_smask;
     const char *interpolate = "true";
     cairo_image_color_t color;
+    cairo_image_surface_t *image;
 
-    /* These are the only image formats we currently support, (which
-     * makes things a lot simpler here). This is enforced through
-     * _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 ||
-	    image->format == CAIRO_FORMAT_A8 ||
-	    image->format == CAIRO_FORMAT_A1);
+    image  = image_surf;
+    if (image->format != CAIRO_FORMAT_RGB24 &&
+	image->format != CAIRO_FORMAT_ARGB32 &&
+	image->format != CAIRO_FORMAT_A8 &&
+	image->format != CAIRO_FORMAT_A1)
+    {
+	cairo_surface_t *surf;
+	cairo_surface_pattern_t pattern;
+
+	surf = _cairo_image_surface_create_with_content (cairo_surface_get_content (&image_surf->base),
+							 image_surf->width,
+							 image_surf->height);
+	image = (cairo_image_surface_t *) surf;
+	if (surf->status) {
+	    status = surf->status;
+	    goto CLEANUP;
+	}
+
+	_cairo_pattern_init_for_surface (&pattern, &image_surf->base);
+	status = _cairo_surface_paint (surf,
+				       CAIRO_OPERATOR_SOURCE, &pattern.base,
+				       NULL);
+        _cairo_pattern_fini (&pattern.base);
+        if (unlikely (status))
+            goto CLEANUP;
+    }
 
     switch (filter) {
     case CAIRO_FILTER_GOOD:
@@ -2497,6 +2515,9 @@ _cairo_pdf_surface_emit_image (cairo_pdf_surface_t     *surface,
 CLEANUP_RGB:
     free (data);
 CLEANUP:
+    if (image != image_surf)
+	cairo_surface_destroy (&image->base);
+
     return status;
 }
 


More information about the cairo-commit mailing list