From 0623a05f48baf9026dbb261203b8f892a4c326dc Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 5 Mar 2021 20:19:05 +0000 Subject: [PATCH] remove vips_recip() it wasn't really necessary, and it was rather slow --- libvips/conversion/unpremultiply.c | 4 ++-- libvips/include/vips/util.h | 14 -------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/libvips/conversion/unpremultiply.c b/libvips/conversion/unpremultiply.c index 780eeaa5..88bbbed2 100644 --- a/libvips/conversion/unpremultiply.c +++ b/libvips/conversion/unpremultiply.c @@ -81,7 +81,7 @@ G_DEFINE_TYPE( VipsUnpremultiply, vips_unpremultiply, VIPS_TYPE_CONVERSION ); \ for( x = 0; x < width; x++ ) { \ IN alpha = p[alpha_band]; \ - OUT factor = max_alpha * vips_recip( alpha ); \ + OUT factor = alpha == 0 ? 0 : max_alpha / alpha; \ \ for( i = 0; i < alpha_band; i++ ) \ q[i] = factor * p[i]; \ @@ -102,7 +102,7 @@ G_DEFINE_TYPE( VipsUnpremultiply, vips_unpremultiply, VIPS_TYPE_CONVERSION ); \ for( x = 0; x < width; x++ ) { \ IN alpha = p[3]; \ - OUT factor = max_alpha * vips_recip( alpha ); \ + OUT factor = alpha == 0 ? 0 : max_alpha / alpha; \ \ q[0] = factor * p[0]; \ q[1] = factor * p[1]; \ diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index 2b3e8726..feb49f72 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -84,20 +84,6 @@ extern "C" { #define VIPS_FMIN( A, B ) VIPS_MIN( A, B ) #endif -/* Calculate 1.0 / x, avoiding division by zero when near zero. - */ -static inline double -vips_recip( double x ) -{ - static const double epsilon = 1e-10; - - int sign = x < 0.0 ? -1.0 : 1.0; - - return( sign * x >= epsilon ? - 1.0 / x : - sign / epsilon ); -} - /* Testing status before the function call saves a lot of time. */ #define VIPS_ONCE( ONCE, FUNC, CLIENT ) \