From 5ac2d26329974ea928e72d8f816a6e53423f9807 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 26 Sep 2017 21:32:09 +0200 Subject: [PATCH] Improve gamma approximation - Use `pow()` if available (e.g. from sass-planifolia or MathSass) - Use an approximation that is optimized to produce good contrast values See also https://github.com/oddbird/accoutrement-color/pull/6 for a similar change. --- core/bourbon/utilities/_gamma.scss | 9 ++++++--- spec/bourbon/utilities/gamma_spec.rb | 2 +- spec/bourbon/utilities/lightness_spec.rb | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/bourbon/utilities/_gamma.scss b/core/bourbon/utilities/_gamma.scss index 2314f5a9a..3e5145b12 100644 --- a/core/bourbon/utilities/_gamma.scss +++ b/core/bourbon/utilities/_gamma.scss @@ -2,8 +2,7 @@ /// Performs gamma correction on a single color channel. /// -/// Note that Sass does not have a `pow()` function, so the calculation -/// is approximate. +/// Note that the calculation is approximate if a `pow()` is not available. /// /// @argument {number (0-1)} $channel /// @@ -16,6 +15,10 @@ @return $channel / 12.92; } @else { $c: ($channel + 0.055) / 1.055; - @return (133 * $c * $c * $c + 155 * $c * $c) / 288; + @if function-exists("pow") { + @return pow($c, 2.4); + } @else { + @return 0.56 * $c * $c * $c + 0.44 * $c * $c; + } } } diff --git a/spec/bourbon/utilities/gamma_spec.rb b/spec/bourbon/utilities/gamma_spec.rb index cdfa8d3f5..2cb0beaaf 100644 --- a/spec/bourbon/utilities/gamma_spec.rb +++ b/spec/bourbon/utilities/gamma_spec.rb @@ -7,7 +7,7 @@ context "called on a color channel" do it "outputs a gamma value between 0 and 1" do - rule = "content: 0.13185;" + rule = "content: 0.12168;" expect(".gamma").to have_ruleset(rule) end diff --git a/spec/bourbon/utilities/lightness_spec.rb b/spec/bourbon/utilities/lightness_spec.rb index 38c9aa9ea..834acbf39 100644 --- a/spec/bourbon/utilities/lightness_spec.rb +++ b/spec/bourbon/utilities/lightness_spec.rb @@ -23,7 +23,7 @@ context "called on gray" do it "outputs a number between 0 and 1 to indicate lightness" do - rule = "content: 0.21795;" + rule = "content: 0.20503;" expect(".lightness-gray").to have_ruleset(rule) end