From ddc31fda73ecc32ccdcba3b0a2a9db1ed8dd66b2 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Wed, 6 Sep 2006 23:00:56 +0200 Subject: [PATCH] imagesim explain: fastbuf replaced with callback --- images/image-sim-test.c | 8 ++++++- images/sig-cmp-gen.h | 48 +++++++++++++++++++++++++---------------- images/sig-cmp.c | 7 +++--- images/signature.h | 2 +- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/images/image-sim-test.c b/images/image-sim-test.c index e0a1899e..bac384ec 100644 --- a/images/image-sim-test.c +++ b/images/image-sim-test.c @@ -62,6 +62,12 @@ static byte *segmentation_name_2; #define MSG(x...) do{ if (verbose) log(L_INFO, ##x); }while(0) #define TRY(x) do{ if (!(x)) die("Error: %s", it.err_msg); }while(0) +static void +msg_str(byte *s, void *param UNUSED) +{ + MSG("%s", s); +} + static void dump_signature(struct image_signature *sig) { @@ -268,7 +274,7 @@ main(int argc, char **argv) if (verbose) { struct fastbuf *fb = bfdopen(0, 4096); - dist = image_signatures_dist_explain(&sig1, &sig2, fb); + dist = image_signatures_dist_explain(&sig1, &sig2, msg_str, NULL); bclose(fb); } else diff --git a/images/sig-cmp-gen.h b/images/sig-cmp-gen.h index 804f1f0c..ef6d2446 100644 --- a/images/sig-cmp-gen.h +++ b/images/sig-cmp-gen.h @@ -1,21 +1,25 @@ -#ifndef SIG_EXPLAIN +#ifndef EXPLAIN #define MSG(x...) do{}while(0) +#define LINE do{}while(0) static uns image_signatures_dist_2(struct image_signature *sig1, struct image_signature *sig2) #else -#define MSG(x...) bprintf(fb, x) +#define MSG(x...) do{ line += sprintf(line, x); }while(0) +#define LINE do{ line = buf; msg(line, param); }while(0) static void -dump_signature(struct image_signature *sig, struct fastbuf *fb) +explain_signature(struct image_signature *sig, void (*msg)(byte *text, void *param), void *param) { + byte buf[1024], *line = buf; MSG("signature: flags=0x%x df=%u dh=%u f=(%u", sig->flags, sig->df, sig->dh, sig->vec.f[0]); for (uns i = 1; i < IMAGE_VEC_F; i++) MSG(" %u", sig->vec.f[i]); - MSG(")\n"); + MSG(")"); + LINE; for (uns j = 0; j < sig->len; j++) { struct image_region *reg = sig->reg + j; @@ -25,12 +29,13 @@ dump_signature(struct image_signature *sig, struct fastbuf *fb) MSG(") h=(%u", reg->h[0]); for (uns i = 1; i < IMAGE_REG_H; i++) MSG(" %u", reg->h[i]); - MSG(")\n"); + MSG(")"); + LINE; } } static uns -image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signature *sig2, struct fastbuf *fb) +image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signature *sig2, void (*msg)(byte *text, void *param), void *param) #endif { @@ -39,15 +44,16 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa uns dist[IMAGE_REG_MAX * IMAGE_REG_MAX], p[IMAGE_REG_MAX], q[IMAGE_REG_MAX]; uns n, i, j, k, l, s, d; struct image_region *reg1, *reg2; - -#ifdef SIG_EXPLAIN - dump_signature(sig1, fb); - dump_signature(sig2, fb); +#ifdef EXPLAIN + byte buf[1024], *line = buf; + explain_signature(sig1, msg, param); + explain_signature(sig2, msg, param); #endif /* Compute distance matrix */ n = 0; - MSG("Distance matrix:\n"); + MSG("Distance matrix:"); + LINE; /* ... for non-textured images */ if (!((sig1->flags | sig2->flags) & IMAGE_SIG_TEXTURED)) for (j = 0, reg2 = sig2->reg; j < sig2->len; j++, reg2++) @@ -70,9 +76,10 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa dt *= 12; else dt *= 16; - DBG("[%u][%u] ... dt=%u ds=%u", i, j, dt, ds); dist[n++] = (dt << 8) + i + (j << 4); - MSG("[%u, %u] ... dt=%u ds=%u\n", i, j, dt, ds); + DBG("[%u, %u] dt=%u ds=%u", i, j, dt, ds); + MSG("[%u, %u] dt=%u ds=%u", i, j, dt, ds); + LINE; } /* ... for textured images (ignore shape properties) */ else @@ -87,7 +94,9 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa isqr((int)reg1->f[4] - (int)reg2->f[4]) + isqr((int)reg1->f[5] - (int)reg2->f[5]); dist[n++] = (dt << 12) + i + (j << 4); - MSG("[%u, %u] ... dt=%u\n", i, j, dt); + DBG("[%u, %u] dt=%u", i, j, dt); + MSG("[%u, %u] dt=%u", i, j, dt); + LINE; } /* One or both signatures have no regions */ @@ -105,7 +114,8 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa /* Compute significance matrix and resulting distance */ uns sum = 0; - MSG("Significance matrix:\n"); + MSG("Significance matrix:"); + LINE; for (k = 0, l = 128; l; k++) { i = dist[k] & 15; @@ -125,12 +135,14 @@ image_signatures_dist_2_explain(struct image_signature *sig1, struct image_signa } l -= s; sum += s * d; - DBG("s[%u][%u]=%u d=%u", i, j, s, d); - MSG("[%u, %u]=%u d=%u\n", i, j, s, d); + DBG("[%u, %u] s=%u d=%u", i, j, s, d); + MSG("[%u, %u] s=%u d=%u", i, j, s, d); + LINE; } return sum; } -#undef SIG_EXPLAIN +#undef EXPLAIN #undef MSG +#undef LINE diff --git a/images/sig-cmp.c b/images/sig-cmp.c index b7cd2ed1..3d22a1f3 100644 --- a/images/sig-cmp.c +++ b/images/sig-cmp.c @@ -11,7 +11,6 @@ #include "lib/lib.h" #include "lib/math.h" -#include "lib/fastbuf.h" #include "images/math.h" #include "images/images.h" #include "images/signature.h" @@ -119,7 +118,7 @@ image_signatures_dist_1(struct image_signature *sig1, struct image_signature *si #define ASORT_EXTRA_ARGS , uns *items #include "lib/arraysort.h" -#define SIG_EXPLAIN +#define EXPLAIN #include "images/sig-cmp-gen.h" #include "images/sig-cmp-gen.h" @@ -138,10 +137,10 @@ image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2 } uns -image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, struct fastbuf *fb) +image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, void (*msg)(byte *text, void *param), void *param) { if (image_sig_compare_method == 2) - return image_signatures_dist_2_explain(sig1, sig2, fb); + return image_signatures_dist_2_explain(sig1, sig2, msg, param); return image_signatures_dist(sig1, sig2); } diff --git a/images/signature.h b/images/signature.h index 597e016d..e84c7f31 100644 --- a/images/signature.h +++ b/images/signature.h @@ -118,7 +118,7 @@ void image_sig_detect_textured(struct image_sig_data *data); /* sig-cmp.c */ uns image_signatures_dist(struct image_signature *sig1, struct image_signature *sig2); -uns image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, struct fastbuf *fb); +uns image_signatures_dist_explain(struct image_signature *sig1, struct image_signature *sig2, void (*msg)(byte *text, void *param), void *param); #endif -- 2.39.5