more hist_local fixups
add tests, add restrict
This commit is contained in:
parent
9660036216
commit
c963678549
@ -172,10 +172,12 @@ vips_hist_local_generate( VipsRegion *or,
|
|||||||
for( y = 0; y < r->height; y++ ) {
|
for( y = 0; y < r->height; y++ ) {
|
||||||
/* Get input and output pointers for this line.
|
/* Get input and output pointers for this line.
|
||||||
*/
|
*/
|
||||||
VipsPel *p = VIPS_REGION_ADDR( seq->ir, r->left, r->top + y );
|
VipsPel * restrict p =
|
||||||
VipsPel *q = VIPS_REGION_ADDR( or, r->left, r->top + y );
|
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;
|
int x, i, j, b;
|
||||||
|
|
||||||
/* Find histogram for start of this line.
|
/* Find histogram for start of this line.
|
||||||
@ -197,8 +199,8 @@ vips_hist_local_generate( VipsRegion *or,
|
|||||||
for( b = 0; b < bands; b++ ) {
|
for( b = 0; b < bands; b++ ) {
|
||||||
/* Sum histogram up to current pel.
|
/* Sum histogram up to current pel.
|
||||||
*/
|
*/
|
||||||
unsigned int *hist = seq->hist[b];
|
unsigned int * restrict hist = seq->hist[b];
|
||||||
const int target = p[centre];
|
const int target = p[centre + b];
|
||||||
const int max_slope = local->max_slope;
|
const int max_slope = local->max_slope;
|
||||||
|
|
||||||
int sum;
|
int sum;
|
||||||
@ -251,23 +253,24 @@ vips_hist_local_generate( VipsRegion *or,
|
|||||||
* Scale by 255, not 256, or we'll get
|
* Scale by 255, not 256, or we'll get
|
||||||
* overflow.
|
* overflow.
|
||||||
*/
|
*/
|
||||||
*q++ = 255 * sum /
|
q[b] = 255 * sum /
|
||||||
(local->width * local->height);
|
(local->width * local->height);
|
||||||
|
|
||||||
/* Adapt histogram --- remove the pels from
|
/* Adapt histogram --- remove the pels from
|
||||||
* the left hand column, add in pels for a
|
* the left hand column, add in pels for a
|
||||||
* new right-hand column.
|
* new right-hand column.
|
||||||
*/
|
*/
|
||||||
p1 = p;
|
p1 = p + b;
|
||||||
for( j = 0; j < local->height; j++ ) {
|
for( j = 0; j < local->height; j++ ) {
|
||||||
hist[p1[0]] -= 1;
|
hist[p1[0]] -= 1;
|
||||||
hist[p1[bands * local->width]] += 1;
|
hist[p1[bands * local->width]] += 1;
|
||||||
|
|
||||||
p1 += lsk;
|
p1 += lsk;
|
||||||
}
|
}
|
||||||
|
|
||||||
p += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p += bands;
|
||||||
|
q += bands;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +74,13 @@ class TestHistogram(unittest.TestCase):
|
|||||||
self.assertTrue(im.avg() < im2.avg())
|
self.assertTrue(im.avg() < im2.avg())
|
||||||
self.assertTrue(im.deviate() < im2.deviate())
|
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):
|
def test_hist_match(self):
|
||||||
im = Vips.Image.identity()
|
im = Vips.Image.identity()
|
||||||
im2 = Vips.Image.identity()
|
im2 = Vips.Image.identity()
|
||||||
|
Loading…
Reference in New Issue
Block a user