From c96367854991dde1a0162349221a103d75853186 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 22 Jan 2017 10:36:07 +0000 Subject: [PATCH] more hist_local fixups add tests, add restrict --- libvips/histogram/hist_local.c | 21 ++++++++++++--------- test/test_histogram.py | 7 +++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libvips/histogram/hist_local.c b/libvips/histogram/hist_local.c index 950074bc..b1085053 100644 --- a/libvips/histogram/hist_local.c +++ b/libvips/histogram/hist_local.c @@ -172,10 +172,12 @@ vips_hist_local_generate( VipsRegion *or, for( y = 0; y < r->height; y++ ) { /* Get input and output pointers for this line. */ - VipsPel *p = VIPS_REGION_ADDR( seq->ir, r->left, r->top + y ); - VipsPel *q = VIPS_REGION_ADDR( or, r->left, r->top + y ); + VipsPel * restrict p = + VIPS_REGION_ADDR( seq->ir, r->left, r->top + y ); + VipsPel * restrict q = + VIPS_REGION_ADDR( or, r->left, r->top + y ); - VipsPel *p1; + VipsPel * restrict p1; int x, i, j, b; /* Find histogram for start of this line. @@ -197,8 +199,8 @@ vips_hist_local_generate( VipsRegion *or, for( b = 0; b < bands; b++ ) { /* Sum histogram up to current pel. */ - unsigned int *hist = seq->hist[b]; - const int target = p[centre]; + unsigned int * restrict hist = seq->hist[b]; + const int target = p[centre + b]; const int max_slope = local->max_slope; int sum; @@ -251,23 +253,24 @@ vips_hist_local_generate( VipsRegion *or, * Scale by 255, not 256, or we'll get * overflow. */ - *q++ = 255 * sum / + q[b] = 255 * sum / (local->width * local->height); /* Adapt histogram --- remove the pels from * the left hand column, add in pels for a * new right-hand column. */ - p1 = p; + p1 = p + b; for( j = 0; j < local->height; j++ ) { hist[p1[0]] -= 1; hist[p1[bands * local->width]] += 1; p1 += lsk; } - - p += 1; } + + p += bands; + q += bands; } } diff --git a/test/test_histogram.py b/test/test_histogram.py index dbacba5d..43a32cba 100755 --- a/test/test_histogram.py +++ b/test/test_histogram.py @@ -74,6 +74,13 @@ class TestHistogram(unittest.TestCase): self.assertTrue(im.avg() < im2.avg()) self.assertTrue(im.deviate() < im2.deviate()) + im3 = im.hist_local(10, 10, max_slope = 3) + + self.assertEqual(im.width, im2.width) + self.assertEqual(im.height, im2.height) + + self.assertTrue(im3.deviate() < im2.deviate()) + def test_hist_match(self): im = Vips.Image.identity() im2 = Vips.Image.identity()