diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/buffer-diff.c | 103 | ||||
-rw-r--r-- | test/buffer-diff.h | 8 | ||||
-rw-r--r-- | test/xlib-surface.c | 4 |
3 files changed, 67 insertions, 48 deletions
diff --git a/test/buffer-diff.c b/test/buffer-diff.c index 1a51ea9b..819ba163 100644 --- a/test/buffer-diff.c +++ b/test/buffer-diff.c @@ -64,9 +64,7 @@ buffer_diff_core (unsigned char *_buf_a, unsigned char *_buf_diff, int width, int height, - int stride_a, - int stride_b, - int stride_diff, + int stride, pixman_bits_t mask, buffer_diff_result_t *result_ret) { @@ -77,14 +75,12 @@ 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_a /= sizeof(pixman_bits_t); - stride_b /= sizeof(pixman_bits_t); - stride_diff /= sizeof(pixman_bits_t); + stride /= sizeof(pixman_bits_t); for (y = 0; y < height; y++) { - row_a = buf_a + y * stride_a; - row_b = buf_b + y * stride_b; - row = buf_diff + y * stride_diff; + row_a = buf_a + y * stride; + row_b = buf_b + y * stride; + row = buf_diff + y * stride; for (x = 0; x < width; x++) { /* check if the pixels are the same */ @@ -126,13 +122,11 @@ buffer_diff (unsigned char *buf_a, unsigned char *buf_diff, int width, int height, - int stride_a, - int stride_b, - int stride_diff, + int stride, buffer_diff_result_t *result) { buffer_diff_core(buf_a, buf_b, buf_diff, - width, height, stride_a, stride_b, stride_diff, 0xffffffff, + width, height, stride, 0xffffffff, result); } @@ -142,13 +136,11 @@ buffer_diff_noalpha (unsigned char *buf_a, unsigned char *buf_diff, int width, int height, - int stride_a, - int stride_b, - int stride_diff, + int stride, buffer_diff_result_t *result) { buffer_diff_core(buf_a, buf_b, buf_diff, - width, height, stride_a, stride_b, stride_diff, 0x00ffffff, + width, height, stride, 0x00ffffff, result); } @@ -195,6 +187,35 @@ flatten_surface (cairo_surface_t **surface, int x, int y) *surface = flat; } +/* Given an image surface, create a new surface that has the same + * contents as the sub-surface with its origin at x,y. + * + * The original surface will be destroyed. + */ +static void +extract_sub_surface (cairo_surface_t **surface, int x, int y) +{ + cairo_surface_t *sub; + cairo_t *cr; + + sub = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + cairo_image_surface_get_width (*surface) - x, + cairo_image_surface_get_height (*surface) - y); + + /* We don't use a device offset like flatten_surface. That's not + * for any important reason, (the results should be + * identical). This style just seemed more natural to me this + * time, so I'm leaving both here so I can look at both to see + * which I like better. */ + cr = cairo_create (sub); + cairo_set_source_surface (cr, *surface, -x, -y); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr); + + cairo_surface_destroy (*surface); + *surface = sub; +} + /* Image comparison code courtesy of Richard Worth <richard@theworths.org> * Returns number of pixels changed, (or -1 on error). * Also saves a "diff" image intended to visually show where the @@ -243,13 +264,32 @@ image_diff_core (const char *filename_a, return status; } - width_a = cairo_image_surface_get_width (surface_a) - ax; - height_a = cairo_image_surface_get_height (surface_a) - ay; - width_b = cairo_image_surface_get_width (surface_b) - bx; - height_b = cairo_image_surface_get_height (surface_b) - by; + if (flatten) { + flatten_surface (&surface_a, ax, ay); + flatten_surface (&surface_b, bx, by); + ax = ay = bx = by = 0; + } + + if (ax || ay) { + extract_sub_surface (&surface_a, ax, ay); + ax = ay = 0; + } + + if (bx || by) { + extract_sub_surface (&surface_b, bx, by); + bx = by = 0; + } + + width_a = cairo_image_surface_get_width (surface_a); + height_a = cairo_image_surface_get_height (surface_a); + stride_a = cairo_image_surface_get_stride (surface_a); + width_b = cairo_image_surface_get_width (surface_b); + height_b = cairo_image_surface_get_height (surface_b); + stride_b = cairo_image_surface_get_stride (surface_b); if (width_a != width_b || - height_a != height_b) + height_a != height_b || + stride_a != stride_b) { cairo_test_log ("Error: Image size mismatch: (%dx%d) vs. (%dx%d)\n" " for %s vs. %s\n", @@ -261,26 +301,13 @@ image_diff_core (const char *filename_a, return CAIRO_STATUS_SURFACE_TYPE_MISMATCH; } - if (flatten) { - flatten_surface (&surface_a, ax, ay); - flatten_surface (&surface_b, bx, by); - ax = ay = bx = by = 0; - } - surface_diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width_a, height_a); - stride_a = cairo_image_surface_get_stride (surface_a); - stride_b = cairo_image_surface_get_stride (surface_b); - - buffer_diff (cairo_image_surface_get_data (surface_a) - + (ay * stride_a) + ax * 4, - cairo_image_surface_get_data (surface_b) - + (by * stride_b) + by * 4, + buffer_diff (cairo_image_surface_get_data (surface_a), + cairo_image_surface_get_data (surface_b), cairo_image_surface_get_data (surface_diff), - width_a, height_a, - stride_a, stride_b, - cairo_image_surface_get_stride (surface_diff), + width_a, height_a, stride_a, result); if (result->pixels_changed) { diff --git a/test/buffer-diff.h b/test/buffer-diff.h index bef42cff..d95c213b 100644 --- a/test/buffer-diff.h +++ b/test/buffer-diff.h @@ -50,9 +50,7 @@ buffer_diff (unsigned char *buf_a, unsigned char *buf_diff, int width, int height, - int stride_a, - int stride_b, - int stride_diff, + int stride, buffer_diff_result_t *result); /* Compares two image buffers ignoring the alpha channel. @@ -69,9 +67,7 @@ buffer_diff_noalpha (unsigned char *buf_a, unsigned char *buf_diff, int width, int height, - int stride_a, - int stride_b, - int stride_diff, + int stride, buffer_diff_result_t *result); /* Compares two image buffers ignoring the alpha channel. A return diff --git a/test/xlib-surface.c b/test/xlib-surface.c index ccde14c1..44bea927 100644 --- a/test/xlib-surface.c +++ b/test/xlib-surface.c @@ -166,8 +166,6 @@ do_test (Display *dpy, SIZE - OFFSCREEN_OFFSET, SIZE - OFFSCREEN_OFFSET, 4 * SIZE, - 4 * SIZE, - 4 * SIZE, &result); } else { buffer_diff_noalpha (reference_data, @@ -176,8 +174,6 @@ do_test (Display *dpy, SIZE, SIZE, 4 * SIZE, - 4 * SIZE, - 4 * SIZE, &result); } |