Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/fuzzymatch/fuzzymatch.c

Issue 13159: Add fuzzy image matching tool for Linux pixel tests (Closed)
Patch Set: Add license block Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /* Fuzzy pixel test matching.
6 *
7 * This is designed to compare two layout test images (RGB 800x600) and manage
8 * to ignore the noise caused by the font renderers choosing slightly different
9 * pixels.
10 *
11 * A B
12 * | |
13 * |--->delta<---|
14 * |
15 * V
16 * gray
17 * |
18 * V
19 * binary
20 * |
21 * |-------------|
22 * | |
23 * 1x3 3x1 Morphological openings
24 * | |
25 * |-----OR------|
26 * |
27 * V
28 * count pixels
29 *
30 * The result is that three different pixels in a row (vertically or
31 * horizontally) will cause the match to fail and the binary exits with code 1.
32 * Otherwise the binary exists with code 0.
33 *
34 * This requires leptonica to be installed. On Ubuntu do
35 * # apt-get install libleptonica libleptonica-dev
36 *
37 * Build with:
38 * % gcc -o fuzzymatch fuzzymatch.c -llept -ljpeg -ltiff -lpng -lz -lm -Wall - O2
39 */
40
41 #include <unistd.h>
42 #include <stdio.h>
43 #include <leptonica/allheaders.h>
44
45 static int
46 usage(const char *argv0) {
47 fprintf(stderr, "Usage: %s <input a> <input b>\n", argv0);
48 return 1;
49 }
50
51 int
52 main(int argc, char **argv) {
53 if (argc != 3)
54 return usage(argv[0]);
55
56 PIX *a = pixRead(argv[1]);
57 PIX *b = pixRead(argv[2]);
58
59 if (!a) {
60 fprintf(stderr, "Failed to open %s\n", argv[1]);
61 return 1;
62 }
63
64 if (!b) {
65 fprintf(stderr, "Failed to open %s\n", argv[1]);
66 return 1;
67 }
68
69 if (pixGetWidth(a) != pixGetWidth(b) ||
70 pixGetHeight(a) != pixGetHeight(b)) {
71 fprintf(stderr, "Inputs are difference sizes\n");
72 return 1;
73 }
74
75 PIX *delta = pixAbsDifference(a, b);
76 pixInvert(delta, delta);
77 pixDestroy(&a);
78 pixDestroy(&b);
79
80 PIX *deltagray = pixConvertRGBToGray(delta, 0, 0, 0);
81 pixDestroy(&delta);
82
83 PIX *deltabinary = pixThresholdToBinary(deltagray, 254);
84
85 PIX *hopened = pixOpenBrick(NULL, deltabinary, 3, 1);
86 PIX *vopened = pixOpenBrick(NULL, deltabinary, 1, 3);
87 pixDestroy(&deltabinary);
88
89 PIX *opened = pixOr(NULL, hopened, vopened);
90 pixDestroy(&hopened);
91 pixDestroy(&vopened);
92
93 l_int32 count;
94 pixCountPixels(opened, &count, NULL);
95 fprintf(stderr, "%d\n", count);
96
97 return count;
98 }
OLDNEW
« no previous file with comments | « third_party/fuzzymatch/SConstruct ('k') | webkit/tools/layout_tests/layout_package/test_failures.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698