aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-06-23 13:02:42 +0200
committerMattias Andrée <maandree@kth.se>2017-06-23 13:02:42 +0200
commitb636cf4a899a90c45b545c866f394653513e96a1 (patch)
tree31b9274167b623ed8d0d4986a675d4429b753b34
parentCIEXYZ_TO_CIE1960UCS: set u and v to the limit if conversion results in division by zero (diff)
downloadlibcolour-b636cf4a899a90c45b545c866f394653513e96a1.tar.gz
libcolour-b636cf4a899a90c45b545c866f394653513e96a1.tar.bz2
libcolour-b636cf4a899a90c45b545c866f394653513e96a1.tar.xz
Fix nan in conversion from ciexyz to cieluv
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--conversions.h10
-rw-r--r--test.c4
2 files changed, 10 insertions, 4 deletions
diff --git a/conversions.h b/conversions.h
index 6a3ad68..71e8b54 100644
--- a/conversions.h
+++ b/conversions.h
@@ -106,11 +106,13 @@
TYPE X__ = (FROM_X), Y__ = (FROM_Y), Z__ = (FROM_Z);\
TYPE L2__, L__, u__, v__, t__;\
t__ = X__ + 15 * Y__ + 3 * Z__;\
- u__ = 4 * X__ / t__;\
- v__ = 9 * Y__ / t__;\
+ u__ = X__ / t__;\
+ v__ = Y__ / t__;\
+ if (WASDIV0(u__) || WASDIV0(v__))\
+ u__ = v__ = D(0.);\
t__ = WX__ + 15 * WY__ + 3 * WZ__;\
- u__ -= 4 * WX__ / t__;\
- v__ -= 9 * WY__ / t__;\
+ u__ = 4 * (u__ - WX__ / t__);\
+ v__ = 9 * (v__ - WY__ / t__);\
L__ = Y__ / WY__;\
L2__ = L__ * 24389;\
L__ = L2__ <= 216 ? L2__ / 27 : xcbrt(L__) * 116 - 16;\
diff --git a/test.c b/test.c
index 693e7d4..719642a 100644
--- a/test.c
+++ b/test.c
@@ -146,6 +146,10 @@ test_2convert_1n(libcolour_model_t model, const char *model_name, double ch1, do
if (ch3 > 0.9999)
return 1;
/* fall through */
+ case LIBCOLOUR_CIELUV:
+ if (ch1 <= 0.00001 && (ch2 > 0.00001 || ch3 > 0.00001))
+ return 1;
+ /* fall through */
default:
c1.srgb.R = ch1, c1.srgb.G = ch2, c1.srgb.B = ch3;
break;