Move target tolerance to cairo_test_target structure (should let single-pixel SVG errors pass)

Previously we were setting the target tolerance based on the surface
type. But that doesn't work as multiple backends will provide a surface
of type meta. So instead we put the tolerance as a value in the
cairo_test_target data structure.

With this change, some single-pixel errors of 1 in the SVG backend
should now be ignored.

Manually "cherry picked" from bcb7863f00
(the regular cherry-pick command cannot handle the file renames and
 indentation changes involved here).
This commit is contained in:
Carl Worth 2006-09-05 22:25:21 -07:00
parent 02497b39c8
commit ad4f0ba2d5

View file

@ -133,50 +133,13 @@ typedef struct _cairo_test_target
const char *name;
cairo_surface_type_t expected_type;
cairo_content_t content;
int error_tolerance;
cairo_test_create_target_surface_t create_target_surface;
cairo_test_write_to_png_t write_to_png;
cairo_test_cleanup_target_t cleanup_target;
void *closure;
} cairo_test_target_t;
/* What's the maximum single-channel difference we will tolerate and
* still allow a test to pass? */
static unsigned int
target_tolerance (cairo_test_target_t *target)
{
switch (target->expected_type) {
/* I'm uncompromising about leaving the image backend as no
* tolerance. There's shouldn't ever be anything that is out of
* our control here. */
case CAIRO_SURFACE_TYPE_IMAGE:
return 0;
/* It seems we should be able to round-trip SVG content perfrectly
* through librsvg and cairo, but for some mysterious reason, some
* systems get an error of 1 for some pixels on some of the text
* tests. XXX: I'd still like to chase these down at some point. */
case CAIRO_SURFACE_TYPE_SVG:
return 1;
/* Everything else gets the no-tolerance policy. It would actually
* be nice to go through some of the backends and see * if it
* wouldn't make sense to increase this. For example, * could we
* use a small value here for the PS backend and * eliminate some
* of the ps-specific reference images? */
case CAIRO_SURFACE_TYPE_PDF:
case CAIRO_SURFACE_TYPE_PS:
case CAIRO_SURFACE_TYPE_XLIB:
case CAIRO_SURFACE_TYPE_XCB:
case CAIRO_SURFACE_TYPE_GLITZ:
case CAIRO_SURFACE_TYPE_QUARTZ:
case CAIRO_SURFACE_TYPE_WIN32:
case CAIRO_SURFACE_TYPE_BEOS:
case CAIRO_SURFACE_TYPE_DIRECTFB:
default:
return 0;
}
}
void
cairo_test_init (const char *test_name)
{
@ -1715,7 +1678,7 @@ cairo_test_for_target (cairo_test_t *test,
if (result.pixels_changed) {
cairo_test_log ("%d pixels differ (with maximum difference of %d) from reference image %s\n",
result.pixels_changed, result.max_diff, ref_name);
if (result.max_diff > target_tolerance (target)) {
if (result.max_diff > target->error_tolerance) {
ret = CAIRO_TEST_FAILURE;
goto UNWIND_CAIRO;
}
@ -1771,82 +1734,85 @@ cairo_test_expecting (cairo_test_t *test,
cairo_test_target_t ** volatile targets_to_test;
cairo_test_target_t targets[] =
{
{ "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA,
/* I'm uncompromising about leaving the image backend as 0
* for tolerance. There shouldn't ever be anything that is out of
* our control here. */
{ "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_image_surface, cairo_surface_write_to_png, NULL},
{ "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR,
{ "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
create_image_surface, cairo_surface_write_to_png, NULL},
#ifdef CAIRO_HAS_TEST_SURFACES
{ "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
CAIRO_CONTENT_COLOR_ALPHA,
CAIRO_CONTENT_COLOR_ALPHA, 0,
create_test_fallback_surface, cairo_surface_write_to_png, NULL },
{ "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
CAIRO_CONTENT_COLOR,
CAIRO_CONTENT_COLOR, 0,
create_test_fallback_surface, cairo_surface_write_to_png, NULL },
{ "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
CAIRO_CONTENT_COLOR_ALPHA,
CAIRO_CONTENT_COLOR_ALPHA, 0,
create_test_meta_surface, cairo_surface_write_to_png, NULL },
{ "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
CAIRO_CONTENT_COLOR,
CAIRO_CONTENT_COLOR, 0,
create_test_meta_surface, cairo_surface_write_to_png, NULL },
{ "test-paginated", CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
CAIRO_CONTENT_COLOR_ALPHA,
CAIRO_CONTENT_COLOR_ALPHA, 0,
create_test_paginated_surface,
test_paginated_write_to_png,
cleanup_test_paginated },
{ "test-paginated", CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
CAIRO_CONTENT_COLOR,
CAIRO_CONTENT_COLOR, 0,
create_test_paginated_surface,
test_paginated_write_to_png,
cleanup_test_paginated },
#endif
#ifdef CAIRO_HAS_GLITZ_SURFACE
#if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
{ "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ,CAIRO_CONTENT_COLOR_ALPHA,
{ "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ,CAIRO_CONTENT_COLOR_ALPHA, 0,
create_cairo_glitz_glx_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_glx },
{ "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR,
{ "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
create_cairo_glitz_glx_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_glx },
#endif
#if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE
{ "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA,
{ "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_cairo_glitz_agl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_agl },
{ "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR,
{ "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
create_cairo_glitz_agl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_agl },
#endif
#if CAIRO_CAN_TEST_GLITZ_WGL_SURFACE
{ "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA,
{ "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_cairo_glitz_wgl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_wgl },
{ "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR,
{ "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
create_cairo_glitz_wgl_surface, cairo_surface_write_to_png,
cleanup_cairo_glitz_wgl },
#endif
#endif /* CAIRO_HAS_GLITZ_SURFACE */
#if 0 && CAIRO_HAS_QUARTZ_SURFACE
{ "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR,
{ "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR, 0,
create_quartz_surface, cairo_surface_write_to_png,
cleanup_quartz },
#endif
#if CAIRO_HAS_WIN32_SURFACE
{ "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR,
{ "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0,
create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
#endif
#if CAIRO_HAS_XCB_SURFACE
{ "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA,
{ "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_xcb_surface, cairo_surface_write_to_png, cleanup_xcb},
#endif
#if CAIRO_HAS_XLIB_SURFACE
{ "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA,
{ "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib},
{ "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR,
{ "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 0,
create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib},
#endif
#if CAIRO_HAS_PS_SURFACE
{ "ps", CAIRO_SURFACE_TYPE_PS,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
create_ps_surface, ps_surface_write_to_png, cleanup_ps },
/* XXX: We expect type image here only due to a limitation in
@ -1857,12 +1823,12 @@ cairo_test_expecting (cairo_test_t *test,
* have source support for PS/meta-surfaces, so the
* create_similar path for all paginated surfaces currently
* returns an image surface.*/
{ "ps", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR,
{ "ps", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
create_ps_surface, ps_surface_write_to_png, cleanup_ps },
#endif
#if CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE
{ "pdf", CAIRO_SURFACE_TYPE_PDF,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED,
CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf },
/* XXX: We expect type image here only due to a limitation in
@ -1873,28 +1839,33 @@ cairo_test_expecting (cairo_test_t *test,
* have source support for PDF/meta-surfaces, so the
* create_similar path for all paginated surfaces currently
* returns an image surface.*/
{ "pdf", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR,
{ "pdf", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf },
#endif
#if CAIRO_HAS_SVG_SURFACE && CAIRO_CAN_TEST_SVG_SURFACE
{ "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA,
/* It seems we should be able to round-trip SVG content perfrectly
* through librsvg and cairo, but for some mysterious reason, some
* systems get an error of 1 for some pixels on some of the text
* tests. XXX: I'd still like to chase these down at some point.
* For now just set teh svg error tolerance to 1. */
{ "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA, 1,
create_svg_surface, svg_surface_write_to_png, cleanup_svg },
{ "svg", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR,
{ "svg", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 1,
create_svg_surface, svg_surface_write_to_png, cleanup_svg },
#endif
#if CAIRO_HAS_BEOS_SURFACE
{ "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR,
{ "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 0,
create_beos_surface, cairo_surface_write_to_png, cleanup_beos},
{ "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR,
{ "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 0,
create_beos_bitmap_surface, cairo_surface_write_to_png, cleanup_beos_bitmap},
{ "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA,
{ "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_beos_bitmap_surface, cairo_surface_write_to_png, cleanup_beos_bitmap},
#endif
#if CAIRO_HAS_DIRECTFB_SURFACE
{ "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR,
{ "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR, 0,
create_directfb_surface, cairo_surface_write_to_png, cleanup_directfb},
{ "directfb-bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA,
{ "directfb-bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA, 0,
create_directfb_bitmap_surface, cairo_surface_write_to_png,cleanup_directfb},
#endif
};