]> mj.ucw.cz Git - libucw.git/commitdiff
- first version of image duplicates, now I'll do some experiments
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Mon, 7 Aug 2006 20:38:23 +0000 (22:38 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Mon, 7 Aug 2006 20:38:23 +0000 (22:38 +0200)
  with speed and parameters... there are many possible optimizations

images/dup-cmp.c
images/dup-cmp.h
images/object.c

index 6b8155ae20bc1e4d99a10063cab4c7d2779a8ffe..35e1ec8e99d992b9be072502dee5c28f31cb0300 100644 (file)
@@ -18,7 +18,7 @@
  *        for aspect ratio threshold near one
  */
 
-#define LOCAL_DEBUG
+#undef LOCAL_DEBUG
 
 #include "sherlock/sherlock.h"
 #include "lib/mempool.h"
@@ -30,7 +30,7 @@
 #include <fcntl.h>
 
 static uns image_dup_ratio_threshold = 140;
-static uns image_dup_error_threshold = 600;
+static uns image_dup_error_threshold = 800;
 static uns image_dup_tab_limit = 8;
 
 static inline byte *
@@ -54,7 +54,16 @@ pixels_average(byte *dest, byte *src1, byte *src2)
   dest[2] = ((uns)src1[2] + (uns)src2[2]) >> 1;
 }
 
-int
+uns
+image_dup_estimate_size(uns cols, uns rows)
+{
+  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++);
+  return sizeof(struct image) + cols * rows * 3 + sizeof(struct image_dup) + (12 << (tab_cols + tab_rows)) + 64;
+}
+
+uns
 image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *img, struct mempool *pool)
 {
   DBG("image_dup_init()");
@@ -300,7 +309,7 @@ same_size_compare(struct image_dup *dup1, struct image_dup *dup2, uns trans)
   return err <= image_dup_error_threshold;
 }
 
-int
+uns
 image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags)
 {
   DBG("image_dup_compare()");
@@ -348,6 +357,8 @@ image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags)
                    result |= 1 << t;
                    if (!(flags & IMAGE_DUP_WANT_ALL))
                      return result;
+                   else
+                     break;
                  }
              }
          }
@@ -373,6 +384,8 @@ image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags)
                    result |= 1 << t;
                    if (!(flags & IMAGE_DUP_WANT_ALL))
                      return result;
+                   else
+                     break;
                  }
              }
          }
index 3b24d3ef996bd02c9b6986374c3810c843745440..bfb24483dde7c128195a071e73f1509f3120e4bf 100644 (file)
@@ -22,7 +22,8 @@ struct image_dup {
 #define IMAGE_DUP_SCALE                0x100
 #define IMAGE_DUP_WANT_ALL     0x200
 
-int image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *image, struct mempool *pool);
-int image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags);
+uns image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image *image, struct mempool *pool);
+uns image_dup_compare(struct image_dup *dup1, struct image_dup *dup2, uns flags);
+uns image_dup_estimate_size(uns cols, uns rows);
 
 #endif
index 3935f89b6e37712cd388b2548f4364720e046574..d817e1c92f10c519d087073e316c2f10fc5fd242 100644 (file)
@@ -6,7 +6,7 @@
  *     This software may be freely distributed and used according to the terms
  */
 
-#define LOCAL_DEBUG
+#undef LOCAL_DEBUG
 
 #include "sherlock/sherlock.h"
 #include "lib/base224.h"
@@ -75,9 +75,8 @@ read_image_obj_thumb(struct image_obj_info *ioi, struct fastbuf *fb, struct imag
   if (!io->background_color.color_space)
     io->background_color = color_white;
   struct image *img;
-  if (!(img = image_io_read_data(io, 0)))
+  if (!(img = image_io_read_data(io, 1)))
     goto error;
-  ASSERT(img->cols == ioi->thumb_cols && img->rows == ioi->thumb_rows);
   DBG("Decompressed thumbnail: size=%ux%u", img->cols, img->rows);
   return img;
 error: