From 666a0a6f83f73c031f75ab703cbd36f24d5627fc Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 12 Sep 2014 14:01:20 +0100 Subject: [PATCH] fix avg of complex oops, can't avg mod2, duh --- libvips/arithmetic/avg.c | 14 ++++---------- python/test_arithmetic.py | 2 +- python/vips8/vips.py | 2 ++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/libvips/arithmetic/avg.c b/libvips/arithmetic/avg.c index ca49214f..f2bdcf8b 100644 --- a/libvips/arithmetic/avg.c +++ b/libvips/arithmetic/avg.c @@ -32,6 +32,8 @@ * - remove liboil * 24/8/11 * - rewrite as a class + * 12/9/14 + * - oops, fix complex avg */ /* @@ -98,17 +100,11 @@ vips_avg_build( VipsObject *object ) if( VIPS_OBJECT_CLASS( vips_avg_parent_class )->build( object ) ) return( -1 ); - /* Calculate average. For complex, we accumulate re*re + - * im*im, so we need to sqrt. - */ vals = (gint64) vips_image_get_width( statistic->in ) * vips_image_get_height( statistic->in ) * vips_image_get_bands( statistic->in ); average = avg->sum / vals; - if( vips_band_format_iscomplex( - vips_image_get_format( statistic->in ) ) ) - average = sqrt( average ); g_object_set( object, "out", average, NULL ); return( 0 ); @@ -151,12 +147,10 @@ vips_avg_stop( VipsStatistic *statistic, void *seq ) TYPE *p = (TYPE *) in; \ \ for( i = 0; i < sz; i++ ) { \ - double mod; \ - \ - mod = p[0] * p[0] + p[1] * p[1]; \ - p += 2; \ + double mod = sqrt( p[0] * p[0] + p[1] * p[1] ); \ \ m += mod; \ + p += 2; \ } \ } diff --git a/python/test_arithmetic.py b/python/test_arithmetic.py index e92180d8..82acb2ce 100755 --- a/python/test_arithmetic.py +++ b/python/test_arithmetic.py @@ -33,7 +33,7 @@ class TestArithmetic(unittest.TestCase): def add12(x): return x + 12 - self.assertEqual([add12(x).avg for x in self.test_set], + self.assertEqual([add12(x).avg() for x in self.test_set], [add12(x) for x in self.avgs]) if __name__ == '__main__': diff --git a/python/vips8/vips.py b/python/vips8/vips.py index a080b572..c193a0f6 100644 --- a/python/vips8/vips.py +++ b/python/vips8/vips.py @@ -185,6 +185,8 @@ def _call_base(name, required, optional, self = None, option_string = None): if len(out) == 1: out = out[0] + elif len(out) == 0: + out = None # unref everything now we have refs to all outputs we want op2.unref_outputs()