From f8bdc0086695dbbeb2d3f97b69d240d38f49258c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 29 Aug 2019 14:20:30 +0100 Subject: [PATCH] void /0 in Yxy2XYZ Now sets 0 rather than inf. --- libvips/colour/Yxy2XYZ.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libvips/colour/Yxy2XYZ.c b/libvips/colour/Yxy2XYZ.c index b15e24e3..04b2e135 100644 --- a/libvips/colour/Yxy2XYZ.c +++ b/libvips/colour/Yxy2XYZ.c @@ -7,7 +7,9 @@ * - gtkdoc * - cleanups * 20/9/12 - * redo as a class + * - redo as a class + * 29/8/19 + * - avoid /0 */ /* @@ -67,18 +69,26 @@ vips_Yxy2XYZ_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width ) float x = p[1]; float y = p[2]; - double total; float X, Z; - p += 3; + if( x == 0.0 || + y == 0.0 ) { + X = 0.0; + Z = 0.0; + } + else { + double total; - total = Y / y; - X = x * total; - Z = (X - x * X - x * Y) / x; + total = Y / y; + X = x * total; + Z = (X - x * X - x * Y) / x; + } q[0] = X; q[1] = Y; q[2] = Z; + + p += 3; q += 3; } }