Skip to main content

Color

Enum Color 

Source
pub enum Color {
Show 33 variants Rgb(Rgb), LinearRgb(LinearRgb), Hsl(Hsl), Hsv(Hsv), Hwb(Hwb), Lab(Lab), Lab65(Lab65), Lch(Lch), Lch65(Lch65), Oklab(Oklab), Oklch(Oklch), Xyz50(Xyz50), Xyz65(Xyz65), P3(P3), Rec2020(Rec2020), A98(A98), ProphotoRgb(ProphotoRgb), Cubehelix(Cubehelix), Dlab(Dlab), Dlch(Dlch), Jab(Jab), Jch(Jch), Yiq(Yiq), Hsi(Hsi), Hsluv(Hsluv), Hpluv(Hpluv), Okhsl(Okhsl), Okhsv(Okhsv), Itp(Itp), Xyb(Xyb), Luv(Luv), Lchuv(Lchuv), Prismatic(Prismatic),
}
Expand description

Tagged union over every supported color space. Variants are added as each space lands.

Variants§

§

Rgb(Rgb)

sRGB.

§

LinearRgb(LinearRgb)

Linear-sRGB.

§

Hsl(Hsl)

HSL (cylindrical sRGB).

§

Hsv(Hsv)

HSV (cylindrical sRGB).

§

Hwb(Hwb)

HWB (hue/whiteness/blackness).

§

Lab(Lab)

CIE Lab D50.

§

Lab65(Lab65)

CIE Lab D65.

§

Lch(Lch)

CIE Lch D50 (polar Lab).

§

Lch65(Lch65)

CIE Lch D65 (polar Lab65).

§

Oklab(Oklab)

Oklab (perceptually uniform).

§

Oklch(Oklch)

Oklch (polar Oklab).

§

Xyz50(Xyz50)

CIE XYZ D50.

§

Xyz65(Xyz65)

CIE XYZ D65.

§

P3(P3)

Display P3.

§

Rec2020(Rec2020)

Rec. 2020.

§

A98(A98)

Adobe RGB (1998).

§

ProphotoRgb(ProphotoRgb)

ProPhoto RGB.

§

Cubehelix(Cubehelix)

Cubehelix (Dave Green’s astronomical color scheme as a space).

§

Dlab(Dlab)

DIN99o Lab (rectangular form of DIN99o LCh).

§

Dlch(Dlch)

DIN99o LCh (polar form).

§

Jab(Jab)

JzAzBz (HDR perceptual Lab).

§

Jch(Jch)

JzCzHz (polar form of JzAzBz).

§

Yiq(Yiq)

NTSC Y’IQ.

§

Hsi(Hsi)

HSI (Hue/Saturation/Intensity).

§

Hsluv(Hsluv)

HSLuv (perceptually uniform HSL).

§

Hpluv(Hpluv)

HPLuv (perceptually uniform HSL, pastel).

§

Okhsl(Okhsl)

OkHSL (Oklab-derived HSL).

§

Okhsv(Okhsv)

OkHSV (Oklab-derived HSV).

§

Itp(Itp)

ICtCp (HDR perceptual, Rec. BT.2100).

§

Xyb(Xyb)

XYB (JPEG XL).

§

Luv(Luv)

CIELUV (D50).

§

Lchuv(Lchuv)

CIELChuv (polar form of CIELUV).

§

Prismatic(Prismatic)

Prismatic (intensity + barycentric chromaticity, Hauke 2009). culors extension; not in culori 4.0.2.

Implementations§

Source§

impl Color

Source

pub fn mode(&self) -> &'static str

Returns the culori mode string for this color’s underlying space ("rgb", "lab", "oklch", etc.). Identical to the corresponding space struct’s ColorSpace::MODE.

Source§

impl Color

Source

pub fn convert_to(&self, target_mode: &str) -> Option<Color>

Convert this color to the named target color space, mirroring culori’s converter(target_mode)(self) dispatch.

Returns None if target_mode is not a recognized culori mode string. Recognized modes match the ColorSpace::MODE constants of every space implemented by this crate ("rgb", "hsl", "hsv", "hwb", "lab", "lab65", "lch", "lch65", "oklab", "oklch", "xyz50", "xyz65", "p3", "rec2020", "a98", "prophoto", "lrgb", "cubehelix", "dlab", "dlch", "jab", "jch", "yiq", "hsi", "hsluv", "hpluv", "okhsl", "okhsv", "itp", "xyb", "luv", "lchuv", "prismatic").

§Routing semantics

For every pair (from, target_mode) where culori 4.0.2’s converters table has a direct entry, this method takes the same path. For pairs without a direct entry, both this method and culori route through rgb. Output agrees with culori.converter(target_mode)(self) to within 1e-13 per channel across the full pair matrix (see fixture suite).

