Skip to main content

ColorSpace

Struct ColorSpace 

Source
pub struct ColorSpace {
    pub primaries: Primaries,
    pub transfer: Transfer,
    pub matrix: Matrix,
    pub range: Range,
}
Expand description

Everything needed to turn a frame’s samples into light, in one place.

Fields§

§primaries: Primaries

The chromaticities.

§transfer: Transfer

The transfer curve.

§matrix: Matrix

The luma coefficients.

§range: Range

Full or limited.

Implementations§

Source§

impl ColorSpace

Source

pub fn guess_for(width: u32, height: u32) -> Self

What a frame of this size is, when the file does not say.

Files with no colour metadata are common, and guessing by resolution is what every player does: SD was made on 601, HD on 709, UHD increasingly on 2020. It is a convention rather than a rule, so anything the container does state overrides this.

Source

pub fn srgb() -> Self

What a still image is: sRGB, full range, no chroma subsampling to undo.

Source

pub fn yuv_to_rgb(self, bit_depth: u32) -> [[f32; 4]; 3]

The YUV→RGB matrix for these settings, as three rows of [y, u, v, offset].

Feed it samples normalised by the maximum code value — code / 255 at 8 bits, code / 1023 at 10 — and it returns display RGB in 0.0..=1.0. The offset column absorbs both the limited-range pedestal and chroma’s neutral point, so a shader is one matrix * yuv + offset with no branches and no per-pixel arithmetic of its own.

bit_depth is needed even though the samples arrive normalised, because the neutral chroma code is 2^(n-1) against a maximum of 2^n - 1: 128/255 at 8 bits, 512/1023 at 10. Calling it exactly 0.5 is the approximation most shaders make, and it tints neutral greys by a fraction of a code value in the wrong direction. It costs nothing to be right.

Trait Implementations§

Source§

impl Clone for ColorSpace

Source§

fn clone(&self) -> Self

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 Copy for ColorSpace

Source§

impl Debug for ColorSpace

Source§

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

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

impl Default for ColorSpace

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ColorSpace

Source§

impl Hash for ColorSpace

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 ColorSpace

Source§

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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.