summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 20:14:20 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-05 20:14:20 +0000
commitd8b258c5e97adbc8e73dd73b319d1cdacb4c15d7 (patch)
tree2e231f5f9b065898111a36b76e7bfab5d6e49b35
parente1a6d0a8acf8c1b93d97f8fb22740bfee4ee7cda (diff)
downloadchromium_src-d8b258c5e97adbc8e73dd73b319d1cdacb4c15d7.zip
chromium_src-d8b258c5e97adbc8e73dd73b319d1cdacb4c15d7.tar.gz
chromium_src-d8b258c5e97adbc8e73dd73b319d1cdacb4c15d7.tar.bz2
Add fuzzy image matching tool for Linux pixel tests
Review URL: http://codereview.chromium.org/13159 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6444 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--third_party/fuzzymatch/SConstruct1
-rw-r--r--third_party/fuzzymatch/fuzzymatch.c98
-rw-r--r--webkit/tools/layout_tests/layout_package/test_failures.py7
-rwxr-xr-xwebkit/tools/layout_tests/run_webkit_tests.py7
4 files changed, 113 insertions, 0 deletions
diff --git a/third_party/fuzzymatch/SConstruct b/third_party/fuzzymatch/SConstruct
new file mode 100644
index 0000000..4fe7baa
--- /dev/null
+++ b/third_party/fuzzymatch/SConstruct
@@ -0,0 +1 @@
+Program('fuzzymatch.c', LIBS = ['lept', 'png', 'jpeg', 'tiff', 'z', 'm'])
diff --git a/third_party/fuzzymatch/fuzzymatch.c b/third_party/fuzzymatch/fuzzymatch.c
new file mode 100644
index 0000000..b1624e0
--- /dev/null
+++ b/third_party/fuzzymatch/fuzzymatch.c
@@ -0,0 +1,98 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/* Fuzzy pixel test matching.
+ *
+ * This is designed to compare two layout test images (RGB 800x600) and manage
+ * to ignore the noise caused by the font renderers choosing slightly different
+ * pixels.
+ *
+ * A B
+ * | |
+ * |--->delta<---|
+ * |
+ * V
+ * gray
+ * |
+ * V
+ * binary
+ * |
+ * |-------------|
+ * | |
+ * 1x3 3x1 Morphological openings
+ * | |
+ * |-----OR------|
+ * |
+ * V
+ * count pixels
+ *
+ * The result is that three different pixels in a row (vertically or
+ * horizontally) will cause the match to fail and the binary exits with code 1.
+ * Otherwise the binary exists with code 0.
+ *
+ * This requires leptonica to be installed. On Ubuntu do
+ * # apt-get install libleptonica libleptonica-dev
+ *
+ * Build with:
+ * % gcc -o fuzzymatch fuzzymatch.c -llept -ljpeg -ltiff -lpng -lz -lm -Wall -O2
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <leptonica/allheaders.h>
+
+static int
+usage(const char *argv0) {
+ fprintf(stderr, "Usage: %s <input a> <input b>\n", argv0);
+ return 1;
+}
+
+int
+main(int argc, char **argv) {
+ if (argc != 3)
+ return usage(argv[0]);
+
+ PIX *a = pixRead(argv[1]);
+ PIX *b = pixRead(argv[2]);
+
+ if (!a) {
+ fprintf(stderr, "Failed to open %s\n", argv[1]);
+ return 1;
+ }
+
+ if (!b) {
+ fprintf(stderr, "Failed to open %s\n", argv[1]);
+ return 1;
+ }
+
+ if (pixGetWidth(a) != pixGetWidth(b) ||
+ pixGetHeight(a) != pixGetHeight(b)) {
+ fprintf(stderr, "Inputs are difference sizes\n");
+ return 1;
+ }
+
+ PIX *delta = pixAbsDifference(a, b);
+ pixInvert(delta, delta);
+ pixDestroy(&a);
+ pixDestroy(&b);
+
+ PIX *deltagray = pixConvertRGBToGray(delta, 0, 0, 0);
+ pixDestroy(&delta);
+
+ PIX *deltabinary = pixThresholdToBinary(deltagray, 254);
+
+ PIX *hopened = pixOpenBrick(NULL, deltabinary, 3, 1);
+ PIX *vopened = pixOpenBrick(NULL, deltabinary, 1, 3);
+ pixDestroy(&deltabinary);
+
+ PIX *opened = pixOr(NULL, hopened, vopened);
+ pixDestroy(&hopened);
+ pixDestroy(&vopened);
+
+ l_int32 count;
+ pixCountPixels(opened, &count, NULL);
+ fprintf(stderr, "%d\n", count);
+
+ return count;
+}
diff --git a/webkit/tools/layout_tests/layout_package/test_failures.py b/webkit/tools/layout_tests/layout_package/test_failures.py
index 1e59462..8779a68 100644
--- a/webkit/tools/layout_tests/layout_package/test_failures.py
+++ b/webkit/tools/layout_tests/layout_package/test_failures.py
@@ -202,3 +202,10 @@ class FailureImageHashMismatch(FailureWithType):
# to the PNGs rather than the checksums.
return "Image mismatch"
+class FailureFuzzyFailure(FailureWithType):
+ """Image hashes didn't match."""
+ OUT_FILENAMES = ["-actual-win.png", "-expected.png"]
+
+ @staticmethod
+ def Message():
+ return "Fuzzy image match also failed"
diff --git a/webkit/tools/layout_tests/run_webkit_tests.py b/webkit/tools/layout_tests/run_webkit_tests.py
index 9f320bc..5672133 100755
--- a/webkit/tools/layout_tests/run_webkit_tests.py
+++ b/webkit/tools/layout_tests/run_webkit_tests.py
@@ -39,6 +39,7 @@ from layout_package import http_server
from layout_package import path_utils
from layout_package import test_failures
from layout_package import test_shell_thread
+from test_types import fuzzy_image_diff
from test_types import image_diff
from test_types import test_type_base
from test_types import text_diff
@@ -597,6 +598,8 @@ def main(options, args):
test_runner.AddTestType(simplified_text_diff.SimplifiedTextDiff)
if not options.no_pixel_tests:
test_runner.AddTestType(image_diff.ImageDiff)
+ if options.fuzzy_pixel_tests:
+ test_runner.AddTestType(fuzzy_image_diff.FuzzyImageDiff)
has_new_failures = test_runner.Run()
logging.info("Exit status: %d" % has_new_failures)
sys.exit(has_new_failures)
@@ -606,6 +609,10 @@ if '__main__' == __name__:
option_parser.add_option("", "--no-pixel-tests", action="store_true",
default=False,
help="disable pixel-to-pixel PNG comparisons")
+ option_parser.add_option("", "--fuzzy-pixel-tests", action="store_true",
+ default=False,
+ help="Also use fuzzy matching to compare pixel test "
+ "outputs.")
option_parser.add_option("", "--results-directory",
default="layout-test-results",
help="Output results directory source dir,"