Module: ColorContrastCalc::Converter::Contrast

Defined in:
lib/color_contrast_calc/converter.rb

Class Method Summary collapse

Class Method Details

.calc_rgb(rgb, ratio = 100) ⇒ Array<Integer>

Return contrast adjusted RGB value of passed color.

The calculation is based on the definition found at www.w3.org/TR/filter-effects/#funcdef-contrast www.w3.org/TR/SVG/filters.html#TransferFunctionElementAttributes

Parameters:

  • rgb (Array<Integer>)

    The Original RGB value before the adjustment

  • ratio (Float) (defaults to: 100)

    Adjustment ratio in percentage

Returns:

  • (Array<Integer>)

    Contrast adjusted RGB value



95
96
97
98
# File 'lib/color_contrast_calc/converter.rb', line 95

def self.calc_rgb(rgb, ratio = 100)
  r = ratio.to_f
  Converter.rgb_map(rgb) {|c| (c * r + 255 * (50 - r / 2)) / 100 }
end