[cairo-commit] 3 commits - test/pdiff test/rgb24-ignore-alpha.c
Chris Wilson
ickle at kemper.freedesktop.org
Tue Oct 16 08:06:21 PDT 2007
test/pdiff/lpyramid.c | 27 +++++++++++++++------------
test/pdiff/pdiff.c | 3 +++
test/rgb24-ignore-alpha.c | 2 ++
3 files changed, 20 insertions(+), 12 deletions(-)
New commits:
commit 5e09653e5dca60902423938737195e38ccde1b95
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Oct 16 15:30:50 2007 +0100
[test/rgb24-ignore-alpha] Destroy the surface after use.
Destroy the surface so that valgrind doesn't complain about the memory
leak.
diff --git a/test/rgb24-ignore-alpha.c b/test/rgb24-ignore-alpha.c
index bb5ec35..2739d26 100644
--- a/test/rgb24-ignore-alpha.c
+++ b/test/rgb24-ignore-alpha.c
@@ -55,6 +55,8 @@ draw (cairo_t *cr, int width, int height)
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
+ cairo_surface_destroy (surface);
+
return CAIRO_TEST_SUCCESS;
}
commit bd3dd72262772f1b2dfd8335630163f2e3bfacac
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Oct 16 15:29:59 2007 +0100
[pdiff] Reorganise the inner loops of the convolution.
Reorder the indices and introduce a couple of temporary accumulators to
improve cache access.
diff --git a/test/pdiff/lpyramid.c b/test/pdiff/lpyramid.c
index b81d67d..366b0e4 100644
--- a/test/pdiff/lpyramid.c
+++ b/test/pdiff/lpyramid.c
@@ -20,7 +20,7 @@
#include <string.h>
struct _lpyramid {
- /* Succesively blurred versions of the original image */
+ /* Successively blurred versions of the original image */
float *levels[MAX_PYR_LEVELS];
int width;
@@ -28,29 +28,32 @@ struct _lpyramid {
};
static void
-convolve (lpyramid_t *pyramid, float *a, float *b)
+convolve (lpyramid_t *pyramid, float *a, const float *b)
/* convolves image b with the filter kernel and stores it in a */
{
- int y,x,i,j,nx,ny;
+ int y,x,i,j;
const float Kernel[] = {0.05f, 0.25f, 0.4f, 0.25f, 0.05f};
int width = pyramid->width;
int height = pyramid->height;
for (y=0; y<height; y++) {
for (x=0; x<width; x++) {
- int index = y * width + x;
- a[index] = 0.0f;
- for (i=-2; i<=2; i++) {
- for (j=-2; j<=2; j++) {
- nx=x+i;
- ny=y+j;
+ float sum = 0.f;
+ for (j=-2; j<=2; j++) {
+ float sum_i = 0.f;
+ int ny=y+j;
+ if (ny<0) ny=-ny;
+ if (ny>=height) ny=2*height - ny - 1;
+ ny *= width;
+ for (i=-2; i<=2; i++) {
+ int nx=x+i;
if (nx<0) nx=-nx;
- if (ny<0) ny=-ny;
if (nx>=width) nx=2*width - nx - 1;
- if (ny>=height) ny=2*height - ny - 1;
- a[index] += Kernel[i+2] * Kernel[j+2] * b[ny * width + nx];
+ sum_i += Kernel[i+2] * b[ny + nx];
}
+ sum += sum_i * Kernel[j+2];
}
+ *a++ = sum;
}
}
}
commit fa9201b9c98b18ea18fbee1e5608f20335a02131
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Oct 16 15:27:33 2007 +0100
[pdiff] Check for too small images.
The Laplacian pyramid can only work on images larger than 3x3 due to the
size of its convolution kernel. So if the image is too small return an
error (-1) before attempting to construction the pyramid.
diff --git a/test/pdiff/pdiff.c b/test/pdiff/pdiff.c
index b75312d..4f3226d 100644
--- a/test/pdiff/pdiff.c
+++ b/test/pdiff/pdiff.c
@@ -286,6 +286,9 @@ pdiff_compare (cairo_surface_t *surface_a,
w = cairo_image_surface_get_width (surface_a);
h = cairo_image_surface_get_height (surface_a);
+ if (w < 3 || h < 3) /* too small for the Laplacian convolution */
+ return -1;
+
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
float r, g, b, l;
More information about the cairo-commit
mailing list