From f8eb8bab9f7a35b8c3249517715134693e5920dc Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Mon, 7 Aug 2006 22:38:23 +0200 Subject: [PATCH] - first version of image duplicates, now I'll do some experiments with speed and parameters... there are many possible optimizations --- images/dup-cmp.c | 21 +++++++++++++++++---- images/dup-cmp.h | 5 +++-- images/object.c | 5 ++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/images/dup-cmp.c b/images/dup-cmp.c index 6b8155ae..35e1ec8e 100644 --- a/images/dup-cmp.c +++ b/images/dup-cmp.c @@ -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 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; } } } diff --git a/images/dup-cmp.h b/images/dup-cmp.h index 3b24d3ef..bfb24483 100644 --- a/images/dup-cmp.h +++ b/images/dup-cmp.h @@ -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 diff --git a/images/object.c b/images/object.c index 3935f89b..d817e1c9 100644 --- a/images/object.c +++ b/images/object.c @@ -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: -- 2.39.5