Enum ColorSpaceTag

Source
#[non_exhaustive]
#[repr(u8)]
pub enum ColorSpaceTag {
Show 16 variants Srgb = 0, LinearSrgb = 1, Lab = 2, Lch = 3, Hsl = 4, Hwb = 5, Oklab = 6, Oklch = 7, DisplayP3 = 8, A98Rgb = 9, ProphotoRgb = 10, Rec2020 = 11, Aces2065_1 = 15, AcesCg = 12, XyzD50 = 13, XyzD65 = 14,
}
Expand description

The color space tag for dynamic colors.

This represents a fixed set of known color spaces. The set contains all color spaces in the CSS Color 4 spec and includes some other color spaces useful for computer graphics.

The integer values of these variants can change in breaking releases.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Srgb = 0

The Srgb color space.

§

LinearSrgb = 1

The LinearSrgb color space.

§

Lab = 2

The Lab color space.

§

Lch = 3

The Lch color space.

§

Hsl = 4

The Hsl color space.

§

Hwb = 5

The Hwb color space.

§

Oklab = 6

The Oklab color space.

§

Oklch = 7

The Oklch color space.

§

DisplayP3 = 8

The DisplayP3 color space.

§

A98Rgb = 9

The A98Rgb color space.

§

ProphotoRgb = 10

The ProphotoRgb color space.

§

Rec2020 = 11

The Rec2020 color space.

§

Aces2065_1 = 15

The Aces2065_1 color space.

§

AcesCg = 12

The AcesCg color space.

§

XyzD50 = 13

The XyzD50 color space.

§

XyzD65 = 14

The XyzD65 color space.

Implementations§

Source§

impl ColorSpaceTag

Source

pub(crate) fn layout(self) -> ColorSpaceLayout

Source

pub(crate) fn same_analogous(self, other: Self) -> bool

Whether all components of the two color spaces are analogous. See also Section 12.2 of CSS Color 4, defining which components are analogous: https://www.w3.org/TR/2024/CRD-css-color-4-20240213/#interpolation-missing.

Note: if color spaces are the same, then they’re also analogous, but in that case we wouldn’t do the conversion, so this function is not guaranteed to return the correct answer in those cases.

Source

pub(crate) fn l_missing(self, missing: Missing) -> bool

Source

pub(crate) fn set_l_missing( self, missing: &mut Missing, components: &mut [f32; 4], )

Source

pub(crate) fn c_missing(self, missing: Missing) -> bool

Source

pub(crate) fn set_c_missing( self, missing: &mut Missing, components: &mut [f32; 4], )

Source

pub(crate) fn h_missing(self, missing: Missing) -> bool

Source

pub(crate) fn set_h_missing( self, missing: &mut Missing, components: &mut [f32; 4], )

Source

pub fn from_linear_srgb(self, rgb: [f32; 3]) -> [f32; 3]

Convert an opaque color from linear sRGB.

This is the tagged counterpart of ColorSpace::from_linear_srgb.

Source

pub fn to_linear_srgb(self, src: [f32; 3]) -> [f32; 3]

Convert an opaque color to linear sRGB.

This is the tagged counterpart of ColorSpace::to_linear_srgb.

Source

pub fn convert(self, target: Self, src: [f32; 3]) -> [f32; 3]

Convert the color components into the target color space.

This is the tagged counterpart of ColorSpace::convert.

Source

pub fn from_linear_srgb_absolute(self, rgb: [f32; 3]) -> [f32; 3]

Convert an opaque color from linear sRGB, without chromatic adaptation.

For most use-cases you should consider using the chromatically-adapting ColorSpaceTag::from_linear_srgb instead.

This is the tagged counterpart of ColorSpace::from_linear_srgb_absolute.

Source

pub fn to_linear_srgb_absolute(self, src: [f32; 3]) -> [f32; 3]

Convert an opaque color to linear sRGB, without chromatic adaptation.

For most use-cases you should consider using the chromatically-adapting ColorSpaceTag::to_linear_srgb instead.

This is the tagged counterpart of ColorSpace::to_linear_srgb_absolute.

Source

pub fn convert_absolute(self, target: Self, src: [f32; 3]) -> [f32; 3]

Convert the color components into the target color space, without chromatic adaptation.

For most use-cases you should consider using the chromatically-adapting ColorSpaceTag::convert instead.

This is the tagged counterpart of ColorSpace::convert_absolute. See the documentation on ColorSpace::convert_absolute for more information.

Source

pub fn chromatically_adapt( self, src: [f32; 3], from: Chromaticity, to: Chromaticity, ) -> [f32; 3]

