From 768ab7fa8f100db9cd4e4db6453d411e84f6742c Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 2 Jan 2018 20:36:14 +0000 Subject: [PATCH] Improve greyscale perf by using isinf/isnan after calc --- libvips/colour/LabQ2sRGB.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/libvips/colour/LabQ2sRGB.c b/libvips/colour/LabQ2sRGB.c index 80cfa49d..d89f5eeb 100644 --- a/libvips/colour/LabQ2sRGB.c +++ b/libvips/colour/LabQ2sRGB.c @@ -350,24 +350,19 @@ vips_col_scRGB2BW( int range, int *lut, float R, float G, float B, int Yi; float v; - /* RGB can be Nan, Inf etc. Throw those values out, they will break - * our clipping. - * - * Don't use isnormal(), it is false for 0.0 and for subnormal - * numbers. + /* The usual ratio. We do this in linear space before we gamma. */ - if( VIPS_ISNAN( R ) || VIPS_ISINF( R ) || - VIPS_ISNAN( G ) || VIPS_ISINF( G ) || - VIPS_ISNAN( B ) || VIPS_ISINF( B ) ) { + Y = 0.2 * R + 0.7 * G + 0.1 * B; + + /* Y can be Nan, Inf etc. Throw those values out, they will break + * our clipping. + */ + if( VIPS_ISNAN( Y ) || VIPS_ISINF( Y ) ) { *g = 0; return( -1 ); } - /* The usual ratio. We do this in linear space before we gamma. - */ - Y = 0.2 * R + 0.7 * G + 0.1 * B; - /* Look up with a float index: interpolate between the nearest two * points. *