Skip to main content

Color

Enum Color 

Source
#[non_exhaustive]
pub enum Color { Rgb { primary: Primaries, transfer: Transfer, whitepoint: Whitepoint, luminance: Luminance, }, Luma { transfer: Transfer, whitepoint: Whitepoint, luminance: Luminance, }, Yuv { primary: Primaries, whitepoint: Whitepoint, transfer: Transfer, luminance: Luminance, differencing: Differencing, }, Oklab, Scalars { transfer: Transfer, }, SrLab2 { whitepoint: Whitepoint, }, }
Expand description

Identifies a color representation.

This names the model by which the numbers in the channels relate to a physical model. How exactly depends on the variant as presented below. Some of them can be customized further with parameters.

Notably, there are NOT the numbers which we will use in image operations. Generally, we will use an associated linear representation of those colors instead. The choice here depends on the color and is documented for each variants. It is chosen to provide models for faithful linear operations on these colors such as mixing etc.

TODO: colors describe paths to linear display, so we should somehow implement direction conversions such as “BT.2087 : Colour conversion from Recommendation ITU-R BT.709 to Recommendation ITU-R BT.2020” in a separate manner.

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

Rgb

An rgb-ish, additive model based on the CIE 1931 XYZ observers.

The linear representation is the screen space linear RGB, which depends on primaries, whitepoint and reference luminance. It is derived from the encoded form through the transfer function.

Fields

§primary: Primaries
§transfer: Transfer
§whitepoint: Whitepoint
§luminance: Luminance
§

Luma

A pure lightness color based on linear stimulus interpolation.

This is a Yuv without reference to any particular differencing scheme for the two chroma channels.

Fields

§transfer: Transfer
§whitepoint: Whitepoint
§luminance: Luminance
§

Yuv

A lightness, chroma difference scheme.

For the L component, this is equivalent to either a Luma or LumaDigital model depending on the Differencing scheme used.

This library does not reliably implement all conversion optimizations that are possible. Please refer to test and benchmark coverage.

Fields

§primary: Primaries
§whitepoint: Whitepoint
§transfer: Transfer
§luminance: Luminance
§differencing: Differencing
§

Oklab

The simple but perceptual space Oklab by Björn Ottoson.

The linear representation of this color is Lab but its quantized components are may be either Lab or LCh.

It’s based on a combination of two linear transforms and one non-linear power-function between them. Coefficients of these transforms are based on optimization against matching pairs in the detailed CAM16 model, trying to predict the parameters in those pairs as precisely as possible. For details see the post’s derivation.

Reference: https://bottosson.github.io/posts/oklab/

§

Scalars

A group of scalar values, with no assigned relation to physical quantities.

The purpose of this color is to simplify the process of creating color ramps and sampling functions, which do not have any interpretation themselves but are just coefficients to be used somewhere else.

The only SampleParts that are allowed to be paired with this are XYZ.

Additionally, you might use the images created with this color as an input or an intermediate step of a transmute to create images with chosen values in the linear representation without the need to manually calculate their texel encoding.

Fields

§transfer: Transfer

The transfer to use for points, as if they are RGB-ish colors. You can simply use Linear if you do not want to encode and rgb texel.

§

SrLab2

A LAB space based on contemporary perceptual understanding.

The newly defined SRLAB2 color model is a compromise between the simplicity of CIELAB and the correctness of CIECAM02.

By combining whitepoint adaption in the (more) precise model of CIECAM02 while performing the transfer function in the cone response space, this achieves a good uniformity by simply modelling the human perception properly. It just leaves out the surround luminance model in the vastly more complex CIECAM02.

This is lacking for HDR. This is because its based on L*ab which is inherently optimized for the small gamut of SDR. It’s not constant luminance at exceedingly bright colors where ICtCp might provide a better estimate (compare ΔEITP, ITU-R Rec. BT.2124).

Reference: https://www.magnetkern.de/srlab2.html

Fields

§whitepoint: Whitepoint

Implementations§

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Eq for Color

Source§

impl Hash for Color

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 Color

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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<P, L> PlaneOf<&L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&L) -> Option<<P as PlaneOf<&L>>::Plane>

Get the layout describing the plane.
Source§

impl<P, L> PlaneOf<&mut L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&mut L) -> Option<<P as PlaneOf<&mut L>>::Plane>

Get the layout describing the plane.
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.