From a078113e6bf4122fa0fd037a1cf4866bc029fba2 Mon Sep 17 00:00:00 2001 From: Chris Lilley Date: Wed, 10 Aug 2022 15:23:41 +0300 Subject: [PATCH] [contrast] Weber returns a clamped max, not zero, if Y2 === 0 --- src/contrast/Weber.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/contrast/Weber.js b/src/contrast/Weber.js index ecb9b0057..c70cdf50d 100644 --- a/src/contrast/Weber.js +++ b/src/contrast/Weber.js @@ -6,6 +6,12 @@ import getColor from "../getColor.js"; import {getLuminance} from "../luminance.js"; +// the darkest sRGB color above black is #000001 and this produces +// a plain Weber contrast of ~45647. +// So, setting the divide-by-zero result at 50000 is a reasonable +// max clamp for the plain Weber +const max = 50000; + export default function contrastWeber (color1, color2) { color1 = getColor(color1); color2 = getColor(color2); @@ -17,5 +23,5 @@ export default function contrastWeber (color1, color2) { [Y1, Y2] = [Y2, Y1]; } - return Y2 === 0 ? 0 : (Y1 - Y2) / Y2; -}; \ No newline at end of file + return Y2 === 0 ? max : (Y1 - Y2) / Y2; +};