summaryrefslogtreecommitdiff
path: root/test/buffer-diff.c
diff options
context:
space:
mode:
authorVladimir Vukicevic <vladimir@pobox.com>2006-02-15 13:46:52 -0800
committerCarl Worth <cworth@cworth.org>2006-05-03 23:42:45 -0700
commitb3e2252b94297b7fbdbd3a3776781ea6df7c8bc6 (patch)
treecda8fb5fdc5d631777e2ab145b8d416339cdbe50 /test/buffer-diff.c
parent7beb3e27a552c724bbdb147bc27b775af0d61063 (diff)
downloadcairo-b3e2252b94297b7fbdbd3a3776781ea6df7c8bc6.tar.gz
Augment test framework to test everything under device offsets as well.
[With this change, two tests with gradients exhibit subtle differences under device offsets. I don't think we actually care about them though. -cworth]
Diffstat (limited to 'test/buffer-diff.c')
-rw-r--r--test/buffer-diff.c98
1 files changed, 70 insertions, 28 deletions
diff --git a/test/buffer-diff.c b/test/buffer-diff.c
index dd1b7c664..c62c44ef4 100644
--- a/test/buffer-diff.c
+++ b/test/buffer-diff.c
@@ -62,7 +62,9 @@ buffer_diff_core (unsigned char *_buf_a,
unsigned char *_buf_diff,
int width,
int height,
- int stride,
+ int stride_a,
+ int stride_b,
+ int stride_diff,
pixman_bits_t mask)
{
int x, y;
@@ -72,12 +74,14 @@ buffer_diff_core (unsigned char *_buf_a,
pixman_bits_t *buf_b = (pixman_bits_t*)_buf_b;
pixman_bits_t *buf_diff = (pixman_bits_t*)_buf_diff;
- stride /= sizeof(pixman_bits_t);
+ stride_a /= sizeof(pixman_bits_t);
+ stride_b /= sizeof(pixman_bits_t);
+ stride_diff /= sizeof(pixman_bits_t);
for (y = 0; y < height; y++)
{
- row_a = buf_a + y * stride;
- row_b = buf_b + y * stride;
- row = buf_diff + y * stride;
+ row_a = buf_a + y * stride_a;
+ row_b = buf_b + y * stride_b;
+ row = buf_diff + y * stride_diff;
for (x = 0; x < width; x++)
{
/* check if the pixels are the same */
@@ -112,9 +116,12 @@ buffer_diff (unsigned char *buf_a,
unsigned char *buf_diff,
int width,
int height,
- int stride)
+ int stride_a,
+ int stride_b,
+ int stride_diff)
{
- return buffer_diff_core(buf_a, buf_b, buf_diff, width, height, stride, 0xffffffff);
+ return buffer_diff_core(buf_a, buf_b, buf_diff,
+ width, height, stride_a, stride_b, stride_diff, 0xffffffff);
}
int
@@ -123,9 +130,12 @@ buffer_diff_noalpha (unsigned char *buf_a,
unsigned char *buf_diff,
int width,
int height,
- int stride)
+ int stride_a,
+ int stride_b,
+ int stride_diff)
{
- return buffer_diff_core(buf_a, buf_b, buf_diff, width, height, stride, 0x00ffffff);
+ return buffer_diff_core(buf_a, buf_b, buf_diff,
+ width, height, stride_a, stride_b, stride_diff, 0x00ffffff);
}
/* Image comparison code courtesy of Richard Worth <richard@theworths.org>
@@ -136,11 +146,16 @@ buffer_diff_noalpha (unsigned char *buf_a,
int
image_diff (const char *filename_a,
const char *filename_b,
- const char *filename_diff)
+ const char *filename_diff,
+ int ax,
+ int ay,
+ int bx,
+ int by)
{
int pixels_changed;
unsigned int width_a, height_a, stride_a;
unsigned int width_b, height_b, stride_b;
+ unsigned int stride_diff;
unsigned char *buf_a, *buf_b, *buf_diff;
read_png_status_t status;
@@ -154,9 +169,13 @@ image_diff (const char *filename_a,
return -1;
}
+ width_a -= ax;
+ height_a -= ay;
+ width_b -= bx;
+ height_b -= by;
+
if (width_a != width_b ||
- height_a != height_b ||
- stride_a != stride_b)
+ height_a != height_b)
{
cairo_test_log ("Error: Image size mismatch: (%dx%d@%d) vs. (%dx%d@%d)\n"
" for %s vs. %s\n",
@@ -168,17 +187,27 @@ image_diff (const char *filename_a,
return -1;
}
- buf_diff = xcalloc (stride_a * height_a, 1);
+ stride_diff = 4 * width_a;
+ buf_diff = xcalloc (stride_diff * height_a, 1);
- pixels_changed = buffer_diff (buf_a, buf_b, buf_diff,
- width_a, height_a, stride_a);
+ pixels_changed = buffer_diff (buf_a + (ay * stride_a) + ax * 4,
+ buf_b + (by * stride_b) + by * 4,
+ buf_diff,
+ width_a, height_a,
+ stride_a, stride_b, stride_diff);
if (pixels_changed) {
- FILE *png_file = fopen (filename_diff, "wb");
- write_png_argb32 (buf_diff, png_file, width_a, height_a, stride_a);
- fclose (png_file);
+ FILE *png_file;
+ if (filename_diff)
+ png_file = fopen (filename_diff, "wb");
+ else
+ png_file = stdout;
+ write_png_argb32 (buf_diff, png_file, width_a, height_a, stride_diff);
+ if (png_file != stdout)
+ fclose (png_file);
} else {
- xunlink (filename_diff);
+ if (filename_diff)
+ xunlink (filename_diff);
}
free (buf_a);
@@ -204,7 +233,11 @@ image_diff (const char *filename_a,
int
image_diff_flattened (const char *filename_a,
const char *filename_b,
- const char *filename_diff)
+ const char *filename_diff,
+ int ax,
+ int ay,
+ int bx,
+ int by)
{
int pixels_changed;
unsigned int width_a, height_a, stride_a;
@@ -225,9 +258,13 @@ image_diff_flattened (const char *filename_a,
return -1;
}
+ width_a -= ax;
+ height_a -= ay;
+ width_b -= bx;
+ height_b -= by;
+
if (width_a != width_b ||
- height_a != height_b ||
- stride_a != stride_b)
+ height_a != height_b)
{
cairo_test_log ("Error: Image size mismatch: (%dx%d@%d) vs. (%dx%d@%d)\n"
" for %s vs. %s\n",
@@ -241,17 +278,19 @@ image_diff_flattened (const char *filename_a,
buf_b_surface = cairo_image_surface_create_for_data (buf_b,
CAIRO_FORMAT_ARGB32,
- width_b, height_b,
+ width_b + bx, height_b + bx,
stride_b);
buf_diff = xcalloc (stride_a * height_a, 1);
- b_flat = xcalloc (stride_b * height_b, 1);
+ b_flat = xcalloc (stride_a * height_a, 1);
b_flat_surface = cairo_image_surface_create_for_data (b_flat,
CAIRO_FORMAT_ARGB32,
- width_b, height_b,
- stride_b);
+ width_a, height_a,
+ stride_a);
+ /*cairo_surface_set_device_offset (b_flat_surface, -bx, -by);*/
+
cr = cairo_create (b_flat_surface);
cairo_set_source_rgb (cr, 1, 1, 1);
@@ -263,8 +302,11 @@ image_diff_flattened (const char *filename_a,
cairo_surface_destroy (b_flat_surface);
cairo_surface_destroy (buf_b_surface);
- pixels_changed = buffer_diff (buf_a, b_flat, buf_diff,
- width_a, height_a, stride_a);
+ pixels_changed = buffer_diff (buf_a + (ay * stride_a) + ax * 4,
+ b_flat,
+ buf_diff,
+ width_a, height_a,
+ stride_a, stride_a, stride_a);
if (pixels_changed) {
FILE *png_file = fopen (filename_diff, "wb");