Enum palette::Color [] [src]

pub enum Color<T: Float = f32> {
    Luma(Luma<T>),
    Rgb(Rgb<T>),
    Xyz(Xyz<T>),
    Lab(Lab<T>),
    Lch(Lch<T>),
    Hsv(Hsv<T>),
    Hsl(Hsl<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.

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.

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

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> From<Luma<T>> for Color<T>
[src]

fn from(color: Luma<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<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<Lab<T>> for Color<T>
[src]

fn from(color: Lab<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<Hsv<T>> for Color<T>
[src]

fn from(color: Hsv<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<Color<T>, T>> for Color<T>
[src]

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.