X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fdup-init.c;h=ea886d0955298b4a26080e1a1768fcbaa3021bc2;hb=493017924f02d69dcc554af0671c514f7a39c2f8;hp=da4b2be4d743114364a62f7f2a4fb4996a770712;hpb=dc4188d47a7e1ac0df29797dcb452b0c2460b634;p=libucw.git diff --git a/images/dup-init.c b/images/dup-init.c index da4b2be4..ea886d09 100644 --- a/images/dup-init.c +++ b/images/dup-init.c @@ -1,7 +1,7 @@ /* * Image Library -- Duplicates Comparison * - * (c) 2006 Pavel Charvat + * (c) 2006--2007 Pavel Charvat * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -9,20 +9,36 @@ #undef LOCAL_DEBUG -#include "sherlock/sherlock.h" +#include "lib/lib.h" #include "lib/mempool.h" #include "lib/fastbuf.h" #include "images/images.h" +#include "images/color.h" #include "images/duplicates.h" #include -static uns image_dup_tab_limit = 8; +void +image_dup_context_init(struct image_context *ic, struct image_dup_context *ctx) +{ + *ctx = (struct image_dup_context) { + .ic = ic, + .flags = IMAGE_DUP_TRANS_ID, + .ratio_threshold = 140, + .error_threshold = 100, + .qtree_limit = 8, + }; +} + +void +image_dup_context_cleanup(struct image_dup_context *ctx UNUSED) +{ +} static inline struct image * -image_dup_subimage(struct image_thread *thread, struct image_dup *dup, struct image *block, uns tab_col, uns tab_row) +image_dup_subimage(struct image_context *ctx, struct image_dup *dup, struct image *block, uns tab_col, uns tab_row) { - return image_init_matrix(thread, block, image_dup_block(dup, tab_col, tab_row), + return image_init_matrix(ctx, block, image_dup_block(dup, tab_col, tab_row), 1 << tab_col, 1 << tab_row, 3 << tab_col, COLOR_SPACE_RGB); } @@ -35,33 +51,66 @@ 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++); - return sizeof(struct image) + cols * rows * 3 + sizeof(struct image_dup) + (12 << (tab_cols + tab_rows)) + 64; + 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_init(struct image_thread *thread, struct image_dup *dup, struct image *img, struct mempool *pool) +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))); + void *ptr = buffer; + + /* Allocate the structure */ + struct image_dup *dup = ptr; + ptr += ALIGN_TO(sizeof(*dup), CPU_STRUCT_ALIGN); + bzero(dup, sizeof(*dup)); ASSERT((img->flags & IMAGE_PIXEL_FORMAT) == COLOR_SPACE_RGB); - dup->image = img; - 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++); - dup->tab_pixels = mp_alloc(pool, dup->tab_size = (12 << (dup->tab_cols + dup->tab_rows))); + /* Clone image */ + 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 + { + 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 < 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; + 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(thread, 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(thread, &block, img)) + if (!image_scale(ctx->ic, &block, img)) return 0; } @@ -91,7 +140,7 @@ image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image { for (uns x = 0; x < (uns)(1 << i); x++) { - pixels_average(d, s, s + line_size); + pixels_average(d, s, s + line_size); d += 3; s += 3; } @@ -100,5 +149,5 @@ image_dup_init(struct image_thread *thread, struct image_dup *dup, struct image } } - return 1; + return ptr - buffer; }