#[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
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
impl Primaries
Sourcepub const fn is_bt_709(&self) -> bool
pub const fn is_bt_709(&self) -> bool
Returns true if this value is of type Bt709. Returns false otherwise
Sourcepub const fn is_unspecified(&self) -> bool
pub const fn is_unspecified(&self) -> bool
Returns true if this value is of type Unspecified. Returns false otherwise
Sourcepub const fn is_bt_470_m(&self) -> bool
pub const fn is_bt_470_m(&self) -> bool
Returns true if this value is of type Bt470M. Returns false otherwise
Sourcepub const fn is_bt_470_bg(&self) -> bool
pub const fn is_bt_470_bg(&self) -> bool
Returns true if this value is of type Bt470Bg. Returns false otherwise
Sourcepub const fn is_smpte_170_m(&self) -> bool
pub const fn is_smpte_170_m(&self) -> bool
Returns true if this value is of type Smpte170M. Returns false otherwise
Sourcepub const fn is_smpte_240_m(&self) -> bool
pub const fn is_smpte_240_m(&self) -> bool
Returns true if this value is of type Smpte240M. Returns false otherwise
Sourcepub const fn is_film(&self) -> bool
pub const fn is_film(&self) -> bool
Returns true if this value is of type Film. Returns false otherwise
Sourcepub const fn is_bt_2020(&self) -> bool
pub const fn is_bt_2020(&self) -> bool
Returns true if this value is of type Bt2020. Returns false otherwise
Sourcepub const fn is_smpte_st_428(&self) -> bool
pub const fn is_smpte_st_428(&self) -> bool
Returns true if this value is of type SmpteSt428. Returns false otherwise
Sourcepub const fn is_smpte_rp_431(&self) -> bool
pub const fn is_smpte_rp_431(&self) -> bool
Returns true if this value is of type SmpteRp431. Returns false otherwise
Sourcepub const fn is_smpte_eg_432(&self) -> bool
pub const fn is_smpte_eg_432(&self) -> bool
Returns true if this value is of type SmpteEg432. Returns false otherwise
Sourcepub const fn is_ebu_3213_e(&self) -> bool
pub const fn is_ebu_3213_e(&self) -> bool
Returns true if this value is of type Ebu3213E. Returns false otherwise
Source§impl Primaries
impl Primaries
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Lowercase FFmpeg-style identifier for this variant
(AVCOL_PRI_* slug).
Sourcepub const fn to_u32(&self) -> Option<u32>
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.
Sourcepub const fn from_u32(v: u32) -> Option<Primaries>
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.
Sourcepub const fn chromaticities(&self) -> Option<[ChromaCoord; 3]>
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.
Sourcepub const fn white_point(&self) -> Option<ChromaCoord>
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].
Sourcepub const fn is_cie_xyz(&self) -> bool
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
impl Primaries
Sourcepub const ROSTER: &'static [Primaries]
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<'de> Deserialize<'de> for Primaries
impl<'de> Deserialize<'de> for Primaries
Source§fn deserialize<D>(de: D) -> Result<Primaries, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(de: D) -> Result<Primaries, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for Primaries
Source§impl FromStr for Primaries
impl FromStr for Primaries
Source§type Err = ParsePrimariesError
type Err = ParsePrimariesError
See the alloc-tier arm above.
Source§fn from_str(s: &str) -> Result<Primaries, <Primaries as FromStr>::Err>
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.