]> mj.ucw.cz Git - libucw.git/blobdiff - images/image-dup-test.c
Updated TODO
[libucw.git] / images / image-dup-test.c
index 0d18ece08a1bd9ba4cdfff6c5ac9753213abfc2e..feece3d1fc7b3f91de3c29fb8e8fb9e098ba6d36 100644 (file)
@@ -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 <ucw/lib.h>
+#include <ucw/getopt.h>
+#include <ucw/fastbuf.h>
+#include <ucw/mempool.h>
+#include <images/images.h>
+#include <images/color.h>
+#include <images/duplicates.h>
 
 #include <stdlib.h>
 #include <fcntl.h>
@@ -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,16 +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;
 
-  image_io_init(&it, &io);
+  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);
@@ -128,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);
@@ -145,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;
 }