Skip to main content

ColorPrimaries

Enum ColorPrimaries 

Source
#[non_exhaustive]
pub enum ColorPrimaries { Bt709, Unspecified, Bt470M, Bt470Bg, Smpte170M, Smpte240M, Film, Bt2020, SmpteSt428, SmpteRp431, SmpteEg432, Ebu3213E, }
Expand description

Color primaries per ITU-T H.273 ColourPrimaries (Table 2) / ISO/IEC 23001-8.

Read from AVFrame.color_primaries / VideoColorSpace.primaries / kCVImageBufferColorPrimariesKey.

Self::to_u32 / Self::from_u32 use the FFmpeg AVColorPrimaries code points (ITU-T H.273 ColourPrimaries); FFmpeg is the source of truth (the downstream consumer reads these via a buffa extern_path). Default is Self::Unspecified (FFmpeg AVCOL_PRI_UNSPECIFIED, code 2); [Self::Other] carries any name this build does not enumerate, so the text round-trip is lossless.

Tier. [Self::Other] needs a heap, so it exists only at the alloc / std tier; at the no-alloc tier this vocabulary is closed and an unrecognised slug is rejected rather than collapsed onto a named variant — an error beats a wrong value.

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 (HDTV).

§

Unspecified

Unspecified — caller infers from height.

§

Bt470M

ITU-R BT.470 System M (legacy NTSC).

§

Bt470Bg

ITU-R BT.470 System BG (PAL/SECAM).

§

Smpte170M

SMPTE 170M (NTSC SD; same primaries as BT.601).

§

Smpte240M

SMPTE 240M (legacy 1990s HDTV).

§

Film

Generic film (ITU-T H.273).

§

Bt2020

ITU-R BT.2020 (UHDTV / HDR10).

§

SmpteSt428

SMPTE ST 428-1 (XYZ).

§

SmpteRp431

SMPTE RP 431-2 (DCI-P3).

§

SmpteEg432

SMPTE EG 432-1 (Display P3).

§

Ebu3213E

EBU Tech. 3213-E (legacy) / JEDEC P22.

Implementations§

Source§

impl Primaries

Source

pub const fn is_bt_709(&self) -> bool

Returns true if this value is of type Bt709. Returns false otherwise

Source

pub const fn is_unspecified(&self) -> bool

Returns true if this value is of type Unspecified. Returns false otherwise

Source

pub const fn is_bt_470_m(&self) -> bool

Returns true if this value is of type Bt470M. Returns false otherwise

Source

pub const fn is_bt_470_bg(&self) -> bool

Returns true if this value is of type Bt470Bg. Returns false otherwise

Source

pub const fn is_smpte_170_m(&self) -> bool

Returns true if this value is of type Smpte170M. Returns false otherwise

Source

pub const fn is_smpte_240_m(&self) -> bool

Returns true if this value is of type Smpte240M. Returns false otherwise

Source

pub const fn is_film(&self) -> bool

Returns true if this value is of type Film. Returns false otherwise

Source

pub const fn is_bt_2020(&self) -> bool

Returns true if this value is of type Bt2020. Returns false otherwise

Source

pub const fn is_smpte_st_428(&self) -> bool

Returns true if this value is of type SmpteSt428. Returns false otherwise

Source

pub const fn is_smpte_rp_431(&self) -> bool

Returns true if this value is of type SmpteRp431. Returns false otherwise

Source

pub const fn is_smpte_eg_432(&self) -> bool

Returns true if this value is of type SmpteEg432. Returns false otherwise

Source

pub const fn is_ebu_3213_e(&self) -> bool

Returns true if this value is of type Ebu3213E. Returns false otherwise

Source§

impl Primaries

Source

pub fn as_str(&self) -> &str

Lowercase FFmpeg-style identifier for this variant (AVCOL_PRI_* slug).

Source

pub const fn to_u32(&self) -> Option<u32>

The FFmpeg AVColorPrimaries code point (ITU-T H.273 ColourPrimaries).

None for [Self::Other]: it names something FFmpeg has no code for, and inventing one would lose the name.

Source

pub const fn from_u32(v: u32) -> Option<Primaries>

