From c9ce8f70a1bc2383e37b2cf6937f171051968498 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 24 Jan 2017 10:51:12 +0000 Subject: [PATCH] fix an off-by-one error in hist_local an odd window width caused an off-by-one error in histogram construction --- ChangeLog | 2 +- libvips/histogram/hist_local.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 74753a90..5cca4acc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,7 +27,7 @@ aferrero2707 - kick load operations from cache on read error, thanks gaillard - fix return from C++ assignment operator overloads (+=, -= etc) -- add @max_slope to vips_local_hist() to implement CLAHE, thanks hunter-87 +- add @max_slope to vips_hist_local() to implement CLAHE, thanks hunter-87 - vips_gaussnoise() pixels are reproducible on recalc, thanks MvGulik 8/12/16 started 8.4.5 diff --git a/libvips/histogram/hist_local.c b/libvips/histogram/hist_local.c index b1085053..b9fed7fb 100644 --- a/libvips/histogram/hist_local.c +++ b/libvips/histogram/hist_local.c @@ -26,6 +26,7 @@ * - sum to <= target, not < target, since cumulative hists include the * current value * - scale result by 255, not 256, to avoid overflow + * - off by 1 fix for odd window widths */ /* @@ -150,7 +151,8 @@ vips_hist_local_generate( VipsRegion *or, VipsImage *in = (VipsImage *) a; const VipsHistLocal *local = (VipsHistLocal *) b; VipsRect *r = &or->valid; - int bands = in->Bands; + const int bands = in->Bands; + const int max_slope = local->max_slope; VipsRect irect; int y; @@ -167,7 +169,7 @@ vips_hist_local_generate( VipsRegion *or, return( -1 ); lsk = VIPS_REGION_LSKIP( seq->ir ); - centre = lsk * (local->height / 2) + bands * local->width / 2; + centre = lsk * (local->height / 2) + bands * (local->width / 2); for( y = 0; y < r->height; y++ ) { /* Get input and output pointers for this line. @@ -201,7 +203,6 @@ vips_hist_local_generate( VipsRegion *or, */ unsigned int * restrict hist = seq->hist[b]; const int target = p[centre + b]; - const int max_slope = local->max_slope; int sum;