Enum palette::Color [] [src]

pub enum Color<T: Float = f32> {
    Luma(Luma<T>),
    Rgb(Rgb<T>),
    Xyz(Xyz<T>),
    Yxy(Yxy<T>),
    Lab(Lab<T>),
    Lch(Lch<T>),
    Hsv(Hsv<T>),
    Hsl(Hsl<T>),
    Hwb(Hwb<T>),
}

A generic color type.

The Color may belong to any color space and it may change depending on which operation is performed. That makes it immune to the "without conversion" rule of the operations it supports. The color spaces are selected as follows:

  • Mix: RGB for no particular reason, except that it's intuitive.
  • Shade: CIE L*a*b* for its luminance component.
  • Hue and GetHue: CIE L*C*h° for its hue component and how it preserves the apparent lightness.
  • Saturate: CIE L*C*h° for its chromaticity component and how it preserves the apparent lightness.

It's not recommended to use Color when full control is necessary, but it can easily be converted to a fixed color space in those cases.

Variants

Luma(Luma<T>)

Linear luminance.

Rgb(Rgb<T>)

Linear RGB.

Xyz(Xyz<T>)

CIE 1931 XYZ.

Yxy(Yxy<T>)

CIE 1931 Yxy.

Lab(Lab<T>)

CIE L*a*b* (CIELAB).

Lch(Lch<T>)

CIE L*C*h°, a polar version of CIE L*a*b*.

Hsv(Hsv<T>)

Linear HSV, a cylindrical version of RGB.

Hsl(Hsl<T>)

Linear HSL, a cylindrical version of RGB.

Hwb(Hwb<T>)

Linear HWB, an intuitive cylindrical version of RGB.

Methods

impl<T: Float> Color<T>
[src]

fn y(luma: T) -> Color<T>

Linear luminance.

fn y_u8(luma: u8) -> Color<T>

Linear luminance from an 8 bit value.

fn rgb(red: T, green: T, blue: T) -> Color<T>

Linear RGB.

fn rgb_u8(red: u8, green: u8, blue: u8) -> Color<T>

Linear RGB from 8 bit values.

fn xyz(x: T, y: T, z: T) -> Color<T>

CIE XYZ.

fn yxy(x: T, y: T, luma: T) -> Color<T>

CIE Yxy.

fn lab(l: T, a: T, b: T) -> Color<T>

CIE L*a*b*.

fn lch(l: T, chroma: T, hue: LabHue<T>) -> Color<T>

CIE L*C*h°.

fn hsv(hue: RgbHue<T>, saturation: T, value: T) -> Color<T>

Linear HSV.

fn hsl(hue: RgbHue<T>, saturation: T, lightness: T) -> Color<T>

Linear HSL.

fn hwb(hue: RgbHue<T>, whiteness: T, balckness: T) -> Color<T>

Linear HWB.

Trait Implementations

impl<T: Debug + Float> Debug for Color<T>
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<T: Copy + Float> Copy for Color<T>
[src]

impl<T: Clone + Float> Clone for Color<T>
[src]

fn clone(&self) -> Color<T>

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl<T: Float> Mix for Color<T>
[src]

type Scalar = T

The type of the mixing factor.

fn mix(&self, other: &Color<T>, factor: T) -> Color<T>

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

impl<T: Float> Shade for Color<T>
[src]

type Scalar = T

The type of the lighten/darken amount.

fn lighten(&self, amount: T) -> Color<T>

Lighten the color by amount.

fn darken(&self, amount: Self::Scalar) -> Self

Darken the color by amount.

impl<T: Float> GetHue for Color<T>
[src]

type Hue = LabHue<T>

The kind of hue unit this color space uses. Read more

fn get_hue(&self) -> Option<LabHue<T>>

Calculate a hue if possible. Read more

impl<T: Float> Hue for Color<T>
[src]

fn with_hue(&self, hue: LabHue<T>) -> Color<T>

Return a new copy of self, but with a specific hue.

fn shift_hue(&self, amount: LabHue<T>) -> Color<T>

Return a new copy of self, but with the hue shifted by amount.

impl<T: Float> Saturate for Color<T>
[src]

type Scalar = T

The type of the (de)saturation factor.

fn saturate(&self, factor: T) -> Color<T>

Increase the saturation by factor.

fn desaturate(&self, factor: Self::Scalar) -> Self

Decrease the saturation by factor.

impl<T: Float> Blend for Color<T>
[src]

type Color = Rgb<T>

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

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

Convert the color to premultiplied alpha.

fn from_premultiplied(color: PreAlpha<Rgb<T>, T>) -> Self

Convert the color from premultiplied alpha.

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

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

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

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

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

Place self over only the visible parts of other.

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

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

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

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

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

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

Return the darkest parts of self and other.

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

Return the lightest parts of self and other.

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

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

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

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

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

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<T> ApproxEq for Color<T> where T: Float + ApproxEq, T::Epsilon: Copy + Float
[src]

type Epsilon = T::Epsilon

Used for specifying relative comparisons.

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

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

fn default_max_ulps() -> u32

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

fn relative_eq(&self, other: &Self, 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: &Self, 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

The inverse of ApproxEq::relative_eq.

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

The inverse of ApproxEq::ulps_eq.

impl<T: Float> From<Luma<T>> for Color<T>
[src]

fn from(color: Luma<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Luma<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Luma<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Rgb<T>> for Color<T>
[src]

fn from(color: Rgb<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Rgb<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Rgb<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Srgb<T>> for Color<T>
[src]

fn from(color: Srgb<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<GammaRgb<T>> for Color<T>
[src]

fn from(color: GammaRgb<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Xyz<T>> for Color<T>
[src]

fn from(color: Xyz<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Xyz<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Xyz<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Yxy<T>> for Color<T>
[src]

fn from(color: Yxy<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Yxy<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Yxy<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Lab<T>> for Color<T>
[src]

fn from(color: Lab<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Lab<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Lab<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Lch<T>> for Color<T>
[src]

fn from(color: Lch<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Lch<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Lch<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Hsv<T>> for Color<T>
[src]

fn from(color: Hsv<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Hsv<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Hsv<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Hsl<T>> for Color<T>
[src]

fn from(color: Hsl<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Hsl<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Hsl<T>, T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Hwb<T>> for Color<T>
[src]

fn from(color: Hwb<T>) -> Color<T>

Performs the conversion.

impl<T: Float> From<Alpha<Hwb<T>, T>> for Color<T>
[src]

fn from(color: Alpha<Hwb<T>, T>) -> Color<T>

Performs the conversion.