| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
|
| 5 |
#include "reftest-compare.h" |
| 6 |
|
| 7 |
static char *opt_filename; |
| 8 |
static gboolean opt_quiet; |
| 9 |
|
| 10 |
int |
| 11 |
main (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 ("FILE1 FILE2"); |
| 25 |
g_option_context_add_main_entries (context, entries, NULL); |
| 26 |
if (!g_option_context_parse (context, &argc, &argv, &error)) |
| 27 |
{ |
| 28 |
if (error != NULL) |
| 29 |
g_printerr ("%s\n", error->message); |
| 30 |
else |
| 31 |
g_printerr ("Option parse error\n"); |
| 32 |
exit (1); |
| 33 |
} |
| 34 |
|
| 35 |
if (argc < 3) |
| 36 |
{ |
| 37 |
g_printerr ("Must specify two files\n"); |
| 38 |
exit (1); |
| 39 |
} |
| 40 |
|
| 41 |
image1 = gdk_texture_new_from_filename (argv[1], &error); |
| 42 |
if (image1 == NULL) |
| 43 |
{ |
| 44 |
g_printerr ("Error loading %s: %s\n", argv[1], error->message); |
| 45 |
exit (1); |
| 46 |
} |
| 47 |
image2 = gdk_texture_new_from_filename (argv[2], &error); |
| 48 |
if (image2 == NULL) |
| 49 |
{ |
| 50 |
g_printerr ("Error loading %s: %s\n", argv[2], error->message); |
| 51 |
exit (1); |
| 52 |
} |
| 53 |
|
| 54 |
diff = reftest_compare_textures (image1, image2); |
| 55 |
|
| 56 |
if (opt_filename && diff) |
| 57 |
{ |
| 58 |
if (!gdk_texture_save_to_png (diff, opt_filename)) |
| 59 |
{ |
| 60 |
g_printerr ("Could not save diff image to %s\n", opt_filename); |
| 61 |
exit (1); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
if (!opt_quiet) |
| 66 |
{ |
| 67 |
if (diff) |
| 68 |
{ |
| 69 |
if (opt_filename) |
| 70 |
g_print ("Differences witten to %s.\n", opt_filename); |
| 71 |
else |
| 72 |
g_print ("The images are different.\n"); |
| 73 |
} |
| 74 |
else |
| 75 |
g_print ("No differences.\n"); |
| 76 |
} |
| 77 |
|
| 78 |
return diff != NULL ? 1 : 0; |
| 79 |
} |