From bedf32e97271b209b7dbcf5b17b50aa862ad8fed Mon Sep 17 00:00:00 2001 From: Chris Lilley Date: Thu, 24 Oct 2024 14:15:13 -0400 Subject: [PATCH] [css-color-hdr] Handle negative component values in HLG function --- css-color-hdr/Overview.bs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/css-color-hdr/Overview.bs b/css-color-hdr/Overview.bs index 8c00dbd6712..b70b4e058ac 100644 --- a/css-color-hdr/Overview.bs +++ b/css-color-hdr/Overview.bs @@ -555,8 +555,11 @@ Predefined color spaces for HDR: {#predefined-HDR} const a = 0.17883277; const b = 0.28466892; // 1 - (4 * a) const c = 0.55991073; // 0.5 - a * Math.log(4 *a) - if (E <= 1/12) { - Edash = Math.sqrt( 3 * E); + // handle negative values + var sign = E < 0? -1 : 1; + var abs = Math.abs(E); + if (abs <= 1/12) { + Edash = sign * Math.sqrt( 3 * abs); } else { Edash = a * Math.log(12 * E - b) + c;