Skip to main content

Primaries

Enum Primaries 

Source
#[non_exhaustive]
pub enum Primaries {
Show 13 variants Bt709, Bt470M, Bt470Bg, Bt601, Smpte240M, GenericFilm, Bt2020, Xyz, DciP3, DisplayP3, Ebu3213, AdobeRgb, Unknown,
}
Expand description

Standardized 1-byte Copy + const chromaticity primaries (and reference white point) for tristimulus RGB color spaces.

Covers all 11 standardized ITU-T H.273 Table 2 ColourPrimaries codes losslessly (Primaries::from_cicp(cp)?.to_cicp() == Some(cp)), plus Adobe RGB (1998) and Unknown. Arbitrary custom chromaticities (PNG cHRM, OpenEXR, JXL custom primaries, ACES AP0/AP1) live in ColorSpace::RgbCustom via Arc<CustomPrimaries> so Primaries stays 1 byte, ColorSpace stays 32 B.

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

Bt709

ITU-R BT.709 / sRGB primaries, D65 white (CICP 1).

§

Bt470M

ITU-R BT.470-6 System M (NTSC 1953) primaries, Illuminant C white (0.310, 0.316) (CICP 4).

§

Bt470Bg

ITU-R BT.470-6 System B, G (PAL/SECAM) primaries, D65 white (CICP 5).

§

Bt601

ITU-R BT.601-7 525 / SMPTE 170M primaries, D65 white (CICP 6).

§

Smpte240M

SMPTE 240M primaries, D65 white (CICP 7; identical chromaticities to Self::Bt601, distinct code).

§

GenericFilm

Generic film (colour filters using Illuminant C), Illuminant C white (0.310, 0.316) (CICP 8).

§

Bt2020

ITU-R BT.2020 / BT.2100 wide-gamut primaries, D65 white (CICP 9).

§

Xyz

SMPTE ST 428-1 CIE 1931 XYZ primaries (R=(1,0), G=(0,1), B=(0,0)), Equal-Energy E white (CICP 10).

§

DciP3

SMPTE RP 431-2 DCI-P3 theater primaries, DCI white (0.314, 0.351) (CICP 11).

§

DisplayP3

Apple Display P3 / SMPTE EG 432-1 primaries, D65 white (CICP 12).

§

Ebu3213

EBU Tech. 3213-E / JEDEC P22 phosphors, D65 white (CICP 22).

§

AdobeRgb

Adobe RGB (1998) primaries, D65 white (no standard H.273 code).

§

Unknown

Unspecified / unknown primaries.

Implementations§

Source§

impl Primaries

Source

pub const WHITE_D65: (f32, f32)

CIE 1931 D65 white point (x, y).

Source

pub const WHITE_DCI: (f32, f32)

SMPTE RP 431-2 DCI theater white point (x, y).

Source

pub const WHITE_C: (f32, f32)

CIE Standard Illuminant C white point (x, y) (BT.470M / Generic Film).

Source

pub const WHITE_E: (f32, f32)

CIE Equal-Energy Illuminant E white point (x, y) (SMPTE ST 428-1 XYZ).

Source

pub const fn chromaticity(self) -> Option<((f32, f32), (f32, f32), (f32, f32))>

CIE 1931 (x, y) coordinates of (R, G, B) primaries, or None for Self::Unknown.

Source

pub const fn white_point(self) -> Option<(f32, f32)>

Reference white point (x, y) of these primaries, or None for Self::Unknown.

Source

pub const fn to_custom(self) -> Option<CustomPrimaries>

Convert any known Primaries variant (including named presets such as Self::AdobeRgb and Self::Bt709) into explicit CustomPrimaries, or None for Self::Unknown.

Source

pub const fn to_icc_d50_matrix_f64(self) -> Option<[[f64; 3]; 3]>

Derive the ICC PCS D50-adapted 3×3 primary matrix (M_D50 = M_adapt · M_native) per ICC.1 cicpType Amendment Annex 1 using Bradford adaptation to PCS D50 (0.9642, 1.0000, 0.8249) (ICC.1:2022 §7.2.16).

Columns 0, 1, 2 are the rXYZ, gXYZ, bXYZ matrix column tags.

Source

pub const fn same_chromaticity(self, other: Primaries) -> bool

Whether self and other have identical CIE 1931 primaries and white point (for example Self::Bt601 and Self::Smpte240M). Returns false if either side is Self::Unknown unless both are Unknown.

Source

pub const fn from_cicp(code: u8) -> Option<Primaries>

Map an ITU-T H.273 Table 2 ColourPrimaries code to Primaries.

Lossless across all 11 standardized codes (1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 22).

Source

pub const fn to_cicp(self) -> Option<u8>

Map Primaries to an ITU-T H.273 Table 2 ColourPrimaries code, when standardized.

Source

pub const fn try_luma_weights(self) -> Option<[f32; 3]>

Linear-light luminance weights [Yr, Yg, Yb] derived from the primaries’ RGB→XYZ Y row, or None for Self::Unknown (use Self::luma_weights only when a BT.709 fallback is intended).

Source

pub const fn luma_weights(self) -> [f32; 3]

Linear-light luminance weights [Yr, Yg, Yb] derived from the primaries’ RGB→XYZ Y row (falls back to BT.709 for Self::Unknown; prefer try_luma_weights when unknown primaries must be refused).

Source

pub const fn rgb_to_xyz_f64(self) -> Option<[[f64; 3]; 3]>

Linear RGB → CIE XYZ (Y_white = 1.0, relative to self.white_point()) 3×3 matrix in f64.

Source

pub const fn gamut_matrix_to(self, dst: Primaries) -> Option<[[f32; 3]; 3]>

Exact 3×3 linear-light gamut conversion matrix from self to dst, applying Bradford chromatic adaptation automatically when self.white_point() != dst.white_point().

Returns the identity matrix when self == dst (for known primaries), and None if either side is Self::Unknown.

Source

pub const fn xyz_to_rgb_f32( self, src_white: WhitePoint, ) -> Option<[[f32; 3]; 3]>

Bradford-adapted 3×3 matrix converting CIE XYZ (at src_white) → linear RGB in self.

Source

pub const fn rgb_to_xyz_f32( self, dst_white: WhitePoint, ) -> Option<[[f32; 3]; 3]>

Bradford-adapted 3×3 matrix converting linear RGB in self → CIE XYZ (at dst_white).

Trait Implementations§

Source§

impl Clone for Primaries

Source§

fn clone(&self) -> Primaries

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 Primaries

Source§

impl Debug for Primaries

Source§

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

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

impl Default for Primaries

Source§

fn default() -> Primaries

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

impl Eq for Primaries

Source§

impl Hash for Primaries

Source§

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

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 Primaries

Source§

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

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.