2 PerceptualDiff - a program that compares two images using a perceptual metric
4 A perceptual metric for production testing. Journal of graphics tools, 9(4):33-40, 2004, Hector Yee
5 Copyright (C) 2006 Yangli Hector Yee
7 This program is free software; you can redistribute it and/or modify it under the terms of the
8 GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with this program;
16 if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
27 static bool Yee_Compare(args_t *args)
29 int width_a, height_a, stride_a;
30 unsigned char *data_a, *row_a;
32 int width_b, height_b, stride_b;
33 unsigned char *data_b, *row_b;
35 unsigned int x, y, dim, pixels_failed;
36 bool identical = true;
38 width_a = cairo_image_surface_get_width (args->surface_a);
39 height_a = cairo_image_surface_get_height (args->surface_a);
40 stride_a = cairo_image_surface_get_stride (args->surface_a);
41 data_a = cairo_image_surface_get_data (args->surface_a);
43 width_b = cairo_image_surface_get_width (args->surface_b);
44 height_b = cairo_image_surface_get_height (args->surface_b);
45 stride_b = cairo_image_surface_get_stride (args->surface_b);
46 data_b = cairo_image_surface_get_data (args->surface_b);
48 if ((width_a != width_b) || (height_a != height_b)) {
49 printf ("FAIL: Image dimensions do not match\n");
55 for (y = 0; y < height_a; y++) {
56 row_a = data_a + y * stride_a;
57 row_b = data_b + y * stride_b;
58 pixel_a = (uint32_t *) row_a;
59 pixel_b = (uint32_t *) row_b;
60 for (x = 0; x < width_a; x++) {
61 if (*pixel_a != *pixel_b) {
69 printf ("PASS: Images are binary identical\n");
73 pixels_failed = pdiff_compare (args->surface_a, args->surface_b,
74 args->Gamma, args->Luminance,
77 if (pixels_failed < args->ThresholdPixels) {
78 printf ("PASS: Images are perceptually indistinguishable\n");
82 printf("FAIL: Images are visibly different\n"
83 "%d pixels are different\n", pixels_failed);
88 int main(int argc, char **argv)
94 if (!args_parse (&args, argc, argv)) {
100 return ! Yee_Compare(&args);