#[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§
source§impl<C, T> AbsDiffEq for PreAlpha<C, T>
impl<C, T> AbsDiffEq for PreAlpha<C, T>
source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
The default tolerance to use when testing values that are close together. Read more
source§impl<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>
source§fn add_assign(&mut self, c: T)
fn add_assign(&mut self, c: T)
Performs the
+=
operation. Read moresource§impl<C: AddAssign, T: Float + AddAssign> AddAssign for PreAlpha<C, T>
impl<C: AddAssign, T: Float + AddAssign> AddAssign for PreAlpha<C, T>
source§fn add_assign(&mut self, other: PreAlpha<C, T>)
fn add_assign(&mut self, other: PreAlpha<C, T>)
Performs the
+=
operation. Read moresource§impl<C, T> Blend for PreAlpha<C, T>
impl<C, T> Blend for PreAlpha<C, T>
source§fn into_premultiplied(self) -> PreAlpha<C, T>
fn into_premultiplied(self) -> PreAlpha<C, T>
Convert the color to premultiplied alpha.
source§fn 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.
source§fn 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. Read moresource§fn over(self, other: Self) -> Self
fn over(self, other: Self) -> Self
Place
self
over other
. This is the good old common alpha
composition equation.source§fn inside(self, other: Self) -> Self
fn inside(self, other: Self) -> Self
Results in the parts of
self
that overlaps the visible parts of
other
.source§fn 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
.source§fn 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.source§fn 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.source§fn screen(self, other: Self) -> Self
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
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 dodge(self, other: Self) -> Self
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
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
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
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
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§impl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>
impl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>
source§impl<'de, C, T> Deserialize<'de> for PreAlpha<C, T>
impl<'de, C, T> Deserialize<'de> for PreAlpha<C, T>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<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>
source§fn div_assign(&mut self, c: T)
fn div_assign(&mut self, c: T)
Performs the
/=
operation. Read moresource§impl<C: DivAssign, T: Float + DivAssign> DivAssign for PreAlpha<C, T>
impl<C: DivAssign, T: Float + DivAssign> DivAssign for PreAlpha<C, T>
source§fn div_assign(&mut self, other: PreAlpha<C, T>)
fn div_assign(&mut self, other: PreAlpha<C, T>)
Performs the
/=
operation. Read moresource§impl<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>
source§fn mul_assign(&mut self, c: T)
fn mul_assign(&mut self, c: T)
Performs the
*=
operation. Read moresource§impl<C: MulAssign, T: Float + MulAssign> MulAssign for PreAlpha<C, T>
impl<C: MulAssign, T: Float + MulAssign> MulAssign for PreAlpha<C, T>
source§fn mul_assign(&mut self, other: PreAlpha<C, T>)
fn mul_assign(&mut self, other: PreAlpha<C, T>)
Performs the
*=
operation. Read moresource§impl<C: PartialEq, T: PartialEq + Float> PartialEq for PreAlpha<C, T>
impl<C: PartialEq, T: PartialEq + Float> PartialEq for PreAlpha<C, T>
source§impl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>
impl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>
source§fn 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.
source§fn into_raw<P: RawPixelSized<T>>(self) -> P
fn into_raw<P: RawPixelSized<T>>(self) -> P
Convert from raw color components.
source§fn 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.
source§fn 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.
source§fn from_raw_slice(slice: &[T]) -> &[Self]
fn from_raw_slice(slice: &[T]) -> &[Self]
Cast a slice of raw color components to a slice of colors. Read more
source§fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]
fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]
Cast a mutable slice of raw color components to a mutable slice of colors. Read more
source§impl<C, T> RelativeEq for PreAlpha<C, T>
impl<C, T> RelativeEq for PreAlpha<C, T>
source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
source§impl<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>
source§fn sub_assign(&mut self, c: T)
fn sub_assign(&mut self, c: T)
Performs the
-=
operation. Read moresource§impl<C: SubAssign, T: Float + SubAssign> SubAssign for PreAlpha<C, T>
impl<C: SubAssign, T: Float + SubAssign> SubAssign for PreAlpha<C, T>
source§fn sub_assign(&mut self, other: PreAlpha<C, T>)
fn sub_assign(&mut self, other: PreAlpha<C, T>)
Performs the
-=
operation. Read moresource§impl<C, T> UlpsEq for PreAlpha<C, T>
impl<C, T> UlpsEq for PreAlpha<C, T>
impl<C: Copy, T: Copy + Float> Copy for PreAlpha<C, T>
impl<C, T: Float> StructuralPartialEq for PreAlpha<C, T>
Auto Trait Implementations§
impl<C, T> RefUnwindSafe for PreAlpha<C, T>where
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<C, T> Send for PreAlpha<C, T>
impl<C, T> Sync for PreAlpha<C, T>
impl<C, T> Unpin for PreAlpha<C, T>
impl<C, T> UnwindSafe for PreAlpha<C, T>where
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Convert the source color to the destination color using the specified
method
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford
method by default
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
impl<T, U> ConvertInto<U> for Twhere
U: ConvertFrom<T>,
source§fn convert_into(self) -> U
fn convert_into(self) -> U
Convert into T with values clamped to the color defined bounds Read more
source§fn convert_unclamped_into(self) -> U
fn convert_unclamped_into(self) -> U
Convert into T. The resulting color might be invalid in its color space Read more
source§fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
fn try_convert_into(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