static int vips_similarity_build( VipsObject *object ) { VipsResample *resample = VIPS_RESAMPLE( object ); VipsSimilarity *similarity = (VipsSimilarity *) object; VipsImage **t = (VipsImage **) vips_object_local_array( object, 4 ); if( VIPS_OBJECT_CLASS( vips_similarity_parent_class )->build( object ) ) return( -1 ); /* Use vips_reduce(), if we can. */ if( similarity->interpolate && strcmp( VIPS_OBJECT_GET_CLASS( similarity->interpolate )-> nickname, "bicubic" ) == 0 && similarity->angle == 0.0 && similarity->idx == 0.0 && similarity->idy == 0.0 && similarity->odx == 0.0 && similarity->ody == 0.0 ) { if( vips_reduce( resample->in, &t[0], 1.0 / similarity->scale, 1.0 / similarity->scale, NULL ) ) return( -1 ); } else { double a = similarity->scale * cos( VIPS_RAD( similarity->angle ) ); double b = similarity->scale * -sin( VIPS_RAD( similarity->angle ) ); double c = -b; double d = a; if( vips_affine( resample->in, &t[0], a, b, c, d, "interpolate", similarity->interpolate, "odx", similarity->odx, "ody", similarity->ody, "idx", similarity->idx, "idy", similarity->idy, NULL ) ) return( -1 ); } if( vips_image_write( t[0], resample->out ) ) return( -1 ); return( 0 ); }
static int vips_similarity_build( VipsObject *object ) { VipsResample *resample = VIPS_RESAMPLE( object ); VipsSimilarity *similarity = (VipsSimilarity *) object; VipsImage **t = (VipsImage **) vips_object_local_array( object, 4 ); gboolean handled; if( VIPS_OBJECT_CLASS( vips_similarity_parent_class )->build( object ) ) return( -1 ); handled = FALSE; /* Use vips_reduce(), if we can. */ if( similarity->interpolate && similarity->angle == 0.0 && similarity->idx == 0.0 && similarity->idy == 0.0 && similarity->odx == 0.0 && similarity->ody == 0.0 ) { const char *nickname = VIPS_OBJECT_GET_CLASS( similarity->interpolate )->nickname; int i; for( i = 0; i < VIPS_NUMBER( vips_similarity_kernel ); i++ ) { VipsInterpolateKernel *ik = &vips_similarity_kernel[i]; if( strcmp( nickname, ik->nickname ) == 0 ) { if( vips_reduce( resample->in, &t[0], 1.0 / similarity->scale, 1.0 / similarity->scale, "kernel", ik->kernel, NULL ) ) return( -1 ); handled = TRUE; break; } } } if( !handled ) { double a = similarity->scale * cos( VIPS_RAD( similarity->angle ) ); double b = similarity->scale * -sin( VIPS_RAD( similarity->angle ) ); double c = -b; double d = a; if( vips_affine( resample->in, &t[0], a, b, c, d, "interpolate", similarity->interpolate, "odx", similarity->odx, "ody", similarity->ody, "idx", similarity->idx, "idy", similarity->idy, NULL ) ) return( -1 ); } if( vips_image_write( t[0], resample->out ) ) return( -1 ); return( 0 ); }