2 * Image duplicates testing
4 * (c) 2006 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU General Public License.
11 #include "lib/getopt.h"
12 #include "lib/fastbuf.h"
13 #include "images/images.h"
14 #include "images/color.h"
15 #include "images/duplicates.h"
26 Usage: image-dup-test [options] image1 image2 \n\
28 -q --quiet no progress messages\n\
29 -f --format-1 image1 format (jpeg, gif, png)\n\
30 -F --format-2 image2 format\n\
31 -g --background background color (hexadecimal RRGGBB)\n\
32 -t --transformations hexadecimal value of allowed transformtion (1=identity, FF=all)\n\
37 static char *shortopts = "qf:F:g:t:" CF_SHORT_OPTS;
38 static struct option longopts[] =
41 { "quiet", 0, 0, 'q' },
42 { "format-1", 0, 0, 'f' },
43 { "format-2", 0, 0, 'F' },
44 { "background", 0, 0, 'g' },
45 { "transormations", 0, 0, 't' },
49 static uns verbose = 1;
50 static byte *file_name_1;
51 static byte *file_name_2;
52 static enum image_format format_1;
53 static enum image_format format_2;
54 static struct color background_color;
55 static uns transformations = IMAGE_DUP_TRANS_ALL;
57 #define MSG(x...) do{ if (verbose) log(L_INFO, ##x); }while(0)
60 main(int argc, char **argv)
64 while ((opt = cf_getopt(argc, argv, shortopts, longopts, NULL)) >= 0)
71 if (!(format_1 = image_extension_to_format(optarg)))
75 if (!(format_2 = image_extension_to_format(optarg)))
80 if (strlen(optarg) != 6)
84 long int v = strtol(optarg, &end, 16);
85 if (errno || *end || v < 0)
87 color_make_rgb(&background_color, (v >> 16) & 255, (v >> 8) & 255, v & 255);
94 long int v = strtol(optarg, &end, 16);
95 if (errno || *end || v < 0 || v > 0xff)
104 if (argc != optind + 2)
106 file_name_1 = argv[optind++];
107 file_name_2 = argv[optind];
109 #define TRY(x) do{ if (!(x)) die("Error: %s", it.err_msg); }while(0)
110 MSG("Initializing image library");
111 struct image_thread it;
113 image_thread_init(&it);
115 struct image *img1, *img2;
117 image_io_init(&it, &io);
118 MSG("Reading %s", file_name_1);
119 io.fastbuf = bopen(file_name_1, O_RDONLY, 1 << 18);
120 io.format = format_1 ? : image_file_name_to_format(file_name_1);
121 TRY(image_io_read_header(&io));
122 io.flags = COLOR_SPACE_RGB | IMAGE_IO_USE_BACKGROUND;
123 if (background_color.color_space)
124 io.background_color = background_color;
125 else if (!io.background_color.color_space)
126 io.background_color = color_black;
127 TRY(image_io_read_data(&io, 1));
130 MSG("Image size=%ux%u", img1->cols, img1->rows);
133 MSG("Reading %s", file_name_2);
134 io.fastbuf = bopen(file_name_2, O_RDONLY, 1 << 18);
135 io.format = format_2 ? : image_file_name_to_format(file_name_2);
136 TRY(image_io_read_header(&io));
137 io.flags = COLOR_SPACE_RGB | IMAGE_IO_USE_BACKGROUND;
138 if (background_color.color_space)
139 io.background_color = background_color;
140 else if (!io.background_color.color_space)
141 io.background_color = color_black;
142 TRY(image_io_read_data(&io, 1));
145 image_io_cleanup(&io);
146 MSG("Image size=%ux%u", img2->cols, img2->rows);
148 struct image_dup dup1, dup2;
149 struct mempool *pool = mp_new(1 << 18);
150 MSG("Creating internal structures");
151 TRY(image_dup_init(&it, &dup1, img1, pool));
152 TRY(image_dup_init(&it, &dup2, img2, pool));
154 MSG("Similarity bitmap %02x", image_dup_compare(&dup1, &dup2, transformations | IMAGE_DUP_SCALE | IMAGE_DUP_WANT_ALL));
160 image_thread_cleanup(&it);