#[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
sourceimpl<C, T> AbsDiffEq<PreAlpha<C, T>> for PreAlpha<C, T> where
C: AbsDiffEq<Epsilon = T::Epsilon>,
T: AbsDiffEq + Float,
T::Epsilon: Copy,
impl<C, T> AbsDiffEq<PreAlpha<C, T>> for PreAlpha<C, T> where
C: AbsDiffEq<Epsilon = T::Epsilon>,
T: AbsDiffEq + Float,
T::Epsilon: Copy,
sourcefn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
The default tolerance to use when testing values that are close together. Read more
sourcefn abs_diff_eq(&self, other: &PreAlpha<C, T>, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &PreAlpha<C, T>, epsilon: Self::Epsilon) -> bool
A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
sourcefn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of AbsDiffEq::abs_diff_eq
.
sourceimpl<C: AddAssign, T: Float + AddAssign> AddAssign<PreAlpha<C, T>> for PreAlpha<C, T>
impl<C: AddAssign, T: Float + AddAssign> AddAssign<PreAlpha<C, T>> for PreAlpha<C, T>
sourcefn add_assign(&mut self, other: PreAlpha<C, T>)
fn add_assign(&mut self, other: PreAlpha<C, T>)
Performs the +=
operation. Read more
sourceimpl<T: Float + AddAssign, C: AddAssign<T>> AddAssign<T> for PreAlpha<C, T>
impl<T: Float + AddAssign, C: AddAssign<T>> AddAssign<T> for PreAlpha<C, T>
sourcefn add_assign(&mut self, c: T)
fn add_assign(&mut self, c: T)
Performs the +=
operation. Read more
sourceimpl<C, T, P> AsMut<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T> + ?Sized,
impl<C, T, P> AsMut<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T> + ?Sized,
sourceimpl<C, T, P> AsRef<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T> + ?Sized,
impl<C, T, P> AsRef<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T> + ?Sized,
sourceimpl<C, T> Blend for PreAlpha<C, T> where
C: Blend<Color = C> + ComponentWise<Scalar = T>,
T: Float,
impl<C, T> Blend for PreAlpha<C, T> where
C: Blend<Color = C> + ComponentWise<Scalar = T>,
T: Float,
type Color = C
type Color = C
The core color type. Typically Self
for color types without alpha.
sourcefn into_premultiplied(self) -> PreAlpha<C, T>
fn into_premultiplied(self) -> PreAlpha<C, T>
Convert the color to premultiplied alpha.
sourcefn from_premultiplied(color: PreAlpha<C, T>) -> PreAlpha<C, T>
fn from_premultiplied(color: PreAlpha<C, T>) -> PreAlpha<C, T>
Convert the color from premultiplied alpha.
sourcefn 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
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. Read more
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
. Read more
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
. Read more
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. Read more
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. Read more
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. Read more
sourcefn dodge(self, other: Self) -> Self
fn dodge(self, other: Self) -> Self
Lighten other
to reflect self
. Results in other
if self
is
black. Read more
sourcefn burn(self, other: Self) -> Self
fn burn(self, other: Self) -> Self
Darken other
to reflect self
. Results in other
if self
is
white. Read more
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
. Read more
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. Read more
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. Read more
sourceimpl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>
impl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>
type Scalar = T
type Scalar = T
The scalar type for color components.
sourcefn component_wise<F: FnMut(T, T) -> T>(
&self,
other: &PreAlpha<C, T>,
f: F
) -> PreAlpha<C, T>
fn component_wise<F: FnMut(T, T) -> T>(
&self,
other: &PreAlpha<C, T>,
f: F
) -> PreAlpha<C, T>
Perform a binary operation on this and an other color.
sourcefn component_wise_self<F: FnMut(T) -> T>(&self, f: F) -> PreAlpha<C, T>
fn component_wise_self<F: FnMut(T) -> T>(&self, f: F) -> PreAlpha<C, T>
Perform a unary operation on this color.
sourceimpl<C: DivAssign, T: Float + DivAssign> DivAssign<PreAlpha<C, T>> for PreAlpha<C, T>
impl<C: DivAssign, T: Float + DivAssign> DivAssign<PreAlpha<C, T>> for PreAlpha<C, T>
sourcefn div_assign(&mut self, other: PreAlpha<C, T>)
fn div_assign(&mut self, other: PreAlpha<C, T>)
Performs the /=
operation. Read more
sourceimpl<T: Float + DivAssign, C: DivAssign<T>> DivAssign<T> for PreAlpha<C, T>
impl<T: Float + DivAssign, C: DivAssign<T>> DivAssign<T> for PreAlpha<C, T>
sourcefn div_assign(&mut self, c: T)
fn div_assign(&mut self, c: T)
Performs the /=
operation. Read more
sourceimpl<C: MulAssign, T: Float + MulAssign> MulAssign<PreAlpha<C, T>> for PreAlpha<C, T>
impl<C: MulAssign, T: Float + MulAssign> MulAssign<PreAlpha<C, T>> for PreAlpha<C, T>
sourcefn mul_assign(&mut self, other: PreAlpha<C, T>)
fn mul_assign(&mut self, other: PreAlpha<C, T>)
Performs the *=
operation. Read more
sourceimpl<T: Float + MulAssign, C: MulAssign<T>> MulAssign<T> for PreAlpha<C, T>
impl<T: Float + MulAssign, C: MulAssign<T>> MulAssign<T> for PreAlpha<C, T>
sourcefn mul_assign(&mut self, c: T)
fn mul_assign(&mut self, c: T)
Performs the *=
operation. Read more
sourceimpl<C, T> PartialEq<PreAlpha<C, T>> for PreAlpha<C, T> where
T: Float + PartialEq,
C: PartialEq,
impl<C, T> PartialEq<PreAlpha<C, T>> for PreAlpha<C, T> where
T: Float + PartialEq,
C: PartialEq,
sourceimpl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>
impl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>
sourcefn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
fn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
Cast as a mutable reference to raw color components.
sourcefn into_raw<P: RawPixelSized<T>>(self) -> P
fn into_raw<P: RawPixelSized<T>>(self) -> P
Convert into raw color components.
sourcefn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
fn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
Cast from a reference to raw color components.
sourcefn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
fn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
Cast from a mutable reference to raw color components.
sourcefn from_raw_slice(slice: &[T]) -> &[Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
fn from_raw_slice(slice: &[T]) -> &[Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Cast a slice of raw color components to a slice of colors. Read more
sourcefn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Cast a mutable slice of raw color components to a mutable slice of colors. Read more
sourceimpl<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,
sourcefn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
sourcefn relative_eq(
&self,
other: &PreAlpha<C, T>,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_eq(
&self,
other: &PreAlpha<C, T>,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
A test for equality that uses a relative comparison if the values are far apart.
sourcefn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
The inverse of RelativeEq::relative_eq
.
sourceimpl<C: SubAssign, T: Float + SubAssign> SubAssign<PreAlpha<C, T>> for PreAlpha<C, T>
impl<C: SubAssign, T: Float + SubAssign> SubAssign<PreAlpha<C, T>> for PreAlpha<C, T>
sourcefn sub_assign(&mut self, other: PreAlpha<C, T>)
fn sub_assign(&mut self, other: PreAlpha<C, T>)
Performs the -=
operation. Read more
sourceimpl<T: Float + SubAssign, C: SubAssign<T>> SubAssign<T> for PreAlpha<C, T>
impl<T: Float + SubAssign, C: SubAssign<T>> SubAssign<T> for PreAlpha<C, T>
sourcefn sub_assign(&mut self, c: T)
fn sub_assign(&mut self, c: T)
Performs the -=
operation. Read more
sourceimpl<C, T> UlpsEq<PreAlpha<C, T>> for PreAlpha<C, T> where
C: UlpsEq<Epsilon = T::Epsilon>,
T: UlpsEq + Float,
T::Epsilon: Copy,
impl<C, T> UlpsEq<PreAlpha<C, T>> for PreAlpha<C, T> where
C: UlpsEq<Epsilon = T::Epsilon>,
T: UlpsEq + Float,
T::Epsilon: Copy,
impl<C: Copy, T: Copy + Float> Copy for PreAlpha<C, T>
impl<C, T> Eq for PreAlpha<C, T> where
T: Float + Eq,
C: Eq,
Auto Trait Implementations
impl<C, T> RefUnwindSafe for PreAlpha<C, T> where
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<C, T> Send for PreAlpha<C, T> where
C: Send,
T: Send,
impl<C, T> Sync for PreAlpha<C, T> where
C: Sync,
T: Sync,
impl<C, T> Unpin for PreAlpha<C, T> where
C: Unpin,
T: Unpin,
impl<C, T> UnwindSafe for PreAlpha<C, T> where
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<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>,
sourcefn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
Convert the source color to the destination color using the specified method Read more
sourcefn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford method by default Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, U> IntoColor<U> for T where
U: FromColor<T>,
impl<T, U> IntoColor<U> for T where
U: FromColor<T>,
sourcefn into_color(self) -> U
fn into_color(self) -> U
Convert into T with values clamped to the color defined bounds Read more
sourceimpl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
sourcefn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Convert into T. The resulting color might be invalid in its color space Read more
sourceimpl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
sourcefn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
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