#[non_exhaustive]#[repr(u8)]pub enum ColorPrimaries {
Bt709 = 1,
Bt2020 = 9,
DisplayP3 = 12,
AdobeRgb = 13,
Unknown = 255,
}Expand description
Color primaries (CIE xy chromaticities of R, G, B) and white point.
Each variant is a complete “named recipe” — primaries and white point
are an inseparable pair (following CICP convention). Use
from_cicp() / to_cicp() for
CICP mapping. Discriminant values are internal.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Bt709 = 1
BT.709 / sRGB (CICP 1). White point: D65.
Bt2020 = 9
BT.2020 / BT.2100 (CICP 9). Wide gamut for HDR. White point: D65.
DisplayP3 = 12
Display P3 (CICP 12, SMPTE EG 432-1). Apple ecosystem. Same RGB primaries as DCI-P3, white point: D65.
AdobeRgb = 13
Adobe RGB (1998). Wide gamut. White point: D65.
Unknown = 255
Primaries not known.
Implementations§
Source§impl ColorPrimaries
impl ColorPrimaries
Sourcepub const fn chromaticity(self) -> Option<((f32, f32), (f32, f32), (f32, f32))>
pub const fn chromaticity(self) -> Option<((f32, f32), (f32, f32), (f32, f32))>
CIE 1931 xy chromaticity coordinates of the RGB primaries.
Returns ((rx, ry), (gx, gy), (bx, by)) or None for Unknown.
These are the canonical coordinates from the relevant standards
(ITU-R BT.709, BT.2020, SMPTE EG 432-1, etc.).
Sourcepub const fn from_cicp(code: u8) -> Option<ColorPrimaries>
pub const fn from_cicp(code: u8) -> Option<ColorPrimaries>
Map a CICP color_primaries code to a ColorPrimaries.
Sourcepub const fn white_point(self) -> (f32, f32)
pub const fn white_point(self) -> (f32, f32)
CIE 1931 xy chromaticity of this color space’s white point.
Sourcepub const fn gamut_matrix_to(self, dst: ColorPrimaries) -> Option<[[f32; 3]; 3]>
pub const fn gamut_matrix_to(self, dst: ColorPrimaries) -> Option<[[f32; 3]; 3]>
Compute the 3×3 linear RGB gamut conversion matrix from self to dst.
Bradford chromatic adaptation is applied automatically when white points
differ (e.g., DCI-P3 D50 → sRGB D65). Returns None for Unknown
primaries. Identity conversions (same primaries) return the identity matrix.
The matrix operates in linear light — apply EOTF before, OETF after.
let m = ColorPrimaries::DisplayP3.gamut_matrix_to(ColorPrimaries::Bt709).unwrap();
// White maps to white
let r = m[0][0] + m[0][1] + m[0][2];
assert!((r - 1.0).abs() < 1e-4);Sourcepub const fn contains(self, other: ColorPrimaries) -> bool
pub const fn contains(self, other: ColorPrimaries) -> bool
Whether self fully contains the gamut of other.
Returns false when white points differ (cross-adapted containment
is not defined without a chromatic adaptation transform).
D65 hierarchy: BT.2020 > Display P3 > Adobe RGB ≈ BT.709.
Trait Implementations§
Source§impl Clone for ColorPrimaries
impl Clone for ColorPrimaries
Source§fn clone(&self) -> ColorPrimaries
fn clone(&self) -> ColorPrimaries
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ColorPrimariesExt for ColorPrimaries
impl ColorPrimariesExt for ColorPrimaries
Source§fn to_xyz_matrix(&self) -> Option<&'static GamutMatrix>
fn to_xyz_matrix(&self) -> Option<&'static GamutMatrix>
Source§fn from_xyz_matrix(&self) -> Option<&'static GamutMatrix>
fn from_xyz_matrix(&self) -> Option<&'static GamutMatrix>
impl Copy for ColorPrimaries
Source§impl Debug for ColorPrimaries
impl Debug for ColorPrimaries
Source§impl Default for ColorPrimaries
impl Default for ColorPrimaries
Source§fn default() -> ColorPrimaries
fn default() -> ColorPrimaries
Source§impl Display for ColorPrimaries
impl Display for ColorPrimaries
impl Eq for ColorPrimaries
Source§impl Hash for ColorPrimaries
impl Hash for ColorPrimaries
Source§impl PartialEq for ColorPrimaries
impl PartialEq for ColorPrimaries
Source§fn eq(&self, other: &ColorPrimaries) -> bool
fn eq(&self, other: &ColorPrimaries) -> bool
self and other values to be equal, and is used by ==.