Decodes from the FFmpeg AVColorPrimaries code produced by Self::to_u32.

None for a code this build names nothing for — a number is FFmpeg’s spelling, not a name to preserve.

Source

pub const fn chromaticities(&self) -> Option<[ChromaCoord; 3]>

CIE 1931 xy chromaticities of the R, G, B primaries (index 0 = red, 1 = green, 2 = blue, matching FFmpeg’s display_primaries layout) defined by this colour-primaries standard, per ITU-T H.273 ColourPrimaries / FFmpeg av_csp_primaries_desc (libavutil/csp.c).

Coordinates are in ChromaCoord’s SMPTE ST 2086 fixed-point units (0.00002 increments; floating value = raw / 50000.0), so BT.709 red (0.640, 0.330) is (32000, 16500).

Returns None for Self::Unspecified and [Self::Other], which carry no defined primaries.

Self::SmpteSt428 reports FFmpeg’s tabulated D-Cinema primaries (white point E), not the CIE XYZ identity that ITU-T H.273 Table 2 lists for ST 428-1 — FFmpeg’s av_csp_primaries_desc is the authority here.

Source

pub const fn white_point(&self) -> Option<ChromaCoord>

CIE 1931 xy reference white point defined by this colour-primaries standard, per ITU-T H.273 / FFmpeg av_csp_primaries_desc (libavutil/csp.c).

Most standards use D65 (0.3127, 0.3290); the exceptions are Self::Bt470M / Self::Film (CIE C), Self::SmpteRp431 (DCI white (0.314, 0.351)), and Self::SmpteSt428 (equal-energy E (1/3, 1/3)). Coordinates use the same ChromaCoord ST 2086 units as Self::chromaticities.

Returns None for Self::Unspecified and [Self::Other].

Source

pub const fn is_cie_xyz(&self) -> bool

Whether these primaries encode color directly in CIE 1931 XYZ rather than an RGB gamut — i.e. the channels are X, Y, Z.

True only for Self::SmpteSt428 (SMPTE ST 428-1, Digital Cinema), whose colorimetric primaries are the XYZ axes — chromaticities (1, 0), (0, 1), (0, 0) — not a set of physical RGB primaries.

This is the colorimetric interpretation, distinct from what Self::chromaticities returns: that method reports FFmpeg’s tabulated D-Cinema RGB primaries for SmpteSt428 (mirroring av_csp_primaries_desc, the authority for that method), whereas a consumer deriving an XYZ↔RGB relationship should treat ST 428-1 as the XYZ identity. Use this predicate to branch on that distinction (e.g. skip building an RGB-primaries-derived matrix for XYZ data).

Source§

impl Primaries

Source

pub const ROSTER: &'static [Primaries]

Every set of colour primaries this vocabulary names, in declaration order.

A slice rather than an array: how many names this build carries is a fact about the release, not part of the type, so a later addition stays a minor change.

The open escape arm is not a member. The roster answers “which names does this build know”, and the escape is precisely the arm that carries a name it does not — listing it would need a slug to put in it, and there isn’t one.

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 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<'de> Deserialize<'de> for Primaries

Source§

fn deserialize<D>(de: D) -> Result<Primaries, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Primaries

Source§

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

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

impl Eq for Primaries

Source§

impl FromStr for Primaries

Source§

type Err = ParsePrimariesError

See the alloc-tier arm above.

Source§

fn from_str(s: &str) -> Result<Primaries, <Primaries as FromStr>::Err>

Reads a primaries name: the canonical slug Self::as_str renders, or FFmpeg’s spelling of the same code point where the two differ.

Emission is injective and canonical — never a synonym — so parse(display(x)) == x holds for every named variant. Parse also takes av_color_primaries_name’s unknown (Self::Unspecified); every other name in that table already matches this vocabulary.

§Errors

Returns ParsePrimariesError only at the no-alloc tier, where the vocabulary is closed. At the alloc / std tier this parse is total — a slug this type does not name rides [Self::Other], carrying the caller’s spelling verbatim — and Self::Err is Infallible there, so the totality is checkable by the compiler rather than only promised here.

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 Serialize for Primaries

Source§

fn serialize<S>( &self, ser: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. 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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.