[cairo-commit] cairo/test .cvsignore, 1.4, 1.5 Makefile.am, 1.9, 1.10 buffer_diff.c, NONE, 1.1 buffer_diff.h, NONE, 1.1 cairo_test.c, 1.5, 1.6 imagediff.c, NONE, 1.1 write_png.c, 1.1, 1.2 write_png.h, 1.1, 1.2

Carl Worth commit at pdx.freedesktop.org
Tue Jan 25 14:45:33 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo/test
In directory gabe:/tmp/cvs-serv17954

Modified Files:
	.cvsignore Makefile.am cairo_test.c write_png.c write_png.h 
Added Files:
	buffer_diff.c buffer_diff.h imagediff.c 
Log Message:

        * test/imagediff.c
        * test/testsvg: Add new testsvg script and accompanying imagediff
        program, (for interim SVG-based test suites while we wait for the
        standard cairo test suite to mature).

        * test/buffer_diff.c:
        * test/cairo_test.c: Split buffer_diff out into its own file for
        the purpose of imagediff.


Index: .cvsignore
===================================================================
RCS file: /cvs/cairo/cairo/test/.cvsignore,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- .cvsignore	13 Jan 2005 22:50:35 -0000	1.4
+++ .cvsignore	25 Jan 2005 22:45:31 -0000	1.5
@@ -2,6 +2,7 @@
 .libs
 Makefile
 Makefile.in
+imagediff
 fill_rule
 leaky_polygon
 line_width

Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/cairo/test/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Makefile.am	19 Jan 2005 15:55:29 -0000	1.9
+++ Makefile.am	25 Jan 2005 22:45:31 -0000	1.10
@@ -42,6 +42,8 @@
 AM_LDFLAGS = $(CAIRO_LIBS) ../src/libcairo.la
 
 cairo_test_lib =\
+buffer_diff.c	\
+buffer_diff.h	\
 cairo_test.c	\
 cairo_test.h	\
 read_png.c	\
@@ -61,4 +63,7 @@
 text_cache_crash_SOURCES = text_cache_crash.c $(cairo_test_lib)
 text_rotate_SOURCES = text_rotate.c $(cairo_test_lib)
 
+noinst_PROGRAMS = imagediff
+imagediff_SOURCES = imagediff.c $(cairo_test_lib)
+
 CLEANFILES = *-out.png *-diff.png

--- NEW FILE: buffer_diff.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: buffer_diff.h ---
(This appears to be a binary file; contents omitted.)

Index: cairo_test.c
===================================================================
RCS file: /cvs/cairo/cairo/test/cairo_test.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cairo_test.c	21 Jan 2005 04:45:38 -0000	1.5
+++ cairo_test.c	25 Jan 2005 22:45:31 -0000	1.6
@@ -32,6 +32,7 @@
 
 #include "cairo_test.h"
 
+#include "buffer_diff.h"
 #include "read_png.h"
 #include "write_png.h"
 #include "xmalloc.h"
@@ -56,53 +57,6 @@
     }
 }
 
