1#include "config.h"
2
3#include <stdlib.h>
4
5#include "reftest-compare.h"
6
7static char *opt_filename;
8static gboolean opt_quiet;
9
10int
11main (int argc, char **argv)
12{
13 GdkTexture *image1;
14 GdkTexture *image2;
15 GdkTexture *diff;
16 GOptionEntry entries[] = {
17 {"output", 'o', 0, G_OPTION_ARG_FILENAME, &opt_filename, "Output location", "FILE" },
18 {"quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Don't talk", NULL },
19 { NULL, }
20 };
21 GOptionContext *context;
22 GError *error = NULL;
23
24 context = g_option_context_new (parameter_string: "FILE1 FILE2");
25 g_option_context_add_main_entries (context, entries, NULL);
26 if (!g_option_context_parse (context, argc: &argc, argv: &argv, error: &error))
27 {
28 if (error != NULL)
29 g_printerr (format: "%s\n", error->message);
30 else
31 g_printerr (format: "Option parse error\n");
32 exit (status: 1);
33 }
34
35 if (argc < 3)
36 {
37 g_printerr (format: "Must specify two files\n");
38 exit (status: 1);
39 }
40
41 image1 = gdk_texture_new_from_filename (path: argv[1], error: &error);
42 if (image1 == NULL)
43 {
44 g_printerr (format: "Error loading %s: %s\n", argv[1], error->message);
45 exit (status: 1);
46 }
47 image2 = gdk_texture_new_from_filename (path: argv[2], error: &error);
48 if (image2 == NULL)
49 {
50 g_printerr (format: "Error loading %s: %s\n", argv[2], error->message);
51 exit (status: 1);
52 }
53
54 diff = reftest_compare_textures (texture1: image1, texture2: image2);
55
56 if (opt_filename && diff)
57 {
58 if (!gdk_texture_save_to_png (texture: diff, filename: opt_filename))
59 {
60 g_printerr (format: "Could not save diff image to %s\n", opt_filename);
61 exit (status: 1);
62 }
63 }
64
65 if (!opt_quiet)
66 {
67 if (diff)
68 {
69 if (opt_filename)
70 g_print (format: "Differences witten to %s.\n", opt_filename);
71 else
72 g_print (format: "The images are different.\n");
73 }
74 else
75 g_print (format: "No differences.\n");
76 }
77
78 return diff != NULL ? 1 : 0;
79}
80

source code of gtk/testsuite/reftests/image-compare.c