Chromatically adapt the color between the given white point chromaticities.

This is the tagged counterpart of ColorSpace::chromatically_adapt.

The color is assumed to be under a reference white point of from and is chromatically adapted to the given white point to. The linear Bradford transform is used to perform the chromatic adaptation.

Source

pub fn scale_chroma(self, src: [f32; 3], scale: f32) -> [f32; 3]

Scale the chroma by the given amount.

This is the tagged counterpart of ColorSpace::scale_chroma.

Source

pub fn clip(self, src: [f32; 3]) -> [f32; 3]

Clip the color’s components to fit within the natural gamut of the color space.

See ColorSpace::clip for more details.

Trait Implementations§

Source§

impl CheckedBitPattern for ColorSpaceTag

Source§

type Bits = u8

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
Source§

fn is_valid_bit_pattern(bits: &u8) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl Clone for ColorSpaceTag

Source§

fn clone(&self) -> ColorSpaceTag

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 Contiguous for ColorSpaceTag

Source§

const MIN_VALUE: u8 = 0u8

The lower inclusive bound for valid instances of this type.
Source§

const MAX_VALUE: u8 = 15u8

The upper inclusive bound for valid instances of this type.
Source§

type Int = u8

The primitive integer type with an identical representation to this type. Read more
Source§

fn from_integer(value: Self::Int) -> Option<Self>

If value is within the range for valid instances of this type, returns Some(converted_value), otherwise, returns None. Read more
Source§

fn into_integer(self) -> Self::Int

Perform the conversion from C into the underlying integral type. This mostly exists otherwise generic code would need unsafe for the value as integer Read more
Source§

impl Debug for ColorSpaceTag

Source§

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

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

impl From<A98Rgb> for ColorSpaceTag

Source§

fn from(_: A98Rgb) -> Self

Converts to this type from the input type.
Source§

impl From<Aces2065_1> for ColorSpaceTag

Source§

fn from(_: Aces2065_1) -> Self

Converts to this type from the input type.
Source§

impl From<AcesCg> for ColorSpaceTag

Source§

fn from(_: AcesCg) -> Self

Converts to this type from the input type.
Source§

impl From<DisplayP3> for ColorSpaceTag

Source§

fn from(_: DisplayP3) -> Self

Converts to this type from the input type.
Source§

impl From<Hsl> for ColorSpaceTag

Source§

fn from(_: Hsl) -> Self

Converts to this type from the input type.
Source§

impl From<Hwb> for ColorSpaceTag

Source§

fn from(_: Hwb) -> Self

Converts to this type from the input type.
Source§

impl From<Lab> for ColorSpaceTag

Source§

fn from(_: Lab) -> Self

Converts to this type from the input type.
Source§

impl From<Lch> for ColorSpaceTag

Source§

fn from(_: Lch) -> Self

Converts to this type from the input type.
Source§

impl From<LinearSrgb> for ColorSpaceTag

Source§

fn from(_: LinearSrgb) -> Self

Converts to this type from the input type.
Source§

impl From<Oklab> for ColorSpaceTag

Source§

fn from(_: Oklab) -> Self

Converts to this type from the input type.
Source§

impl From<Oklch> for ColorSpaceTag

Source§

fn from(_: Oklch) -> Self

Converts to this type from the input type.
Source§

impl From<ProphotoRgb> for ColorSpaceTag

Source§

fn from(_: ProphotoRgb) -> Self

Converts to this type from the input type.
Source§

impl From<Rec2020> for ColorSpaceTag

Source§

fn from(_: Rec2020) -> Self

Converts to this type from the input type.
Source§

impl From<Srgb> for ColorSpaceTag

Source§

fn from(_: Srgb) -> Self

Converts to this type from the input type.
Source§

impl From<XyzD50> for ColorSpaceTag

Source§

fn from(_: XyzD50) -> Self

Converts to this type from the input type.
Source§

impl From<XyzD65> for ColorSpaceTag

Source§

fn from(_: XyzD65) -> Self

Converts to this type from the input type.
Source§

impl FromStr for ColorSpaceTag

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for ColorSpaceTag

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ColorSpaceTag

Source§

fn eq(&self, other: &ColorSpaceTag) -> 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 Zeroable for ColorSpaceTag

Source§

fn zeroed() -> Self

Source§

impl Copy for ColorSpaceTag

Source§

impl Eq for ColorSpaceTag

Source§

impl NoUninit for ColorSpaceTag

Source§

impl StructuralPartialEq for ColorSpaceTag

Auto Trait Implementations§

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.