# `Color.Blend`

CSS Compositing and Blending Level 1 blend modes.

`blend/3,4` computes `B(Cb, Cs)` for a source and backdrop colour
using one of the sixteen standard CSS blend modes. Both inputs are
interpreted in sRGB and the result is returned as a
`Color.SRGB` struct.

Separable blend modes (`:multiply`, `:screen`, `:overlay`,
`:darken`, `:lighten`, `:color_dodge`, `:color_burn`,
`:hard_light`, `:soft_light`, `:difference`, `:exclusion`) operate
per-channel.

Non-separable modes (`:hue`, `:saturation`, `:color`, `:luminosity`)
exchange specific colour attributes between source and backdrop and
are defined in terms of an sRGB luminance and saturation.

`:normal` simply returns the source.

### Examples

    iex> {:ok, c} = Color.Blend.blend("white", "red", :multiply)
    iex> Color.SRGB.to_hex(c)
    "#ff0000"

    iex> {:ok, c} = Color.Blend.blend([0.5, 0.5, 0.5], [0.5, 0.5, 0.5], :screen)
    iex> Color.SRGB.to_hex(c)
    "#bfbfbf"

# `blend`

```elixir
@spec blend(Color.input(), Color.input(), atom()) ::
  {:ok, Color.SRGB.t()} | {:error, Exception.t()}
```

Blends a source over a backdrop using the given blend mode.

### Arguments

* `backdrop` is the destination colour (`Cb`) — any colour accepted
  by `Color.new/1`.

* `source` is the source colour (`Cs`) — any colour accepted by
  `Color.new/1`.

* `mode` is one of `[:normal, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hue, :saturation, :color, :luminosity]`.

### Returns

* `{:ok, %Color.SRGB{}}` on success.

* `{:error, reason}` if the mode is unknown.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
