Struct palette::blend::PreAlpha

source ·
#[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>
where C: AbsDiffEq<Epsilon = T::Epsilon>, T: AbsDiffEq + Float, T::Epsilon: Copy,

§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

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.
source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of ApproxEq::abs_diff_eq.
source§

impl<T: Float, C: Add<T>> Add<T> for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Add<T>>::Output, T>

The resulting type after applying the + operator.
source§

fn add(self, c: T) -> Self::Output

Performs the + operation. Read more
source§

impl<C: Add, T: Float> Add for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Add>::Output, T>

The resulting type after applying the + operator.
source§

fn add(self, other: PreAlpha<C, T>) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Float + AddAssign, C: AddAssign<T>> AddAssign<T> for PreAlpha<C, T>

source§

fn add_assign(&mut self, c: T)

Performs the += operation. Read more
source§

impl<C: AddAssign, T: Float + AddAssign> AddAssign for PreAlpha<C, T>

source§

fn add_assign(&mut self, other: PreAlpha<C, T>)

Performs the += operation. Read more
source§

impl<C, T, P> AsMut<P> for PreAlpha<C, T>
where C: Pixel<T>, T: Float, P: RawPixel<T> + ?Sized,

source§

fn as_mut(&mut self) -> &mut P

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<C, T, P> AsRef<P> for PreAlpha<C, T>
where C: Pixel<T>, T: Float, P: RawPixel<T> + ?Sized,

source§

fn as_ref(&self) -> &P

Converts this type into a shared reference of the (usually inferred) input type.
source§

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.
source§

fn into_premultiplied(self) -> PreAlpha<C, T>

Convert the color to premultiplied alpha.
source§

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) -> 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
source§

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

Results in the parts of self that overlaps the visible parts of other.
source§

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

Results in the parts of self that lies outside the visible parts of other.
source§

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

Place self over only the visible parts of other.
source§

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

Results in either self or other, where they do not overlap.
source§

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

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.
source§

impl<C: Clone, T: Clone + Float> Clone for PreAlpha<C, T>

source§

fn clone(&self) -> PreAlpha<C, T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: ComponentWise<Scalar = T>, T: Float> ComponentWise for PreAlpha<C, T>

§

type Scalar = T

The scalar type for color components.
source§

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.
source§

fn component_wise_self<F: FnMut(T) -> T>(&self, f: F) -> PreAlpha<C, T>

Perform a unary operation on this color.
source§

impl<C: Debug, T: Debug + Float> Debug for PreAlpha<C, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<C: Default, T: Float> Default for PreAlpha<C, T>

source§

fn default() -> PreAlpha<C, T>

Returns the “default value” for a type. Read more
source§

impl<C, T: Float> Deref for PreAlpha<C, T>

§

type Target = C

The resulting type after dereferencing.
source§

fn deref(&self) -> &C

Dereferences the value.
source§

impl<C, T: Float> DerefMut for PreAlpha<C, T>

source§

fn deref_mut(&mut self) -> &mut C

Mutably dereferences the value.
source§

impl<'de, C, T> Deserialize<'de> for PreAlpha<C, T>
where C: Deserialize<'de>, T: Deserialize<'de> + Float,

source§

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, C: Div<T>> Div<T> for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Div<T>>::Output, T>

The resulting type after applying the / operator.
source§

fn div(self, c: T) -> Self::Output

Performs the / operation. Read more
source§

impl<C: Div, T: Float> Div for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Div>::Output, T>

The resulting type after applying the / operator.
source§

fn div(self, other: PreAlpha<C, T>) -> Self::Output

Performs the / operation. Read more
source§

impl<T: Float + DivAssign, C: DivAssign<T>> DivAssign<T> for PreAlpha<C, T>

source§

fn div_assign(&mut self, c: T)

Performs the /= operation. Read more
source§

impl<C: DivAssign, T: Float + DivAssign> DivAssign for PreAlpha<C, T>

source§

fn div_assign(&mut self, other: PreAlpha<C, T>)

Performs the /= operation. Read more
source§

