Module: ColorContrastCalc::Converter::AlphaCompositing

Defined in:
lib/color_contrast_calc/converter.rb

Defined Under Namespace

Modules: Rgba

Class Method Summary collapse

Class Method Details

.compose(foreground, background, base = Rgba::WHITE) ⇒ Hash

Return a pair of RGBA colors created from two other RGBA colors placed on a base color.

The calculation is based on the definition found at www.w3.org/TR/compositing-1/#simplealphacompositing

Parameters:

  • foreground (Array<Integer, Float>)

    RGBA value

  • background (Array<Integer, Float>)

    RGBA value

  • base (Array<Integer, Float>) (defaults to: Rgba::WHITE)

    RGBA value

Returns:

  • (Hash)

    A pair of RGBA values with :foreground and :background as its keys



50
51
52
53
54
55
56
57
58
# File 'lib/color_contrast_calc/converter.rb', line 50

def self.compose(foreground, background, base = Rgba::WHITE)
  back = calc(background, base)
  fore = calc(foreground, back)

  {
    foreground: normalize(fore),
    background: normalize(back)
  }
end