[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / imagediff.c
blob188c1a979e01c10e8999875a5ba667fd395b27c4
1 /* imagediff - Compare two images
3 * Copyright © 2004 Richard D. Worth
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of Richard Worth
10 * not be used in advertising or publicity pertaining to distribution
11 * of the software without specific, written prior permission.
12 * Richard Worth makes no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without express
14 * or implied warranty.
16 * RICHARD WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18 * NO EVENT SHALL RICHARD WORTH BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Richard D. Worth <richard@theworths.org> */
26 #include <stdio.h>
27 #include <stdlib.h>
29 #include "buffer-diff.h"
30 #include "xmalloc.h"
32 int
33 main (int argc, char *argv[])
35 buffer_diff_result_t result;
36 cairo_status_t status;
38 unsigned int ax, ay, bx, by;
40 if (argc != 3 && argc != 7) {
41 fprintf (stderr, "Usage: %s image1.png image2.png [ax ay bx by]\n", argv[0]);
42 fprintf (stderr, "Computes an output image designed to present a \"visual diff\" such that even\n");
43 fprintf (stderr, "small errors in single pixels are readily apparent in the output.\n");
44 fprintf (stderr, "The output image is written on stdout.\n");
45 exit (1);
48 if (argc == 7) {
49 ax = strtoul (argv[3], NULL, 0);
50 ay = strtoul (argv[4], NULL, 0);
51 bx = strtoul (argv[5], NULL, 0);
52 by = strtoul (argv[6], NULL, 0);
53 } else {
54 ax = ay = bx = by = 0;
57 status = image_diff (argv[1], argv[2], NULL, ax, ay, bx, by, &result);
59 if (status) {
60 fprintf (stderr, "Error comparing images: %s\n",
61 cairo_status_to_string (status));
62 return 1;
65 if (result.pixels_changed)
66 fprintf (stderr, "Total pixels changed: %d with a maximum channel difference of %d.\n",
67 result.pixels_changed,
68 result.max_diff);
70 return (result.pixels_changed != 0);