palette::blend

Trait Blend

source
pub trait Blend {
    // Required methods
    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 different ways of mixing colors together.

This implements the classic separable blend modes, as described by W3C.

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 Methods§

source

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.

source

fn screen(self, other: Self) -> Self

Make a color which is at least as light as self or other.

source

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.

source

fn darken(self, other: Self) -> Self

Return the darkest parts of self and other.

source

fn lighten(self, other: Self) -> Self

Return the lightest parts of self and other.

source

fn dodge(self, other: Self) -> Self

Lighten other to reflect self. Results in other if self is black.

source

fn burn(self, other: Self) -> Self

Darken other to reflect self. Results in other if self is white.

source

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.

source

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.

source

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.

source

fn exclusion(self, other: Self) -> Self

Similar to difference, but appears to result in a lower contrast. other is inverted if self is white, and preserved if self is black.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<C, T, const N: usize> Blend for Alpha<C, T>
where C: Premultiply<Scalar = T> + StimulusColor + ArrayCast<Array = [T; N]> + Clone, T: Real + Zero + One + MinMax + Clamp + Sqrt + Abs + Arithmetics + PartialCmp + Clone, T::Mask: LazySelect<T>,

source§

impl<C, T, const N: usize> Blend for PreAlpha<C>
where C: Premultiply<Scalar = T> + StimulusColor + ArrayCast<Array = [T; N]> + Clone, T: Real + Zero + One + MinMax + Clamp + Sqrt + Abs + Arithmetics + PartialCmp + Clone, T::Mask: LazySelect<T>,

source§

impl<C, T, const N: usize> Blend for C
where C: Premultiply<Scalar = T> + StimulusColor + ArrayCast<Array = [T; N]> + Clone, T: Real + Zero + One + MinMax + Clamp + Sqrt + Abs + Arithmetics + PartialCmp + Clone, T::Mask: LazySelect<T>,