Contrast with crate::convert() which always routes through XYZ D65 and so accumulates ~1e-14 drift on pairs where culori takes a shorter path.

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate 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 Debug for Color

Source§

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

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

impl From<A98> for Color

Source§

fn from(c: A98) -> Self

Converts to this type from the input type.
Source§

impl From<Cubehelix> for Color

Source§

fn from(c: Cubehelix) -> Self

Converts to this type from the input type.
Source§

impl From<Dlab> for Color

Source§

fn from(c: Dlab) -> Self

Converts to this type from the input type.
Source§

impl From<Dlch> for Color

Source§

fn from(c: Dlch) -> Self

Converts to this type from the input type.
Source§

impl From<Hpluv> for Color

Source§

fn from(c: Hpluv) -> Self

Converts to this type from the input type.
Source§

impl From<Hsi> for Color

Source§

fn from(c: Hsi) -> Self

Converts to this type from the input type.
Source§

impl From<Hsl> for Color

Source§

fn from(c: Hsl) -> Self

Converts to this type from the input type.
Source§

impl From<Hsluv> for Color

Source§

fn from(c: Hsluv) -> Self

Converts to this type from the input type.
Source§

impl From<Hsv> for Color

Source§

fn from(c: Hsv) -> Self

Converts to this type from the input type.
Source§

impl From<Hwb> for Color

Source§

fn from(c: Hwb) -> Self

Converts to this type from the input type.
Source§

impl From<Itp> for Color

Source§

fn from(c: Itp) -> Self

Converts to this type from the input type.
Source§

impl From<Jab> for Color

Source§

fn from(c: Jab) -> Self

Converts to this type from the input type.
Source§

impl From<Jch> for Color

Source§

fn from(c: Jch) -> Self

Converts to this type from the input type.
Source§

impl From<Lab> for Color

Source§

fn from(c: Lab) -> Self

Converts to this type from the input type.
Source§

impl From<Lab65> for Color

Source§

fn from(c: Lab65) -> Self

Converts to this type from the input type.
Source§

impl From<Lch> for Color

Source§

fn from(c: Lch) -> Self

Converts to this type from the input type.
Source§

impl From<Lch65> for Color

Source§

fn from(c: Lch65) -> Self

Converts to this type from the input type.
Source§

impl From<Lchuv> for Color

Source§

fn from(c: Lchuv) -> Self

Converts to this type from the input type.
Source§

impl From<LinearRgb> for Color

Source§

fn from(c: LinearRgb) -> Self

Converts to this type from the input type.
Source§

impl From<Luv> for Color

Source§

fn from(c: Luv) -> Self

Converts to this type from the input type.
Source§

impl From<Okhsl> for Color

Source§

fn from(c: Okhsl) -> Self

Converts to this type from the input type.
Source§

impl From<Okhsv> for Color

Source§

fn from(c: Okhsv) -> Self

Converts to this type from the input type.
Source§

impl From<Oklab> for Color

Source§

fn from(c: Oklab) -> Self

Converts to this type from the input type.
Source§

impl From<Oklch> for Color

Source§

fn from(c: Oklch) -> Self

Converts to this type from the input type.
Source§

impl From<P3> for Color

Source§

fn from(c: P3) -> Self

Converts to this type from the input type.
Source§

impl From<Prismatic> for Color

Source§

fn from(c: Prismatic) -> Self

Converts to this type from the input type.
Source§

impl From<ProphotoRgb> for Color

Source§

fn from(c: ProphotoRgb) -> Self

Converts to this type from the input type.
Source§

impl From<Rec2020> for Color

Source§

fn from(c: Rec2020) -> Self

Converts to this type from the input type.
Source§

impl From<Rgb> for Color

Source§

fn from(c: Rgb) -> Self

Converts to this type from the input type.
Source§

impl From<Xyb> for Color

Source§

fn from(c: Xyb) -> Self

Converts to this type from the input type.
Source§

impl From<Xyz50> for Color

Source§

fn from(c: Xyz50) -> Self

Converts to this type from the input type.
Source§

impl From<Xyz65> for Color

Source§

fn from(c: Xyz65) -> Self

Converts to this type from the input type.
Source§

impl From<Yiq> for Color

Source§

fn from(c: Yiq) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Color) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Color> for A98

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Cubehelix

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Dlab

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Dlch

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Hpluv

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Hsi

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Hsl

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Hsluv

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Hsv

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Hwb

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Itp

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Jab

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Jch

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Lab

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Lab65

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Lch

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Lch65

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Lchuv

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for LinearRgb

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Luv

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Okhsl

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Okhsv

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Oklab

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Oklch

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for P3

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Prismatic

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for ProphotoRgb

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Rec2020

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Rgb

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Xyb

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Xyz50

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Xyz65

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Color> for Yiq

Source§

type Error = ColorVariantMismatch

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

fn try_from(c: Color) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Color

Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnsafeUnpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.