ref: 52fd69b721bf44e66fc82f103ce90f74a43fa2a8
parent: 8c213f349db0bbec6fb4c503d41fcca4838ac13f
author: Sigrid Haflínudóttir <[email protected]>
date: Sat Mar 14 15:36:12 EDT 2020
hsluv: avoid div by 0 error
--- a/hsluv.c
+++ b/hsluv.c
@@ -228,9 +228,14 @@
static void
xyz2luv(Triplet* in_out)
{
- double var_u = (4.0 * in_out->a) / (in_out->a + (15.0 * in_out->b) + (3.0 * in_out->c));
- double var_v = (9.0 * in_out->b) / (in_out->a + (15.0 * in_out->b) + (3.0 * in_out->c));
double l = y2l(in_out->b);
+ double var_u = 4.0 * in_out->a;
+ double var_v = 9.0 * in_out->b;
+ double div = (in_out->a + (15.0 * in_out->b) + (3.0 * in_out->c));
+ if (div > 0.00000001) {
+ var_u /= div;
+ var_v /= div;
+ }
double u = 13.0 * l * (var_u - ref_u);
double v = 13.0 * l * (var_v - ref_v);