Skip to content

Commit

Permalink
Improve gamma approximation
Browse files Browse the repository at this point in the history
- Use `pow()` if available (e.g. from sass-planifolia or MathSass)
- Use an approximation that is optimized to produce good contrast values

See also oddbird/accoutrement-color#6 for a
similar change.
  • Loading branch information
xi authored and tysongach committed Jul 20, 2018
1 parent cc80a97 commit 5ac2d26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions core/bourbon/utilities/_gamma.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion spec/bourbon/utilities/gamma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/bourbon/utilities/lightness_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ac2d26

Please sign in to comment.