aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--conversions.h30
-rw-r--r--test.c6
2 files changed, 30 insertions, 6 deletions
diff --git a/conversions.h b/conversions.h
index 71e8b54..4672dfd 100644
--- a/conversions.h
+++ b/conversions.h
@@ -70,23 +70,41 @@
TYPE t__ = X__ + 15 * Y__ + 3 * Z__;\
TYPE u__ = (FROM_U) / L13__ + 4 * X__ / t__;\
TYPE v__ = (FROM_V) / L13__ + 9 * Y__ / t__;\
+ if (WASDIV0(u__) || WASDIV0(v__)) {\
+ u__ = D(0.);\
+ v__ = D(0.);\
+ }\
if (L__ <= 8) {\
Y__ *= L__ * 27 / 24389;\
} else {\
L__ = (L__ + 16) / 116;\
Y__ *= L__ * L__ * L__;\
}\
- (TO_X) = D(2.25) * Y__ * u__ / v__;\
+ u__ /= v__;\
+ if (WASDIV0(u__)) {\
+ (TO_X) = D(0.);\
+ (TO_Z) = D(0.);\
+ } else {\
+ (TO_X) = D(2.25) * Y__ * u__;\
+ (TO_Z) = Y__ * (3 / v__ - D(0.75) * u__ - 5);\
+ }\
(TO_Y) = Y__;\
- (TO_Z) = Y__ * (3 / v__ - D(0.75) * u__ / v__ - 5);\
} while (0)
#define CIE1960UCS_TO_CIEXYZ(FROM_U, FROM_V, FROM_Y, TO_X, TO_Y, TO_Z)\
do {\
- TYPE u__ = (FROM_U), v__ = (FROM_V), Y__ = (FROM_Y);\
- (TO_X) = D(1.5) * Y__ * u__ / v__;\
- (TO_Y) = Y__;\
- (TO_Z) = (4 * Y__ - Y__ * u__ - 10 * Y__ * v__) / (2 * v__);\
+ TYPE u__ = (FROM_U), v__ = (FROM_V), Y__ = (FROM_Y), X__, Z__;\
+ X__ = D(1.5) * Y__ * u__ / v__;\
+ Z__ = (4 * Y__ - Y__ * u__ - 10 * Y__ * v__) / (2 * v__);\
+ if (WASDIV0(X__) || WASDIV0(Z__)) {/* FIXME */\
+ (TO_X) = X__;\
+ (TO_Y) = Y__;\
+ (TO_Z) = Z__;\
+ } else {\
+ (TO_X) = X__;\
+ (TO_Y) = Y__;\
+ (TO_Z) = Z__;\
+ }\
} while (0)
#define CIEXYZ_TO_CIELAB(FROM_X, FROM_Y, FROM_Z, TO_L, TO_A, TO_B)\
diff --git a/test.c b/test.c
index 719642a..9c7a318 100644
--- a/test.c
+++ b/test.c
@@ -40,6 +40,12 @@ test_2convert(libcolour_colour_t *c1, libcolour_colour_t *c2, libcolour_colour_t
return -1;
if (libcolour_convert(c2, c3))
return -1;
+ if (!(isnan(c2->srgb.R) || isnan(c2->srgb.G) || isnan(c2->srgb.B)))
+ if ((isnan(c3->srgb.R) || isnan(c3->srgb.G) || isnan(c3->srgb.B)))
+ fprintf(stderr, "(%lf %lf %lf)[%i] -> (%lf %lf %lf)[%i] -> (%lf %lf %lf)[%i]\n",
+ c1->srgb.R, c1->srgb.G, c1->srgb.B, c1->model,
+ c2->srgb.R, c2->srgb.G, c2->srgb.B, c2->model,
+ c3->srgb.R, c3->srgb.G, c3->srgb.B, c3->model);
if ((c1->model == LIBCOLOUR_CIELCHUV) &&
!isnan(c1->cielchuv.h) && !isnan(c3->cielchuv.h) &&
!isinf(c1->cielchuv.h) && !isinf(c3->cielchuv.h) &&