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

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, Rgb, Rgba};
use palette::blend::PreAlpha;

let a = PreAlpha::from(Rgba::new(0.4, 0.5, 0.5, 0.3));
let b = PreAlpha::from(Rgba::new(0.3, 0.8, 0.4, 0.4));
let c = PreAlpha::from(Rgba::new(0.7, 0.1, 0.8, 0.8));

let res = Rgb::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

The premultiplied color components (original.color * original.alpha).

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]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

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

[src]

Formats the value using the given formatter.

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

[src]

Performs the conversion.

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

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

[src]

Convert the color to premultiplied alpha.

[src]

Convert the color from premultiplied alpha.

[src]

Blend self, as the source color, with destination, using blend_function. Anything that implements BlendFunction is acceptable, including functions and closures. Read more

[src]

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

[src]

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

[src]

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

[src]

Place self over only the visible parts of other.

[src]

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

[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

[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

[src]

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

[src]

Multiply self or other if other is dark, or screen them if other is light. This results in an S curve. Read more

[src]

Return the darkest parts of self and other.

[src]

Return the lightest parts of self and other.

[src]

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

[src]

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

[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

[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

[src]

Return the absolute difference between self and other. It's basically abs(self - other), but regulated by the alpha component. Read more

[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: Mix> Mix for PreAlpha<C, C::Scalar>
[src]

The type of the mixing factor.

[src]

Mix the color with an other color, by factor. Read more

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

The scalar type for color components.

[src]

Perform a binary operation on this and an other color.

[src]

Perform a unary operation on this color.

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

Used for specifying relative comparisons.

[src]

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

[src]

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

[src]

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

[src]

A test for equality that uses a relative comparison if the values are far apart.

[src]

A test for equality that uses units in the last place (ULP) if the values are far apart.

[src]

The inverse of ApproxEq::relative_eq.

[src]

The inverse of ApproxEq::ulps_eq.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after dereferencing.

[src]

Dereferences the value.

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

[src]

Mutably dereferences the value.