]> mj.ucw.cz Git - libucw.git/commitdiff
MergeImages: Added several config options.
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 22 Nov 2007 13:31:21 +0000 (14:31 +0100)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 22 Nov 2007 13:31:21 +0000 (14:31 +0100)
images/dup-cmp.c
images/dup-init.c
images/duplicates.h
images/image-dup-test.c

index 39dc595948bfe19440cf7d4b870df2c262a735fe..9f98b1939dd145b1c7c209bfdb1fb4a45a15eae6 100644 (file)
@@ -152,6 +152,8 @@ same_size_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct
 {
   struct image *img1 = &dup1->image;
   struct image *img2 = &dup2->image;
+  if (!img1->pixels || !img2->pixels)
+    return 1;
   ctx->sum_pixels += img1->cols * img1->rows;
   byte *block1 = img1->pixels;
   byte *block2 = img2->pixels;
index bcc392e9fb27fe716c6982a091e500d8fd54d938..ea886d0955298b4a26080e1a1768fcbaa3021bc2 100644 (file)
@@ -26,6 +26,7 @@ image_dup_context_init(struct image_context *ic, struct image_dup_context *ctx)
     .flags = IMAGE_DUP_TRANS_ID,
     .ratio_threshold = 140,
     .error_threshold = 100,
+    .qtree_limit = 8,
   };
 }
 
@@ -34,8 +35,6 @@ image_dup_context_cleanup(struct image_dup_context *ctx UNUSED)
 {
 }
 
-static uns image_dup_tab_limit = 8;
-
 static inline struct image *
 image_dup_subimage(struct image_context *ctx, struct image_dup *dup, struct image *block, uns tab_col, uns tab_row)
 {
@@ -52,17 +51,19 @@ pixels_average(byte *dest, byte *src1, byte *src2)
 }
 
 uns
-image_dup_estimate_size(uns cols, uns rows)
+image_dup_estimate_size(uns cols, uns rows, uns same_size_compare, uns qtree_limit)
 {
   uns tab_cols, tab_rows;
-  for (tab_cols = 0; (uns)(2 << tab_cols) < cols && tab_cols < image_dup_tab_limit; tab_cols++);
-  for (tab_rows = 0; (uns)(2 << tab_rows) < rows && tab_rows < image_dup_tab_limit; tab_rows++);
-  uns size = sizeof(struct image_dup) + cols * rows * 3  + (12 << (tab_cols + tab_rows)) + 3 * CPU_STRUCT_ALIGN;
+  for (tab_cols = 0; (uns)(2 << tab_cols) < cols && tab_cols < qtree_limit; tab_cols++);
+  for (tab_rows = 0; (uns)(2 << tab_rows) < rows && tab_rows < qtree_limit; tab_rows++);
+  uns size = sizeof(struct image_dup) + (12 << (tab_cols + tab_rows)) + 2 * CPU_STRUCT_ALIGN;
+  if (same_size_compare)
+    size += cols * rows * 3 + CPU_STRUCT_ALIGN;
   return ALIGN_TO(size, CPU_STRUCT_ALIGN);
 }
 
 uns
