[][src]Struct amethyst_rendy::palette::blend::PreAlpha

#[repr(C)]
pub struct PreAlpha<C, T> where
    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, T> Default for PreAlpha<C, T> where
    C: Default,
    T: Float
[src]

impl<C, T> Copy for PreAlpha<C, T> where
    C: Copy,
    T: Copy + Float
[src]

impl<T, C> Pixel<T> for PreAlpha<C, T> where
    C: Pixel<T>,
    T: Float
[src]

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

Cast as a reference to raw color components.

fn as_raw_mut<P>(&mut self) -> &mut P where
    P: RawPixel<T> + ?Sized
[src]

Cast as a mutable reference to raw color components.

fn into_raw<P>(self) -> P where
    P: RawPixelSized<T>, 
[src]

Convert from raw color components.

fn from_raw<P>(pixel: &P) -> &Self where
    P: RawPixel<T> + ?Sized
[src]

Cast from a reference to raw color components.

fn from_raw_mut<P>(pixel: &mut P) -> &mut Self where
    P: RawPixel<T> + ?Sized
[src]

Cast from a mutable reference to raw color components.

Important traits for &'_ [u8]
fn from_raw_slice(slice: &[T]) -> &[Self][src]

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

Important traits for &'_ [u8]
fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self][src]

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

Important traits for &'_ [u8]
fn into_raw_slice(slice: &[Self]) -> &[T][src]

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

Important traits for &'_ [u8]
fn into_raw_slice_mut(slice: &mut [Self]) -> &mut [T][src]

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

impl<C, T> Clone for PreAlpha<C, T> where
    C: Clone,
    T: Clone + Float
[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

impl<C, T> Blend for PreAlpha<C, T> where
    C: Blend<Color = C> + ComponentWise<Scalar = T>,
    T: Float
[src]

type Color = C

The core color type. Typically Self for color types without alpha.

fn blend<F>(self, destination: Self, blend_function: F) -> Self where
    F: BlendFunction<Self::Color>, 
[src]

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]

Place self over other. This is the good old common alpha composition equation. Read more

fn inside(self, other: Self) -> Self[src]

Results in the parts of self that overlaps the visible parts of other. Read more

fn outside(self, other: Self) -> Self[src]

Results in the parts of self that lies outside the visible parts of other. Read more

fn atop(self, other: Self) -> Self[src]

Place self over only the visible parts of other.

fn xor(self, other: Self) -> Self[src]

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

fn plus(self, other: Self) -> Self[src]

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]

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]

Make a color which is at least as light as self or other.

fn overlay(self, other: Self) -> Self[src]

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]

Return the darkest parts of self and other.

fn lighten(self, other: Self) -> Self[src]

Return the lightest parts of self and other.

fn dodge(self, other: Self) -> Self[src]

Lighten other to reflect self. Results in other if self is black. Read more

fn burn(self, other: Self) -> Self[src]

Darken other to reflect self. Results in other if self is white. Read more

fn hard_light(self, other: Self) -> Self[src]

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]

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]

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]

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, T> PartialEq<PreAlpha<C, T>> for PreAlpha<C, T> where
    C: PartialEq<C>,
    T: PartialEq<T> + Float
[src]

impl<C, T> Add<PreAlpha<C, T>> for PreAlpha<C, T> where
    C: Add<C>,
    T: Float
[src]

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

The resulting type after applying the + operator.

impl<T, C> Add<T> for PreAlpha<C, T> where
    C: Add<T>,
    T: Float
[src]

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

The resulting type after applying the + operator.

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

impl<C, T> Sub<PreAlpha<C, T>> for PreAlpha<C, T> where
    C: Sub<C>,
    T: Float
[src]

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

The resulting type after applying the - operator.

impl<T, C> Sub<T> for PreAlpha<C, T> where
    C: Sub<T>,
    T: Float
[src]

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

The resulting type after applying the - operator.

impl<C, T> Mul<PreAlpha<C, T>> for PreAlpha<C, T> where
    C: Mul<C>,
    T: Float
[src]

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

The resulting type after applying the * operator.

impl<T, C> Mul<T> for PreAlpha<C, T> where
    C: Mul<T>,
    T: Float
[src]

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

The resulting type after applying the * operator.

impl<C> Mix for PreAlpha<C, <C as Mix>::Scalar> where
    C: Mix
[src]

type Scalar = <C as Mix>::Scalar

The type of the mixing factor.

impl<T, C> Div<T> for PreAlpha<C, T> where
    C: Div<T>,
    T: Float
[src]

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

The resulting type after applying the / operator.

impl<C, T> Div<PreAlpha<C, T>> for PreAlpha<C, T> where
    C: Div<C>,
    T: Float
[src]

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

The resulting type after applying the / operator.

impl<C, T> ApproxEq for PreAlpha<C, T> where
    C: ApproxEq<Epsilon = <T as ApproxEq>::Epsilon>,
    T: ApproxEq + Float,
    <T as ApproxEq>::Epsilon: Copy
[src]

type Epsilon = <T as ApproxEq>::Epsilon

Used for specifying relative comparisons.

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

The inverse of ApproxEq::relative_eq.

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

The inverse of ApproxEq::ulps_eq.

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

impl<C, T> Debug for PreAlpha<C, T> where
    C: Debug,
    T: Debug + Float
[src]

impl<C, T> From<PreAlpha<C, T>> for Alpha<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
[src]

impl<C, T> DerefMut for PreAlpha<C, T> where
    T: Float
[src]

impl<C, T> Deref for PreAlpha<C, T> where
    T: Float
[src]

type Target = C

The resulting type after dereferencing.

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

impl<C, T> ComponentWise for PreAlpha<C, T> where
    C: ComponentWise<Scalar = T>,
    T: Float
[src]

type Scalar = T

The scalar type for color components.

Auto Trait Implementations

impl<C, T> Unpin for PreAlpha<C, T> where
    C: Unpin,
    T: Unpin

impl<C, T> Sync for PreAlpha<C, T> where
    C: Sync,
    T: Sync

impl<C, T> Send for PreAlpha<C, T> where
    C: Send,
    T: Send

impl<C, T> UnwindSafe for PreAlpha<C, T> where
    C: UnwindSafe,
    T: UnwindSafe

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

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

fn adapt_into(self) -> D[src]

Convert the source color to the destination color using the bradford method by default Read more

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

impl<T> SetParameter for T[src]

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 
[src]

Sets value as a parameter of self.

impl<T> MemoryUsage for T where
    T: Deref + Debug,
    <T as Deref>::Target: MemoryUsage
[src]

impl<T> Supports<T> for T[src]

impl<T> Erased for T[src]

impl<T> Serialize for T where
    T: Serialize + ?Sized
[src]

impl<T> Scalar for T where
    T: Copy + PartialEq<T> + Any + Debug
[src]

fn is<T>() -> bool where
    T: Scalar
[src]

Tests if Self the same as the type T Read more

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 
[src]

impl<T> Resource for T where
    T: Any + Send + Sync
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> TryDefault for T where
    T: Default
[src]

fn unwrap_default() -> Self[src]

Calls try_default and panics on an error case.

impl<T> Event for T where
    T: Send + Sync + 'static, 
[src]

impl<T> Clone for T where
    T: Clone
[src]

impl<T> Config for T where
    T: Deserialize<'a> + Serialize + Default
[src]