Module palette::blend

source ·
Expand description

Color blending and blending equations.

Palette offers both OpenGL style blending equations, as well as most of the SVG composition operators (also common in photo manipulation software). The composition operators are all implemented in the Blend trait, and ready to use with any appropriate color type:

use palette::{LinSrgba, Blend};

let a = LinSrgba::new(0.2, 0.5, 0.1, 0.8);
let b = LinSrgba::new(0.6, 0.3, 0.5, 0.1);
let c = a.overlay(b);

Blending equations can be defined using the Equations type, which is then passed to the blend function, from the Blend trait:

use palette::{LinSrgba, Blend};
use palette::blend::{Equations, Parameter};

let blend_mode = Equations::from_parameters(
    Parameter::SourceAlpha,
    Parameter::OneMinusSourceAlpha
);

let a = LinSrgba::new(0.2, 0.5, 0.1, 0.8);
let b = LinSrgba::new(0.6, 0.3, 0.5, 0.1);
let c = a.blend(b, blend_mode);

Note that blending will use premultiplied alpha, which may result in loss of some color information in some cases. One such case is that a completely transparent resultant color will become black.

Structs

  • A pair of blending equations and corresponding parameters.
  • A pair of source and destination parameters.
  • Premultiplied alpha wrapper.

Enums

Traits

  • A trait for colors that can be blended together.
  • A trait for custom blend functions.