Merge pull request #842 from lovell/perf-scRGB2BW

Perf: ~15% improvement in conversion to greyscale
This commit is contained in:
John Cupitt 2018-01-03 08:27:40 +00:00 committed by GitHub
commit 917d61e785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 12 deletions

View File

@ -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.
*