[cairo-commit] [cairo-www] src/cookbook

Chris Wilson ickle at freedesktop.org
Thu Jun 18 00:21:19 PDT 2009


 src/cookbook/blur.c |   28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

New commits:
commit ee70c3b94cb5498f8e98e10a4d8b327640f09ec9
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Jun 18 08:20:47 2009 +0100

    Handle A8 images within blur

diff --git a/src/cookbook/blur.c b/src/cookbook/blur.c
index 622ff86..1ed8798 100644
--- a/src/cookbook/blur.c
+++ b/src/cookbook/blur.c
@@ -28,7 +28,7 @@
 
 /* Performs a simple 2D Gaussian blur of radius @radius on surface @surface. */
 void
-blur_surface (cairo_surface_t *surface, int radius)
+blur_image_surface (cairo_surface_t *surface, int radius)
 {
     cairo_surface_t *tmp;
     int width, height;
@@ -47,12 +47,30 @@ blur_surface (cairo_surface_t *surface, int radius)
     width = cairo_image_surface_get_width (surface);
     height = cairo_image_surface_get_height (surface);
 
-    tmp = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
+    switch (cairo_image_surface_get_format (surface)) {
+    case CAIRO_FORMAT_A1:
+    default:
+	/* Don't even think about it! */
+	return;
+
+    case CAIRO_FORMAT_A8:
+	/* Handle a8 surfaces by effectively unrolling the loops by a
+	 * factor of 4 - this is safe since we know that stride has to be a
+	 * multiple of uint32_t. */
+	width /= 4;
+	break;
+
+    case CAIRO_FORMAT_RGB24:
+    case CAIRO_FORMAT_ARGB32:
+	break;
+    }
+
+    tmp = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
     if (cairo_surface_status (tmp))
 	return;
 
-    src_stride = cairo_image_surface_get_stride (surface);
     src = cairo_image_surface_get_data (surface);
+    src_stride = cairo_image_surface_get_stride (surface);
 
     dst = cairo_image_surface_get_data (tmp);
     dst_stride = cairo_image_surface_get_stride (tmp);
@@ -63,7 +81,7 @@ blur_surface (cairo_surface_t *surface, int radius)
 	a += kernel[i] = exp (- f * f / 30.0) * 80;
     }
 
-    /* horizontally blur from surface -> tmp */
+    /* Horizontally blur from surface -> tmp */
     for (i = 0; i < height; i++) {
 	s = (uint32_t *) (src + i * src_stride);
 	d = (uint32_t *) (dst + i * dst_stride);
@@ -89,7 +107,7 @@ blur_surface (cairo_surface_t *surface, int radius)
 	}
     }
 
-    /* then vertically blur from tmp -> surface */
+    /* Then vertically blur from tmp -> surface */
     for (i = 0; i < height; i++) {
 	s = (uint32_t *) (dst + i * dst_stride);
 	d = (uint32_t *) (src + i * src_stride);


More information about the cairo-commit mailing list