X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=images%2Fsig-seg.c;h=082a1c8e5bcfc9dd02d832f677090431796a48ab;hb=b56cd57bdce6b573ac0fc973ba4d16057c1e2ca5;hp=7e6e09f5a2a802ad1e71870848af0e9883ff65b2;hpb=3cbca97fcc3bd2708329315fa60e535ba319b9d2;p=libucw.git diff --git a/images/sig-seg.c b/images/sig-seg.c index 7e6e09f5..082a1c8e 100644 --- a/images/sig-seg.c +++ b/images/sig-seg.c @@ -7,11 +7,11 @@ * of the GNU Lesser General Public License. */ -#define LOCAL_DEBUG +#undef LOCAL_DEBUG -#include "sherlock/sherlock.h" -#include "lib/conf.h" -#include "lib/heap.h" +#include "ucw/lib.h" +#include "ucw/conf.h" +#include "ucw/heap.h" #include "images/images.h" #include "images/signature.h" #include "images/math.h" @@ -68,7 +68,9 @@ static void prequant_finish_region(struct image_sig_region *region) { if (region->count < 2) - memcpy(region->c, region->a, sizeof(region->c)); + { + region->e = 0; + } else { u64 a = 0; @@ -91,9 +93,7 @@ prequant_heap_cmp(struct image_sig_region *a, struct image_sig_region *b) #define ASORT_PREFIX(x) prequant_##x #define ASORT_KEY_TYPE uns -#define ASORT_ELT(i) val[i] -#define ASORT_EXTRA_ARGS , uns *val -#include "lib/arraysort.h" +#include "ucw/sorter/array-simple.h" static uns prequant(struct image_sig_block *blocks, uns blocks_count, struct image_sig_region *regions) @@ -120,13 +120,13 @@ prequant(struct image_sig_block *blocks, uns blocks_count, struct image_sig_regi DBG("Step... regions_count=%u heap_count=%u region->count=%u, region->e=%u", regions_count, heap_count, region->count, (uns)region->e); if (region->count < 2 || - region->e < image_sig_prequant_thresholds[regions_count - 1] * region->count) + region->e < image_sig_prequant_thresholds[regions_count - 1] * blocks_count) { HEAP_DELMIN(struct image_sig_region *, heap, heap_count, prequant_heap_cmp, HEAP_SWAP); continue; } - /* Select axis to split - the one with maximum covariance */ + /* Select axis to split - the one with maximum average quadratic error */ axis = 0; u64 cov = (u64)region->count * region->c[0] - (u64)region->b[0] * region->b[0]; for (uns i = 1; i < 6; i++) @@ -161,7 +161,7 @@ prequant(struct image_sig_block *blocks, uns blocks_count, struct image_sig_regi block = region->blocks; for (uns i = 0; i < region->count; i++, block = block->next) val[i] = block->v[axis]; - prequant_sort(region->count, val); + prequant_sort(val, region->count); cval = 1; cnt[0] = 1; for (uns i = 1; i < region->count; i++) @@ -174,7 +174,7 @@ prequant(struct image_sig_block *blocks, uns blocks_count, struct image_sig_regi cval++; } } - + /* Select split value - to minimize error */ uns b1 = val[0] * cnt[0]; uns c1 = isqr(val[0]) * cnt[0]; @@ -193,14 +193,14 @@ prequant(struct image_sig_block *blocks, uns blocks_count, struct image_sig_regi c2 -= c0; i += cnt[k]; j -= cnt[k]; - u64 err = (u64)c1 - (u64)b1 * b1 / i + (u64)c2 - (u64)b2 * b2 / j; + u64 err = (u64)c1 - (u64)b1 * b1 / i + (u64)c2 - (u64)b2 * b2 / j; if (err < best_err) { best_err = err; split_val = val[k]; } } - DBG("split_val=%u best_err=%Lu b[axis]=%u c[axis]=%u", split_val, (long long)best_err, region->b[axis], region->c[axis]); + DBG("split_val=%u best_err=%llu b[axis]=%u c[axis]=%u", split_val, (long long)best_err, region->b[axis], region->c[axis]); /* Split region */ block = region->blocks; @@ -324,7 +324,7 @@ postquant(struct image_sig_block *blocks, uns blocks_count, struct image_sig_reg if (error > last_error) break; u64 dif = last_error - error; - if (dif * image_sig_postquant_threshold < last_error * 100) + if (dif * image_sig_postquant_threshold < (u64)last_error * 100) break; } }