-image_dup_new(struct image_context *ctx, struct image *img, void *buffer)
+image_dup_new(struct image_dup_context *ctx, struct image *img, void *buffer, uns same_size_compare)
 {
   DBG("image_dup_init()");
   ASSERT(!((uintptr_t)buffer & (CPU_STRUCT_ALIGN - 1)));
@@ -76,32 +77,40 @@ image_dup_new(struct image_context *ctx, struct image *img, void *buffer)
   ASSERT((img->flags & IMAGE_PIXEL_FORMAT) == COLOR_SPACE_RGB);
 
   /* Clone image */
-  if (!image_init_matrix(ctx, &dup->image, ptr, img->cols, img->rows, img->cols * 3, COLOR_SPACE_RGB))
-    return 0;
-  uns size = img->rows * img->cols * 3;
-  ptr += ALIGN_TO(size, CPU_STRUCT_ALIGN);
-  byte *s = img->pixels;
-  byte *d = dup->image.pixels;
-  for (uns row = img->rows; row--; )
+  if (same_size_compare)
+    {
+      if (!image_init_matrix(ctx->ic, &dup->image, ptr, img->cols, img->rows, img->cols * 3, COLOR_SPACE_RGB))
+        return 0;
+      uns size = img->rows * img->cols * 3;
+      ptr += ALIGN_TO(size, CPU_STRUCT_ALIGN);
+      byte *s = img->pixels;
+      byte *d = dup->image.pixels;
+      for (uns row = img->rows; row--; )
+        {
+         memcpy(d, s, img->row_pixels_size);
+         d += dup->image.row_size;
+         s += img->row_size;
+       }
+    }
+  else
     {
-      memcpy(d, s, img->row_pixels_size);
-      d += dup->image.row_size;
-      s += img->row_size;
+      dup->image.cols = img->cols;
+      dup->image.rows = img->rows;
     }
 
-  for (dup->tab_cols = 0; (uns)(2 << dup->tab_cols) < img->cols && dup->tab_cols < image_dup_tab_limit; dup->tab_cols++);
-  for (dup->tab_rows = 0; (uns)(2 << dup->tab_rows) < img->rows && dup->tab_rows < image_dup_tab_limit; dup->tab_rows++);
+  for (dup->tab_cols = 0; (uns)(2 << dup->tab_cols) < img->cols && dup->tab_cols < ctx->qtree_limit; dup->tab_cols++);
+  for (dup->tab_rows = 0; (uns)(2 << dup->tab_rows) < img->rows && dup->tab_rows < ctx->qtree_limit; dup->tab_rows++);
   dup->tab_row_size = 6 << dup->tab_cols;
   dup->tab_pixels = ptr;
-  size = 12 << (dup->tab_cols + dup->tab_rows);
+  uns size = 12 << (dup->tab_cols + dup->tab_rows);
   ptr += ALIGN_TO(size, CPU_STRUCT_ALIGN);
 
   /* Scale original image to right bottom block */
   {
     struct image block;
-    if (!image_dup_subimage(ctx, dup, &block, dup->tab_cols, dup->tab_rows))
+    if (!image_dup_subimage(ctx->ic, dup, &block, dup->tab_cols, dup->tab_rows))
       return 0;
-    if (!image_scale(ctx, &block, img))
+    if (!image_scale(ctx->ic, &block, img))
       return 0;
   }
 
index ac86472bfbda6232f93aa883ec23abca9916590e..968335bf674c1a60e74cf69d68500719c2a490a6 100644 (file)
@@ -20,6 +20,7 @@ struct image_dup_context {
   uns flags;
   uns ratio_threshold;
   uns error_threshold;
+  uns qtree_limit;
   u64 sum_depth;
   u64 sum_pixels;
 };
@@ -37,8 +38,9 @@ struct image_dup {
 
 void image_dup_context_init(struct image_context *ic, struct image_dup_context *ctx);
 void image_dup_context_cleanup(struct image_dup_context *ctx);
-uns image_dup_estimate_size(uns cols, uns rows);
-uns image_dup_new(struct image_context *ctx, struct image *image, void *buffer);
+
+uns image_dup_estimate_size(uns cols, uns rows, uns same_size_compare, uns qtree_limit);
+uns image_dup_new(struct image_dup_context *ctx, struct image *image, void *buffer, uns same_size_compare);
 
 /* dup-cmp.c */
 
index 048b53f371d4e01d2f1d6349ee7a6a1c436ec778..93fde378819e8573df42257a6fe7cb68fd65b775 100644 (file)
@@ -151,12 +151,12 @@ main(int argc, char **argv)
   struct image_dup *dup1, *dup2;
   struct mempool *pool = mp_new(1 << 18);
   MSG("Creating internal structures");
-  dup1 = mp_start(pool, image_dup_estimate_size(img1->cols, img1->rows));
-  uns size = image_dup_new(&ctx, img1, dup1);
+  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));
-  size = image_dup_new(&ctx, img2, dup2);
+  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);