diff --git a/TODO b/TODO index dc6ed5fd..12072e97 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,11 @@ nip2: im_prepare.c:324: im_prepare_to: Assertion `clipped.left == r->left' failed. + also, im_spcor a rectangular image one pixel smaller with itself and the + peak comes at (eg. 134x134) rather than in the centre of the image + + suspicious! + - doing im_create_fmask() and friends - how about im_invalidate_area()? we currently repaint the whole window on diff --git a/libvips/convolution/im_spcor.c b/libvips/convolution/im_spcor.c index 252bc458..b7c552fa 100644 --- a/libvips/convolution/im_spcor.c +++ b/libvips/convolution/im_spcor.c @@ -86,26 +86,34 @@ typedef struct { double c1; /* sqrt(sumij (ref(i,j)-mean(ref))^2) */ } Spcor; -#define LOOP(IN) { \ +#define LOOP( IN ) { \ IN *a = (IN *) p; \ IN *b = (IN *) ref->data; \ int in_lsk = lsk / sizeof( IN ); \ - IN *a1, *b1; \ + IN *a1; \ + IN *b1; \ \ /* For each pel in or, loop over ref. First, \ * calculate mean of area in ir corresponding to ref. \ */ \ - for( a1 = a, sum1 = 0, j = 0; j < ref->Ysize; j++, a1 += in_lsk ) \ + a1 = a; \ + sum1 = 0; \ + for( j = 0; j < ref->Ysize; j++ ) { \ for( i = 0; i < ref->Xsize; i++ ) \ sum1 += a1[i]; \ - imean = (double) sum1 / (ref->Xsize * ref->Ysize); \ + a1 += in_lsk; \ + } \ + imean = sum1 / (ref->Xsize * ref->Ysize); \ \ /* Loop over ir again, this time calculating \ * sum-of-squares-of-differences for this window on \ * ir, and also sum-of-products-of-differences from mean. \ */ \ - for( a1 = a, b1 = b, sum2 = 0.0, sum3 = 0.0, j = 0; \ - j < ref->Ysize; j++, a1 += in_lsk, b1 += ref->Xsize ) { \ + a1 = a; \ + b1 = b; \ + sum2 = 0.0; \ + sum3 = 0.0; \ + for( j = 0; j < ref->Ysize; j++ ) { \ for( i = 0; i < ref->Xsize; i++ ) { \ /* Reference pel, and input pel. \ */ \ @@ -122,6 +130,8 @@ typedef struct { */ \ sum3 += (rp - spcor->rmean) * (ip - imean); \ } \ + a1 += in_lsk; \ + b1 += ref->Xsize; \ } \ } @@ -137,8 +147,8 @@ spcor_gen( REGION *or, void *vseq, void *a, void *b ) Rect *r = &or->valid; int le = r->left; int to = r->top; - int bo = IM_RECT_BOTTOM(r); - int ri = IM_RECT_RIGHT(r); + int bo = IM_RECT_BOTTOM( r ); + int ri = IM_RECT_RIGHT( r ); int x, y, i, j; int lsk; @@ -196,10 +206,10 @@ static Spcor * spcor_new( IMAGE *out, IMAGE *ref ) { Spcor *spcor; - int sz = ref->Xsize * ref->Ysize; + size_t sz = ref->Xsize * ref->Ysize; PEL *p = (PEL *) ref->data; double s; - int i; + size_t i; if( !(spcor = IM_NEW( out, Spcor )) ) return( NULL ); @@ -212,7 +222,8 @@ spcor_new( IMAGE *out, IMAGE *ref ) /* Find sqrt-of-sum-of-squares-of-differences. */ - for( s = 0.0, i = 0; i < sz; i++ ) { + s = 0.0; + for( i = 0; i < sz; i++ ) { double t = (int) p[i] - spcor->rmean; s += t * t; } @@ -245,18 +256,11 @@ im_spcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ) */ if( im_check_uncoded( "im_spcor", in ) || im_check_mono( "im_spcor", in ) || - im_check_uncoded( "im_spcor", ref ) || - im_check_mono( "im_spcor", ref ) || + im_check_8or16( "im_spcor", in ) || + im_check_coding_same( "im_spcor", in, ref ) || + im_check_bands_same( "im_spcor", in, ref ) || im_check_format_same( "im_spcor", in, ref ) ) return( -1 ); - if( in->BandFmt != IM_BANDFMT_UCHAR && - in->BandFmt != IM_BANDFMT_CHAR && - in->BandFmt != IM_BANDFMT_SHORT && - in->BandFmt != IM_BANDFMT_USHORT ) { - im_error( "im_spcor", - "%s", _( "input not char/uchar/short/ushort" ) ); - return( -1 ); - } /* Prepare the output image. */ diff --git a/libvips/include/vips/check.h b/libvips/include/vips/check.h index 4d70142e..dc9f28b4 100644 --- a/libvips/include/vips/check.h +++ b/libvips/include/vips/check.h @@ -60,6 +60,7 @@ int im_check_noncomplex( const char *domain, IMAGE *im ); int im_check_complex( const char *domain, IMAGE *im ); int im_check_format( const char *domain, IMAGE *im, VipsBandFmt fmt ); int im_check_u8or16( const char *domain, IMAGE *im ); +int im_check_8or16( const char *domain, IMAGE *im ); int im_check_format_same( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_size_same( const char *domain, IMAGE *im1, IMAGE *im2 ); int im_check_vector( const char *domain, int n, IMAGE *im ); diff --git a/libvips/iofuncs/check.c b/libvips/iofuncs/check.c index 181f4698..cd24c96b 100644 --- a/libvips/iofuncs/check.c +++ b/libvips/iofuncs/check.c @@ -865,6 +865,35 @@ im_check_uint( const char *domain, IMAGE *im ) return( 0 ); } +/** + * im_check_8or16: + * @domain: the originating domain for the error message + * @im: image to check + * + * Check that the image is 8 or 16-bit integer, signed or unsigned. + * Otherwise set an error message + * and return non-zero. + * + * See also: im_error(). + * + * Returns: 0 if OK, -1 otherwise. + */ +int +im_check_8or16( const char *domain, IMAGE *im ) +{ + if( im->BandFmt != IM_BANDFMT_UCHAR && + im->BandFmt != IM_BANDFMT_USHORT && + im->BandFmt != IM_BANDFMT_CHAR && + im->BandFmt != IM_BANDFMT_SHORT ) { + im_error( domain, "%s", + _( "image must be 8- or 16-bit integer, " + "signed or unsigned" ) ); + return( -1 ); + } + + return( 0 ); +} + /** * im_check_u8or16: * @domain: the originating domain for the error message diff --git a/libvips/resample/mbicubic.cpp b/libvips/resample/mbicubic.cpp index 4394f4d1..7d06efa8 100644 --- a/libvips/resample/mbicubic.cpp +++ b/libvips/resample/mbicubic.cpp @@ -624,7 +624,6 @@ vips_interpolate_mbicubic_interpolate( VipsInterpolate* restrict interpolate, static void vips_interpolate_mbicubic_class_init( VipsInterpolateMbicubicClass *klass ) { - GObjectClass *gobject_class = G_OBJECT_CLASS( klass ); VipsObjectClass *object_class = VIPS_OBJECT_CLASS( klass ); VipsInterpolateClass *interpolate_class = VIPS_INTERPOLATE_CLASS( klass );