impl<C, T> From<Alpha<C, T>> for PreAlpha<C, T>
where C: ComponentWise<Scalar = T>, T: Float,

source§

fn from(color: Alpha<C, T>) -> PreAlpha<C, T>

Converts to this type from the input type.
source§

impl<C, T> From<PreAlpha<C, T>> for Alpha<C, T>
where C: ComponentWise<Scalar = T>, T: Float,

source§

fn from(color: PreAlpha<C, T>) -> Alpha<C, T>

Converts to this type from the input type.
source§

impl<C: Mix> Mix for PreAlpha<C, C::Scalar>

§

type Scalar = <C as Mix>::Scalar

The type of the mixing factor.
source§

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

impl<T: Float, C: Mul<T>> Mul<T> for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Mul<T>>::Output, T>

The resulting type after applying the * operator.
source§

fn mul(self, c: T) -> Self::Output

Performs the * operation. Read more
source§

impl<C: Mul, T: Float> Mul for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Mul>::Output, T>

The resulting type after applying the * operator.
source§

fn mul(self, other: PreAlpha<C, T>) -> Self::Output

Performs the * operation. Read more
source§

impl<T: Float + MulAssign, C: MulAssign<T>> MulAssign<T> for PreAlpha<C, T>

source§

fn mul_assign(&mut self, c: T)

Performs the *= operation. Read more
source§

impl<C: MulAssign, T: Float + MulAssign> MulAssign for PreAlpha<C, T>

source§

fn mul_assign(&mut self, other: PreAlpha<C, T>)

Performs the *= operation. Read more
source§

impl<C: PartialEq, T: PartialEq + Float> PartialEq for PreAlpha<C, T>

source§

fn eq(&self, other: &PreAlpha<C, T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Float, C: Pixel<T>> Pixel<T> for PreAlpha<C, T>

source§

const CHANNELS: usize = _

The number of color channels.
source§

fn as_raw<P: RawPixel<T> + ?Sized>(&self) -> &P

Cast as a reference to raw color components.
source§

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

Convert from raw color components.
source§

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

Cast from a mutable reference to raw color components.
source§

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]

Cast a mutable slice of raw color components to a mutable slice of colors. Read more
source§

fn into_raw_slice(slice: &[Self]) -> &[T]

Cast a slice of colors to a slice of raw color components. Read more
source§

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

impl<C, T> RelativeEq for PreAlpha<C, T>
where C: RelativeEq<Epsilon = T::Epsilon>, T: RelativeEq + Float, T::Epsilon: Copy,

source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

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.
source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

The inverse of ApproxEq::relative_eq.
source§

impl<C, T> Serialize for PreAlpha<C, T>
where C: Serialize, T: Serialize + Float,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Float, C: Sub<T>> Sub<T> for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Sub<T>>::Output, T>

The resulting type after applying the - operator.
source§

fn sub(self, c: T) -> Self::Output

Performs the - operation. Read more
source§

impl<C: Sub, T: Float> Sub for PreAlpha<C, T>

§

type Output = PreAlpha<<C as Sub>::Output, T>

The resulting type after applying the - operator.
source§

fn sub(self, other: PreAlpha<C, T>) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Float + SubAssign, C: SubAssign<T>> SubAssign<T> for PreAlpha<C, T>

source§

fn sub_assign(&mut self, c: T)

Performs the -= operation. Read more
source§

impl<C: SubAssign, T: Float + SubAssign> SubAssign for PreAlpha<C, T>

source§

fn sub_assign(&mut self, other: PreAlpha<C, T>)

Performs the -= operation. Read more
source§

impl<C, T> UlpsEq for PreAlpha<C, T>
where C: UlpsEq<Epsilon = T::Epsilon>, T: UlpsEq + Float, T::Epsilon: Copy,

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

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.
source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of ApproxEq::ulps_eq.
source§

impl<C: Copy, T: Copy + Float> Copy for PreAlpha<C, T>

source§

impl<C, T: Float> StructuralPartialEq for PreAlpha<C, T>

Auto Trait Implementations§

§

impl<C, T> RefUnwindSafe for PreAlpha<C, T>

§

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§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

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

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

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

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

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,