X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fimage-dup-test.c;h=feece3d1fc7b3f91de3c29fb8e8fb9e098ba6d36;hb=e5d79225e3eef5c39be7f8e5006e331ed0f76f2f;hp=ecfa5500f1fb22266bd15acf7d479327efe64101;hpb=c1afcf90949e5058a95e0e12a09b25a068d68b61;p=libucw.git diff --git a/images/image-dup-test.c b/images/image-dup-test.c index ecfa5500..feece3d1 100644 --- a/images/image-dup-test.c +++ b/images/image-dup-test.c @@ -7,12 +7,13 @@ * of the GNU General Public License. */ -#include "lib/lib.h" -#include "lib/getopt.h" -#include "lib/fastbuf.h" -#include "images/images.h" -#include "images/color.h" -#include "images/duplicates.h" +#include +#include +#include +#include +#include +#include +#include #include #include @@ -45,7 +46,7 @@ static struct option longopts[] = { "transormations", 0, 0, 't' }, { NULL, 0, 0, 0 } }; - + static uns verbose = 1; static byte *file_name_1; static byte *file_name_2; @@ -54,7 +55,7 @@ static enum image_format format_2; static struct color background_color; static uns transformations = IMAGE_DUP_TRANS_ALL; -#define MSG(x...) do{ if (verbose) log(L_INFO, ##x); }while(0) +#define MSG(x...) do{ if (verbose) msg(L_INFO, ##x); }while(0) int main(int argc, char **argv) @@ -105,17 +106,18 @@ main(int argc, char **argv) usage(); file_name_1 = argv[optind++]; file_name_2 = argv[optind]; - -#define TRY(x) do{ if (!(x)) die("Error: %s", it.err_msg); }while(0) + +#define TRY(x) do{ if (!(x)) exit(1); }while(0) MSG("Initializing image library"); - struct image_thread it; + struct image_context ctx; + struct image_dup_context idc; struct image_io io; - image_thread_init(&it); + image_context_init(&ctx); + image_dup_context_init(&ctx, &idc); struct image *img1, *img2; - if (!image_io_init(&it, &io)) - die("Cannot initialize image I/O (%s)", it.err_msg); + TRY(image_io_init(&ctx, &io)); MSG("Reading %s", file_name_1); io.fastbuf = bopen(file_name_1, O_RDONLY, 1 << 18); io.format = format_1 ? : image_file_name_to_format(file_name_1); @@ -129,7 +131,7 @@ main(int argc, char **argv) bclose(io.fastbuf); img1 = io.image; MSG("Image size=%ux%u", img1->cols, img1->rows); - + image_io_reset(&io); MSG("Reading %s", file_name_2); io.fastbuf = bopen(file_name_2, O_RDONLY, 1 << 18); @@ -146,19 +148,27 @@ main(int argc, char **argv) image_io_cleanup(&io); MSG("Image size=%ux%u", img2->cols, img2->rows); - struct image_dup dup1, dup2; + struct image_dup *dup1, *dup2; struct mempool *pool = mp_new(1 << 18); MSG("Creating internal structures"); - TRY(image_dup_init(&it, &dup1, img1, pool)); - TRY(image_dup_init(&it, &dup2, img2, pool)); + dup1 = mp_start(pool, image_dup_estimate_size(img1->cols, img1->rows, 1, idc.qtree_limit)); + uns size = image_dup_new(&idc, img1, dup1, 1); + TRY(size); + mp_end(pool, (void *)dup1 + size); + dup2 = mp_start(pool, image_dup_estimate_size(img2->cols, img2->rows, 1, idc.qtree_limit)); + size = image_dup_new(&idc, img2, dup2, 1); + TRY(size); + mp_end(pool, (void *)dup2 + size); - MSG("Similarity bitmap %02x", image_dup_compare(&dup1, &dup2, transformations | IMAGE_DUP_SCALE | IMAGE_DUP_WANT_ALL)); + idc.flags = transformations | IMAGE_DUP_SCALE | IMAGE_DUP_WANT_ALL; + MSG("Similarity bitmap %02x", image_dup_compare(&idc, dup1, dup2)); mp_delete(pool); - + image_destroy(img1); image_destroy(img2); - image_thread_cleanup(&it); + image_dup_context_cleanup(&idc); + image_context_cleanup(&ctx); MSG("Done."); return 0; }