diff --git a/ChangeLog b/ChangeLog index 745496df..3e577737 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ - added im_local_imask(), im_local_dmask() - added im_mpercent_hist() - im_maplut() casts the index image to one of the uint types +- fixed a couple of /0 problems with scale == 0 masks 16/1/10 started 7.21.2 - "invalidate" is careful to keep images alive, so invalidate callbacks can do diff --git a/TODO b/TODO index 2ef3eeae..a5ab0a52 100644 --- a/TODO +++ b/TODO @@ -4,8 +4,6 @@ - quite a few hist operations have no GUI ... lhisteq, for example? or histspec? -- conv with scale == 0 gives /0 error - - added im_local_imask(), im_local_dmask(), needs docs? is local_imask() in the best place? shouldn't it be in mask.h? diff --git a/libvips/convolution/im_conv.c b/libvips/convolution/im_conv.c index 069854ca..5d5ec9e8 100644 --- a/libvips/convolution/im_conv.c +++ b/libvips/convolution/im_conv.c @@ -29,7 +29,7 @@ * - reworked and simplified, about 10% faster * - slightly better range clipping * 27/7/01 JC - * - rejects masks with scale == 0 + * - reject masks with scale == 0 * 7/4/04 * - im_conv() now uses im_embed() with edge stretching on the input, not * the output @@ -419,6 +419,10 @@ im_conv_raw( IMAGE *in, IMAGE *out, INTMASK *mask ) im_check_noncomplex( "im_conv", in ) || im_check_imask( "im_conv", mask ) ) return( -1 ); + if( mask->scale == 0 ) { + im_error( "im_conv", "%s", "mask scale must be non-zero" ); + return( -1 ); + } if( !(conv = conv_new( in, out, mask )) ) return( -1 ); diff --git a/libvips/convolution/im_conv_f.c b/libvips/convolution/im_conv_f.c index edb58a5a..9b34d93c 100644 --- a/libvips/convolution/im_conv_f.c +++ b/libvips/convolution/im_conv_f.c @@ -316,6 +316,10 @@ im_conv_f_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ) im_check_noncomplex( "im_conv", in ) || im_check_dmask( "im_conv", mask ) ) return( -1 ); + if( mask->scale == 0 ) { + im_error( "im_conv_f", "%s", "mask scale must be non-zero" ); + return( -1 ); + } if( !(conv = conv_new( in, out, mask )) ) return( -1 ); diff --git a/libvips/convolution/im_convsep.c b/libvips/convolution/im_convsep.c index 8adc52b2..da5da3cd 100644 --- a/libvips/convolution/im_convsep.c +++ b/libvips/convolution/im_convsep.c @@ -381,6 +381,10 @@ im_convsep_raw( IMAGE *in, IMAGE *out, INTMASK *mask ) "%s", _( "expect 1xN or Nx1 input mask" ) ); return( -1 ); } + if( mask->scale == 0 ) { + im_error( "im_convsep", "%s", "mask scale must be non-zero" ); + return( -1 ); + } if( !(conv = conv_new( in, out, mask )) ) return( -1 ); diff --git a/libvips/convolution/im_convsep_f.c b/libvips/convolution/im_convsep_f.c index 0f752f11..01e9ee8e 100644 --- a/libvips/convolution/im_convsep_f.c +++ b/libvips/convolution/im_convsep_f.c @@ -285,6 +285,10 @@ im_convsep_f_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ) "%s", _( "expect 1xN or Nx1 input mask" ) ); return( -1 ); } + if( mask->scale == 0 ) { + im_error( "im_convsep_f", "%s", "mask scale must be non-zero" ); + return( -1 ); + } if( !(conv = conv_new( in, out, mask )) ) return( -1 ); diff --git a/libvips/mask/rw_mask.c b/libvips/mask/rw_mask.c index 25d02ebc..8ed9e488 100644 --- a/libvips/mask/rw_mask.c +++ b/libvips/mask/rw_mask.c @@ -476,6 +476,8 @@ im_scale_dmask( DOUBLEMASK *m, const char *name ) if( dsum == m->scale ) out->scale = isum; + else if( dsum == 0.0 ) + out->scale = 1.0; else out->scale = IM_RINT( m->scale * isum / dsum ); @@ -486,7 +488,7 @@ void im_norm_dmask( DOUBLEMASK *mask ) { const int n = mask->xsize * mask->ysize; - const double scale = 1.0 / mask->scale; + const double scale = (mask->scale == 0) ? 0 : (1.0 / mask->scale); int i;