X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=images%2Fdup-cmp.c;h=e16f0634c2b3ff82f6bbf4d9423bf0df6bfb0e84;hb=511633192ca7f4c1ce412c4bb11f1299f2b13211;hp=e05fae3de30f49c9e9c092f0d5cbb6474f1a5668;hpb=2f678dc9ccd4cd88531c97ad48375074db3ad8be;p=libucw.git diff --git a/images/dup-cmp.c b/images/dup-cmp.c index e05fae3d..e16f0634 100644 --- a/images/dup-cmp.c +++ b/images/dup-cmp.c @@ -9,9 +9,9 @@ #undef LOCAL_DEBUG -#include "lib/lib.h" -#include "lib/mempool.h" -#include "lib/fastbuf.h" +#include "ucw/lib.h" +#include "ucw/mempool.h" +#include "ucw/fastbuf.h" #include "images/images.h" #include "images/duplicates.h" @@ -91,6 +91,7 @@ static int blocks_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct image_dup *dup2, uns tab_col, uns tab_row, uns trans) { DBG("blocks_compare(tab_col=%d tab_row=%d trans=%d)", tab_col, tab_row, trans); + ctx->sum_pixels += 1 << (tab_col + tab_row); byte *block1 = image_dup_block(dup1, tab_col, tab_row); byte *block2; int col_step, row_step; @@ -103,6 +104,7 @@ blocks_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct ima case 0: ; uns err = (err_sum(block1, block2, 1 << (tab_col + tab_row)) >> (tab_col + tab_row)); DBG("average error=%d", err); + ctx->error = err; return err <= ctx->error_threshold; case 1: col_step = -3; @@ -143,6 +145,7 @@ blocks_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct ima } uns err = (err_sum_transformed(block1, block2, (1 << tab_col), (1 << tab_row), (3 << tab_col), col_step, row_step) >> (tab_col + tab_row)); DBG("average error=%d", err); + ctx->error = err; return err <= ctx->error_threshold; } @@ -151,6 +154,9 @@ 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; int col_step, row_step; @@ -200,13 +206,14 @@ same_size_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct } uns err = (err_sum_transformed(block1, block2, img1->cols, img1->rows, img1->row_size, col_step, row_step) / ((u64)img1->cols * img1->rows)); DBG("average error=%d", err); + ctx->error = err; return err <= ctx->error_threshold; } uns image_dup_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct image_dup *dup2) { - DBG("image_dup_compare()"); + DBG("image_dup_compare(%p, %p)", dup1, dup2); if (!average_compare(ctx, dup1, dup2)) return 0; struct image *img1 = &dup1->image; @@ -239,8 +246,10 @@ image_dup_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct if (flags & (1 << t)) { DBG("Testing trans %d", t); - for (uns i = MAX(cols, rows); i--; ) + uns i = MAX(cols, rows), depth = 1; + while (i--) { + depth++; uns col = MAX(0, (int)(cols - i)); uns row = MAX(0, (int)(rows - i)); if (!blocks_compare(ctx, dup1, dup2, col, row, t)) @@ -256,6 +265,7 @@ image_dup_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct break; } } + ctx->sum_depth += depth; } } if (flags & 0xf0) @@ -266,8 +276,10 @@ image_dup_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct if (flags & (1 << t)) { DBG("Testing trans %d", t); - for (uns i = MAX(cols, rows); i--; ) + uns i = MAX(cols, rows), depth = 1; + while (i--) { + depth++; uns col = MAX(0, (int)(cols - i)); uns row = MAX(0, (int)(rows - i)); if (!blocks_compare(ctx, dup1, dup2, col, row, t)) @@ -283,6 +295,7 @@ image_dup_compare(struct image_dup_context *ctx, struct image_dup *dup1, struct break; } } + ctx->sum_depth += depth; } } return result;