Struct palette::blend::PreAlpha [−][src]
#[repr(C)]pub struct PreAlpha<C, T: Float> { pub color: C, pub alpha: T, }
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
impl<C: Clone, T: Clone + Float> Clone for PreAlpha<C, T>
[src]
impl<C: Clone, T: Clone + Float> Clone for PreAlpha<C, T>
fn clone(&self) -> PreAlpha<C, T>
[src]
fn clone(&self) -> PreAlpha<C, T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<C: Copy, T: Copy + Float> Copy for PreAlpha<C, T>
[src]
impl<C: Copy, T: Copy + Float> Copy for PreAlpha<C, T>
impl<C: PartialEq, T: PartialEq + Float> PartialEq for PreAlpha<C, T>
[src]
impl<C: PartialEq, T: PartialEq + Float> PartialEq for PreAlpha<C, T>
fn eq(&self, other: &PreAlpha<C, T>) -> bool
[src]
fn eq(&self, other: &PreAlpha<C, T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &PreAlpha<C, T>) -> bool
[src]
fn ne(&self, other: &PreAlpha<C, T>) -> bool
This method tests for !=
.
impl<C: Debug, T: Debug + Float> Debug for PreAlpha<C, T>
[src]
impl<C: Debug, T: Debug + Float> Debug for PreAlpha<C, T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<C, T> From<Alpha<C, T>> for PreAlpha<C, T> where
C: ComponentWise<Scalar = T>,
T: Float,
[src]
impl<C, T> From<Alpha<C, T>> for PreAlpha<C, T> where
C: ComponentWise<Scalar = T>,
T: Float,
impl<C, T> From<PreAlpha<C, T>> for Alpha<C, T> where
C: ComponentWise<Scalar = T>,
T: Float,
[src]
impl<C, T> From<PreAlpha<C, T>> for Alpha<C, T> where
C: ComponentWise<Scalar = T>,
T: Float,
impl<C, T> Blend for PreAlpha<C, T> where
C: Blend<Color = C> + ComponentWise<Scalar = T>,
T: Float,
[src]
impl<C, T> Blend for PreAlpha<C, T> where
C: Blend<Color = C> + ComponentWise<Scalar = T>,
T: Float,
type Color = C
The core color type. Typically Self
for color types without alpha.
fn into_premultiplied(self) -> PreAlpha<C, T>
[src]
fn into_premultiplied(self) -> PreAlpha<C, T>
Convert the color to premultiplied alpha.
fn from_premultiplied(color: PreAlpha<C, T>) -> PreAlpha<C, T>
[src]
fn from_premultiplied(color: PreAlpha<C, T>) -> PreAlpha<C, T>
Convert the color from premultiplied alpha.
fn blend<F>(self, destination: Self, blend_function: F) -> Self where
F: BlendFunction<Self::Color>,
[src]
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
fn over(self, other: Self) -> Self
[src]
fn over(self, other: Self) -> Self
Place self
over other
. This is the good old common alpha composition equation. Read more
fn inside(self, other: Self) -> Self
[src]
fn inside(self, other: Self) -> Self
Results in the parts of self
that overlaps the visible parts of other
. Read more
fn outside(self, other: Self) -> Self
[src]
fn outside(self, other: Self) -> Self
Results in the parts of self
that lies outside the visible parts of other
. Read more
fn atop(self, other: Self) -> Self
[src]
fn atop(self, other: Self) -> Self
Place self
over only the visible parts of other
.
fn xor(self, other: Self) -> Self
[src]
fn xor(self, other: Self) -> Self
Results in either self
or other
, where they do not overlap.
fn plus(self, other: Self) -> Self
[src]
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
fn multiply(self, other: Self) -> Self
[src]
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
fn screen(self, other: Self) -> Self
[src]
fn screen(self, other: Self) -> Self
Make a color which is at least as light as self
or other
.
fn overlay(self, other: Self) -> Self
[src]
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
fn darken(self, other: Self) -> Self
[src]
fn darken(self, other: Self) -> Self
Return the darkest parts of self
and other
.
fn lighten(self, other: Self) -> Self
[src]
fn lighten(self, other: Self) -> Self
Return the lightest parts of self
and other
.
fn dodge(self, other: Self) -> Self
[src]
fn dodge(self, other: Self) -> Self
Lighten other
to reflect self
. Results in other
if self
is black. Read more
fn burn(self, other: Self) -> Self
[src]
fn burn(self, other: Self) -> Self
Darken other
to reflect self
. Results in other
if self
is white. Read more
fn hard_light(self, other: Self) -> Self
[src]
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
fn soft_light(self, other: Self) -> Self
[src]
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
fn difference(self, other: Self) -> Self
[src]
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
fn exclusion(self, other: Self) -> Self
[src]
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. Read more
impl<C: Mix> Mix for PreAlpha<C, C::Scalar>
[src]
impl<C: Mix> Mix for PreAlpha<C, C::Scalar>
type Scalar = C::Scalar
The type of the mixing factor.
fn mix(
&self,
other: &PreAlpha<C, C::Scalar>,
factor: C::Scalar
) -> PreAlpha<C, C::Scalar>
[src]
fn mix(
&self,
other: &PreAlpha<C, C::Scalar>,
factor: C::Scalar
) -> PreAlpha<C, C::Scalar>
Mix the color with an other color, by factor
. Read more
impl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>
[src]
impl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>
type Scalar = T
The scalar type for color components.
fn component_wise<F: FnMut(T, T) -> T>(
&self,
other: &PreAlpha<C, T>,
f: F
) -> PreAlpha<C, T>
[src]
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.
fn component_wise_self<F: FnMut(T) -> T>(&self, f: F) -> PreAlpha<C, T>
[src]
fn component_wise_self<F: FnMut(T) -> T>(&self, f: F) -> PreAlpha<C, T>
Perform a unary operation on this color.
impl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>
[src]
impl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>
const CHANNELS: usize
CHANNELS: usize = <C>::CHANNELS + 1
The number of color channels.
fn as_raw<P: RawPixel<T> + ?Sized>(&self) -> &P
[src]
fn as_raw<P: RawPixel<T> + ?Sized>(&self) -> &P
Cast as a reference to raw color components.
fn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
[src]
fn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
Cast as a mutable reference to raw color components.
fn into_raw<P: RawPixelSized<T>>(self) -> P
[src]
fn into_raw<P: RawPixelSized<T>>(self) -> P
Convert from raw color components.
fn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
[src]
fn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
Cast from a reference to raw color components.
fn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
[src]
fn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
Cast from a mutable reference to raw color components.
fn from_raw_slice(slice: &[T]) -> &[Self]
[src]
fn from_raw_slice(slice: &[T]) -> &[Self]
Cast a slice of raw color components to a slice of colors. Read more
fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]
[src]
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
fn into_raw_slice(slice: &[Self]) -> &[T]
[src]
fn into_raw_slice(slice: &[Self]) -> &[T]
Cast a slice of colors to a slice of raw color components. Read more
fn into_raw_slice_mut(slice: &mut [Self]) -> &mut [T]
[src]
fn into_raw_slice_mut(slice: &mut [Self]) -> &mut [T]
Cast a mutable slice of colors to a mutable slice of raw color components. Read more
impl<C: Default, T: Float> Default for PreAlpha<C, T>
[src]
impl<C: Default, T: Float> Default for PreAlpha<C, T>
impl<C, T> ApproxEq for PreAlpha<C, T> where
C: ApproxEq<Epsilon = T::Epsilon>,
T: ApproxEq + Float,
T::Epsilon: Copy,
[src]
impl<C, T> ApproxEq for PreAlpha<C, T> where
C: ApproxEq<Epsilon = T::Epsilon>,
T: ApproxEq + Float,
T::Epsilon: Copy,
type Epsilon = T::Epsilon
Used for specifying relative comparisons.
fn default_epsilon() -> Self::Epsilon
[src]
fn default_epsilon() -> Self::Epsilon
The default tolerance to use when testing values that are close together. Read more
fn default_max_relative() -> Self::Epsilon
[src]
fn default_max_relative() -> Self::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
fn default_max_ulps() -> u32
[src]
fn default_max_ulps() -> u32
The default ULPs to tolerate when testing values that are far-apart. Read more
fn relative_eq(
&self,
other: &PreAlpha<C, T>,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
[src]
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.
fn ulps_eq(
&self,
other: &PreAlpha<C, T>,
epsilon: Self::Epsilon,
max_ulps: u32
) -> bool
[src]
fn ulps_eq(
&self,
other: &PreAlpha<C, T>,
epsilon: Self::Epsilon,
max_ulps: u32
) -> bool
A test for equality that uses units in the last place (ULP) if the values are far apart.
fn relative_ne(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
[src]
fn relative_ne(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
The inverse of ApproxEq::relative_eq
.
fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool
[src]
fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool
The inverse of ApproxEq::ulps_eq
.
impl<C: Add, T: Float> Add for PreAlpha<C, T>
[src]
impl<C: Add, T: Float> Add for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the +
operator.
fn add(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
[src]
fn add(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
Performs the +
operation.
impl<T: Float, C: Add<T>> Add<T> for PreAlpha<C, T>
[src]
impl<T: Float, C: Add<T>> Add<T> for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the +
operator.
fn add(self, c: T) -> PreAlpha<C::Output, T>
[src]
fn add(self, c: T) -> PreAlpha<C::Output, T>
Performs the +
operation.
impl<C: Sub, T: Float> Sub for PreAlpha<C, T>
[src]
impl<C: Sub, T: Float> Sub for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the -
operator.
fn sub(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
[src]
fn sub(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
Performs the -
operation.
impl<T: Float, C: Sub<T>> Sub<T> for PreAlpha<C, T>
[src]
impl<T: Float, C: Sub<T>> Sub<T> for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the -
operator.
fn sub(self, c: T) -> PreAlpha<C::Output, T>
[src]
fn sub(self, c: T) -> PreAlpha<C::Output, T>
Performs the -
operation.
impl<C: Mul, T: Float> Mul for PreAlpha<C, T>
[src]
impl<C: Mul, T: Float> Mul for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the *
operator.
fn mul(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
[src]
fn mul(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
Performs the *
operation.
impl<T: Float, C: Mul<T>> Mul<T> for PreAlpha<C, T>
[src]
impl<T: Float, C: Mul<T>> Mul<T> for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the *
operator.
fn mul(self, c: T) -> PreAlpha<C::Output, T>
[src]
fn mul(self, c: T) -> PreAlpha<C::Output, T>
Performs the *
operation.
impl<C: Div, T: Float> Div for PreAlpha<C, T>
[src]
impl<C: Div, T: Float> Div for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the /
operator.
fn div(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
[src]
fn div(self, other: PreAlpha<C, T>) -> PreAlpha<C::Output, T>
Performs the /
operation.
impl<T: Float, C: Div<T>> Div<T> for PreAlpha<C, T>
[src]
impl<T: Float, C: Div<T>> Div<T> for PreAlpha<C, T>
type Output = PreAlpha<C::Output, T>
The resulting type after applying the /
operator.
fn div(self, c: T) -> PreAlpha<C::Output, T>
[src]
fn div(self, c: T) -> PreAlpha<C::Output, T>
Performs the /
operation.
impl<C, T, P: ?Sized> AsRef<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T>,
[src]
impl<C, T, P: ?Sized> AsRef<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T>,
impl<C, T, P: ?Sized> AsMut<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T>,
[src]
impl<C, T, P: ?Sized> AsMut<P> for PreAlpha<C, T> where
C: Pixel<T>,
T: Float,
P: RawPixel<T>,
impl<C, T: Float> Deref for PreAlpha<C, T>
[src]
impl<C, T: Float> Deref for PreAlpha<C, T>
type Target = C
The resulting type after dereferencing.
fn deref(&self) -> &C
[src]
fn deref(&self) -> &C
Dereferences the value.
impl<C, T: Float> DerefMut for PreAlpha<C, T>
[src]
impl<C, T: Float> DerefMut for PreAlpha<C, T>