pub trait Blend: Sized{
type Color: Blend<Color = Self::Color> + ComponentWise;
Show 20 methods
// Required methods
fn into_premultiplied(
self
) -> PreAlpha<Self::Color, <Self::Color as ComponentWise>::Scalar>;
fn from_premultiplied(
color: PreAlpha<Self::Color, <Self::Color as ComponentWise>::Scalar>
) -> Self;
// Provided methods
fn blend<F>(self, destination: Self, blend_function: F) -> Self
where F: BlendFunction<Self::Color> { ... }
fn over(self, other: Self) -> Self { ... }
fn inside(self, other: Self) -> Self { ... }
fn outside(self, other: Self) -> Self { ... }
fn atop(self, other: Self) -> Self { ... }
fn xor(self, other: Self) -> Self { ... }
fn plus(self, other: Self) -> Self { ... }
fn multiply(self, other: Self) -> Self { ... }
fn screen(self, other: Self) -> Self { ... }
fn overlay(self, other: Self) -> Self { ... }
fn darken(self, other: Self) -> Self { ... }
fn lighten(self, other: Self) -> Self { ... }
fn dodge(self, other: Self) -> Self { ... }
fn burn(self, other: Self) -> Self { ... }
fn hard_light(self, other: Self) -> Self { ... }
fn soft_light(self, other: Self) -> Self { ... }
fn difference(self, other: Self) -> Self { ... }
fn exclusion(self, other: Self) -> Self { ... }
}
Expand description
A trait for colors that can be blended together.
Blending can either be performed through the predefined blend modes, or a custom blend functions.
Note: The default implementations of the blend modes are meant for color components in the range [0.0, 1.0] and may otherwise produce strange results.
Required Associated Types§
sourcetype Color: Blend<Color = Self::Color> + ComponentWise
type Color: Blend<Color = Self::Color> + ComponentWise
The core color type. Typically Self
for color types without alpha.
Required Methods§
sourcefn into_premultiplied(
self
) -> PreAlpha<Self::Color, <Self::Color as ComponentWise>::Scalar>
fn into_premultiplied( self ) -> PreAlpha<Self::Color, <Self::Color as ComponentWise>::Scalar>
Convert the color to premultiplied alpha.
sourcefn from_premultiplied(
color: PreAlpha<Self::Color, <Self::Color as ComponentWise>::Scalar>
) -> Self
fn from_premultiplied( color: PreAlpha<Self::Color, <Self::Color as ComponentWise>::Scalar> ) -> Self
Convert the color from premultiplied alpha.
Provided Methods§
sourcefn blend<F>(self, destination: Self, blend_function: F) -> Selfwhere
F: BlendFunction<Self::Color>,
fn blend<F>(self, destination: Self, blend_function: F) -> Selfwhere
F: BlendFunction<Self::Color>,
Blend self, as the source color, with destination
, using
blend_function
. Anything that implements BlendFunction
is
acceptable, including functions and closures.
use palette::{LinSrgb, LinSrgba, Blend};
use palette::blend::PreAlpha;
type PreRgba = PreAlpha<LinSrgb<f32>, f32>;
fn blend_mode(a: PreRgba, b: PreRgba) -> PreRgba {
PreAlpha {
color: LinSrgb::new(a.red * b.green, a.green * b.blue, a.blue * b.red),
alpha: a.alpha * b.alpha,
}
}
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);
sourcefn over(self, other: Self) -> Self
fn over(self, other: Self) -> Self
Place self
over other
. This is the good old common alpha
composition equation.
sourcefn inside(self, other: Self) -> Self
fn inside(self, other: Self) -> Self
Results in the parts of self
that overlaps the visible parts of
other
.
sourcefn outside(self, other: Self) -> Self
fn outside(self, other: Self) -> Self
Results in the parts of self
that lies outside the visible parts of
other
.
sourcefn plus(self, other: Self) -> Self
fn plus(self, other: Self) -> Self
Add self
and other
. This uses the alpha component to regulate the
effect, so it’s not just plain component wise addition.
sourcefn multiply(self, other: Self) -> Self
fn multiply(self, other: Self) -> Self
Multiply self
with other
. This uses the alpha component to regulate
the effect, so it’s not just plain component wise multiplication.
sourcefn overlay(self, other: Self) -> Self
fn overlay(self, other: Self) -> Self
Multiply self
or other
if other is dark, or screen them if other
is light. This results in an S curve.
sourcefn dodge(self, other: Self) -> Self
fn dodge(self, other: Self) -> Self
Lighten other
to reflect self
. Results in other
if self
is
black.
sourcefn burn(self, other: Self) -> Self
fn burn(self, other: Self) -> Self
Darken other
to reflect self
. Results in other
if self
is
white.
sourcefn hard_light(self, other: Self) -> Self
fn hard_light(self, other: Self) -> Self
Multiply self
or other
if other is dark, or screen them if self
is light. This is similar to overlay
, but depends on self
instead
of other
.
sourcefn soft_light(self, other: Self) -> Self
fn soft_light(self, other: Self) -> Self
Lighten other
if self
is light, or darken other
as if it’s burned
if self
is dark. The effect is increased if the components of self
is further from 0.5.
sourcefn difference(self, other: Self) -> Self
fn difference(self, other: Self) -> Self
Return the absolute difference between self
and other
. It’s
basically abs(self - other)
, but regulated by the alpha component.