Struct palette::blend::PreAlpha [−][src]
#[repr(C)]pub struct PreAlpha<C, T: Float> { pub color: C, pub alpha: T, }
Expand description
Premultiplied alpha wrapper.
Premultiplied colors are commonly used in composition algorithms to simplify the calculations. It may also be preferred when interpolating between colors, which is one of the reasons why it’s offered as a separate type. The other reason is to make it easier to avoid unnecessary computations in composition chains.
use palette::{Blend, LinSrgb, LinSrgba}; use palette::blend::PreAlpha; let a = PreAlpha::from(LinSrgba::new(0.4, 0.5, 0.5, 0.3)); let b = PreAlpha::from(LinSrgba::new(0.3, 0.8, 0.4, 0.4)); let c = PreAlpha::from(LinSrgba::new(0.7, 0.1, 0.8, 0.8)); let res = LinSrgb::from_premultiplied(a.screen(b).overlay(c));
Note that converting to and from premultiplied alpha will cause the alpha component to be clamped to [0.0, 1.0].
Fields
color: C
The premultiplied color components (original.color * original.alpha
).
alpha: T
The transparency component. 0.0 is fully transparent and 1.0 is fully opaque.
Trait Implementations
The default tolerance to use when testing values that are close together. Read more
A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
The inverse of AbsDiffEq::abs_diff_eq
.
Performs the +=
operation. Read more
Performs the +=
operation. Read more
type Color = C
type Color = C
The core color type. Typically Self
for color types without alpha.
Convert the color to premultiplied alpha.
Convert the color from premultiplied alpha.
fn blend<F>(self, destination: Self, blend_function: F) -> Self where
F: BlendFunction<Self::Color>,
fn blend<F>(self, destination: Self, blend_function: F) -> Self where
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. Read more
Place self
over other
. This is the good old common alpha
composition equation. Read more
Results in the parts of self
that overlaps the visible parts of
other
. Read more
Results in the parts of self
that lies outside the visible parts of
other
. Read more
Add self
and other
. This uses the alpha component to regulate the
effect, so it’s not just plain component wise addition. Read more
Multiply self
with other
. This uses the alpha component to regulate
the effect, so it’s not just plain component wise multiplication. Read more
Multiply self
or other
if other is dark, or screen them if other
is light. This results in an S curve. Read more
Lighten other
to reflect self
. Results in other
if self
is
black. Read more
Darken other
to reflect self
. Results in other
if self
is
white. Read more
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
. Read more
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. Read more
Return the absolute difference between self
and other
. It’s
basically abs(self - other)
, but regulated by the alpha component. Read more
type Scalar = T
type Scalar = T
The scalar type for color components.
Perform a binary operation on this and an other color.
Perform a unary operation on this color.
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Cast as a mutable reference to raw color components.
Convert into raw color components.
Cast from a reference to raw color components.
Cast from a mutable reference to raw color components.
Cast a slice of raw color components to a slice of colors. Read more
Cast a mutable slice of raw color components to a mutable slice of colors. Read more
Cast a slice of colors to a slice of raw color components. Read more
Cast a mutable slice of colors to a mutable slice of raw color components. Read more
impl<C, T> RelativeEq<PreAlpha<C, T>> for PreAlpha<C, T> where
C: RelativeEq<Epsilon = T::Epsilon>,
T: RelativeEq + Float,
T::Epsilon: Copy,
impl<C, T> RelativeEq<PreAlpha<C, T>> for PreAlpha<C, T> where
C: RelativeEq<Epsilon = T::Epsilon>,
T: RelativeEq + Float,
T::Epsilon: Copy,
The default relative tolerance for testing values that are far-apart. Read more
A test for equality that uses a relative comparison if the values are far apart.
The inverse of RelativeEq::relative_eq
.
Performs the -=
operation. Read more
Performs the -=
operation. Read more
The default ULPs to tolerate when testing values that are far-apart. Read more
A test for equality that uses units in the last place (ULP) if the values are far apart.
Auto Trait Implementations
impl<C, T> RefUnwindSafe for PreAlpha<C, T> where
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<C, T> UnwindSafe for PreAlpha<C, T> where
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
Mutably borrows from an owned value. Read more
Convert into T with values clamped to the color defined bounds Read more
Convert into T. The resulting color might be invalid in its color space Read more
Convert into T, returning ok if the color is inside of its defined
range, otherwise an OutOfBounds
error is returned which contains
the unclamped color. Read more