-/* Image comparison code courttesy of Richard Worth.
- * Returns number of pixels changed.
- * Also fills out a "diff" image intended to visually show where the
- * images differ.
- */
-static int
-image_diff (char *buf_a, char *buf_b, char *buf_diff,
-	    int width, int height, int stride)
-{
-    int x, y;
-    int total_pixels_changed = 0;
-    unsigned char *row_a, *row_b, *row;
-
-    for (y = 0; y < height; y++)
-    {
-	row_a = buf_a + y * stride;
-	row_b = buf_b + y * stride;
-	row = buf_diff + y * stride;
-	for (x = 0; x < width; x++)
-	{
-	    int channel;
-	    unsigned char value_a, value_b;
-	    int pixel_changed = 0;
-	    for (channel = 0; channel < 4; channel++)
-	    {
-		double diff;
-		value_a = row_a[x * 4 + channel];
-		value_b = row_b[x * 4 + channel];
-		if (value_a != value_b)
-		    pixel_changed = 1;
-		diff = value_a - value_b;
-		row[x * 4 + channel] = 128 + diff / 3.0;
-	    }
-	    if (pixel_changed) {
-		total_pixels_changed++;
-	    } else {
-		row[x*4+0] = 0;
-		row[x*4+1] = 0;
-		row[x*4+2] = 0;
-	    }
-	    row[x * 4 + 3] = 0xff; /* Set ALPHA to 100% (opaque) */
-	}
-    }
-
-    return total_pixels_changed;
-}
-
 cairo_test_status_t
 cairo_test (cairo_test_t *test, cairo_test_draw_function_t draw)
 {
@@ -115,6 +69,7 @@
     int ref_width, ref_height, ref_stride;
     read_png_status_t png_status;
     cairo_test_status_t ret;
+    FILE *png_file;
 
     /* The cairo part of the test is the easiest part */
     cr = cairo_create ();
@@ -146,7 +101,9 @@
     xasprintf (&ref_name, "%s/%s%s", srcdir, test->name, CAIRO_TEST_REF_SUFFIX);
     xasprintf (&diff_name, "%s%s", test->name, CAIRO_TEST_DIFF_SUFFIX);
 
-    write_png_argb32 (png_buf, png_name, test->width, test->height, stride);
+    png_file = fopen (png_name, "w");
+    write_png_argb32 (png_buf, png_file, test->width, test->height, stride);
+    fclose (png_file);
 
     ref_buf = NULL;
     png_status = (read_png_argb32 (ref_name, &ref_buf, &ref_width, &ref_height, &ref_stride));
@@ -178,12 +135,14 @@
 	goto BAIL;
     }
 
-    pixels_changed = image_diff (png_buf, ref_buf, diff_buf,
-				 test->width, test->height, stride);
+    pixels_changed = buffer_diff (png_buf, ref_buf, diff_buf,
+				  test->width, test->height, stride);
     if (pixels_changed) {
 	fprintf (stderr, "  Error: %d pixels differ from reference image %s\n",
 		 pixels_changed, ref_name);
-	write_png_argb32 (diff_buf, diff_name, test->width, test->height, stride);
+	png_file = fopen (diff_name, "w");
+	write_png_argb32 (diff_buf, png_file, test->width, test->height, stride);
+	fclose (png_file);
 	ret = CAIRO_TEST_FAILURE;
 	goto BAIL;
     } else {

--- NEW FILE: imagediff.c ---
(This appears to be a binary file; contents omitted.)

Index: write_png.c
===================================================================
RCS file: /cvs/cairo/cairo/test/write_png.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- write_png.c	26 Oct 2004 21:38:43 -0000	1.1
+++ write_png.c	25 Jan 2005 22:45:31 -0000	1.2
@@ -55,17 +55,15 @@
 }
 
 void
-write_png_argb32 (char *buffer, char *filename,
+write_png_argb32 (char *buffer, FILE *file,
 		  int width, int height, int stride)
 {
-    FILE *f;
     int i;
     png_struct *png;
     png_info *info;
     png_byte **rows;
     png_color_16 white;
     
-    f = fopen (filename, "w");
     rows = malloc (height * sizeof(png_byte*));
 
     for (i = 0; i < height; i++) {
@@ -75,7 +73,7 @@
     png = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
     info = png_create_info_struct (png);
 
-    png_init_io (png, f);
+    png_init_io (png, file);
     png_set_IHDR (png, info,
 		  width, height, 8,
 		  PNG_COLOR_TYPE_RGB_ALPHA, 
@@ -98,5 +96,4 @@
     png_destroy_write_struct (&png, &info);
 
     free (rows);
-    fclose (f);
 }

Index: write_png.h
===================================================================
RCS file: /cvs/cairo/cairo/test/write_png.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- write_png.h	26 Oct 2004 21:38:43 -0000	1.1
+++ write_png.h	25 Jan 2005 22:45:31 -0000	1.2
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2003 USC, Information Sciences Institute
+ * Copyright © 2003 USC, Information Sciences Institute
  *
  * Permission to use, copy, modify, distribute, and sell this software
  * and its documentation for any purpose is hereby granted without
@@ -29,7 +29,7 @@
 #define WRITE_PNG_H
 
 void
-write_png_argb32 (char *buffer, char *filename,
+write_png_argb32 (char *buffer, FILE * file,
 		  int width, int height, int stride);
 
 #endif




More information about the cairo-commit mailing list