Class GssFunctions.MakeContrastingColor

java.lang.Object
com.google.common.css.compiler.gssfunctions.GssFunctions.MakeContrastingColor
All Implemented Interfaces:
GssFunction
Enclosing class:
GssFunctions

public static class GssFunctions.MakeContrastingColor extends Object implements GssFunction
The "makeContrastingColor" function generates a contrasting color with the same hue as the input color. The generated color passes (or almost passes) the contrast test described in the W3C accessibility evaluation working draft "http://www.w3.org/TR/AERT#color-contrast".

The function takes two parameters:

  • The input color to find the contrasting color for,
  • the similarity value (a float between 0.0 - 1.0) which tells how similar the computed color should be to the input color.

The algorithm for the contrasting color generation is as follows:

  1. First a base contrasting color is chosen. It is either black or white, as one of these colors is guaranteed to be in contrast with any given color. Additionally both of these colors are "hue-neutral", so choosing the contrasting color in between the input color and black or white should give pleasant results.
  2. A closest required contrasting color is found. This is a color in between the input color and the base contrasting color. It has the same hue as the input color. This color is found in HSB color space, by a bisection of a line between the input color and the base contrasting color. To improve function performance, a limited number of the bisection steps (NUM_ITERATIONS) is performed. This gives a constant expected time of function execution. At the same time the color that is found may not pass the contrast test, but is guaranteed to be close to the "contrast boundary".
  3. The output color of the function is an interpolation of the closest contrasting color and the base contrasting color. The interpolation is controlled using the "similarity" parameter. If similarity is set to 1, it means that the result is the closest contrasting color. If similarity is set to 0, it means that the result is the base contrasting color.
  • Constructor Details

    • MakeContrastingColor

      public MakeContrastingColor()
  • Method Details