#[non_exhaustive]pub enum ColorSpace {
Rgb {
primaries: Primaries,
transfer: Transfer,
range: SignalRange,
alpha: AlphaMode,
diffuse_white: Option<DiffuseWhite>,
},
RgbCustom {
primaries: Arc<CustomPrimaries>,
transfer: Transfer,
range: SignalRange,
alpha: AlphaMode,
diffuse_white: Option<DiffuseWhite>,
},
Gray {
transfer: Transfer,
range: SignalRange,
alpha: AlphaMode,
diffuse_white: Option<DiffuseWhite>,
},
Xyz {
white_point: WhitePoint,
alpha: AlphaMode,
diffuse_white: Option<DiffuseWhite>,
},
Oklab {
alpha: AlphaMode,
},
Perceptual {
space: PerceptualSpace,
alpha: AlphaMode,
},
Cmyk {
inverted: bool,
alpha: AlphaMode,
icc: Option<Arc<[u8]>>,
},
Icc {
profile: Arc<[u8]>,
color_channels: u8,
alpha: AlphaMode,
intent: RenderingIntent,
},
Untagged {
total_channels: u8,
alpha: AlphaMode,
},
}Expand description
Full re-export of zenpixels core types (zero module name collisions!).
Authoritative color meaning of pixel samples — an algebraic enum with zero
contradictory or impossible combinations.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Rgb
Standard tristimulus RGB color space (standardized 1-byte Primaries).
Fields
range: SignalRangeFull or narrow studio signal range.
diffuse_white: Option<DiffuseWhite>Luminance of relative-linear 1.0 in cd/m² (required when crossing PQ ↔ relative light).
RgbCustom
Tristimulus RGB with validated custom CIE 1931 primaries + white point
(PNG cHRM, OpenEXR chromaticities, JXL custom primaries, ACES AP0/AP1, extended ICC cicp).
Stored behind Arc<CustomPrimaries> so ColorSpace stays 32 B and cloning is zero-allocation
while keeping standard Primaries a 1-byte Copy + const enum.
Fields
primaries: Arc<CustomPrimaries>Validated custom CIE 1931 primaries and white point.
range: SignalRangeFull or narrow studio signal range.
diffuse_white: Option<DiffuseWhite>Luminance of relative-linear 1.0 in cd/m² (required when crossing PQ ↔ relative light).
Gray
Achromatic single-channel luminance / luma.
Fields
range: SignalRangeFull or narrow range.
diffuse_white: Option<DiffuseWhite>Luminance of relative-linear 1.0 in cd/m².
Xyz
CIE 1931 linear XYZ tristimulus space (e.g. TIFF SGILog / LogLuv).
Fields
white_point: WhitePointReference white point (e.g. WhitePoint::D65, WhitePoint::E, WhitePoint::D50).
diffuse_white: Option<DiffuseWhite>Luminance of Y = 1.0 in cd/m², if known.
Oklab
Björn Ottosson’s Oklab — CIE XYZ D65-anchored (no primaries or transfer field!).
Perceptual
Additional perceptual or cylindrical color space (Oklch, CieLab, Jzazbz, Hsl, Hsv, …).
Fields
space: PerceptualSpaceWhich perceptual/cylindrical model the channels represent.
Cmyk
Subtractive printer ink (CMYK) — requires an explicit CMS backend and ICC profile to convert to display color.
Fields
Icc
Arbitrary authoritative ICC profile — no conflicting CICP primaries/transfer alongside it.
Fields
color_channels: u8Number of color channels excluding alpha/padding (e.g. 3 for RGB, 1 for Gray, 4 for CMYK).
intent: RenderingIntentPreferred rendering intent.
Untagged
Non-color numeric data (depth maps, normals, masks, generic signed/wide payloads).
Implementations§
Source§impl ColorSpace
impl ColorSpace
Sourcepub const SRGB: ColorSpace
pub const SRGB: ColorSpace
Standard full-range sRGB (opaque / no alpha).
Sourcepub const SRGB_ALPHA: ColorSpace
pub const SRGB_ALPHA: ColorSpace
Standard full-range sRGB with straight alpha.
Sourcepub const LINEAR_SRGB: ColorSpace
pub const LINEAR_SRGB: ColorSpace
Linear-light BT.709 / sRGB (no alpha).
Sourcepub const LINEAR_SRGB_ALPHA: ColorSpace
pub const LINEAR_SRGB_ALPHA: ColorSpace
Linear-light BT.709 / sRGB with straight alpha.
Sourcepub const DISPLAY_P3: ColorSpace
pub const DISPLAY_P3: ColorSpace
Display P3 with sRGB transfer (no alpha).
Sourcepub const DISPLAY_P3_ALPHA: ColorSpace
pub const DISPLAY_P3_ALPHA: ColorSpace
Display P3 with sRGB transfer and straight alpha.
Sourcepub const BT2100_PQ: ColorSpace
pub const BT2100_PQ: ColorSpace
BT.2100 PQ HDR (BT.2020 primaries, ST 2084 PQ, full range, no alpha).
Sourcepub const BT2100_HLG_SCENE: ColorSpace
pub const BT2100_HLG_SCENE: ColorSpace
BT.2100 HLG HDR scene-referred (no display OOTF selected yet).
Sourcepub const BT2100_HLG_1000: ColorSpace
pub const BT2100_HLG_1000: ColorSpace
BT.2100 HLG HDR with explicit 1000-nit reference display rendering.
Sourcepub const GRAY_SRGB: ColorSpace
pub const GRAY_SRGB: ColorSpace
Grayscale with sRGB transfer (no alpha).
Sourcepub const GRAY_LINEAR: ColorSpace
pub const GRAY_LINEAR: ColorSpace
Linear grayscale (no alpha).
Sourcepub const OKLAB: ColorSpace
pub const OKLAB: ColorSpace
Oklab perceptual space (CIE XYZ D65-anchored, no alpha).
Sourcepub const OKLABA: ColorSpace
pub const OKLABA: ColorSpace
Oklab + straight alpha.
Sourcepub fn rgb_custom(
primaries: CustomPrimaries,
transfer: Transfer,
range: SignalRange,
alpha: AlphaMode,
diffuse_white: Option<DiffuseWhite>,
) -> ColorSpace
pub fn rgb_custom( primaries: CustomPrimaries, transfer: Transfer, range: SignalRange, alpha: AlphaMode, diffuse_white: Option<DiffuseWhite>, ) -> ColorSpace
Construct an Self::RgbCustom color space from validated CustomPrimaries.
Sourcepub const fn rgb_custom_arc(
primaries: Arc<CustomPrimaries>,
transfer: Transfer,
range: SignalRange,
alpha: AlphaMode,
diffuse_white: Option<DiffuseWhite>,
) -> ColorSpace
pub const fn rgb_custom_arc( primaries: Arc<CustomPrimaries>, transfer: Transfer, range: SignalRange, alpha: AlphaMode, diffuse_white: Option<DiffuseWhite>, ) -> ColorSpace
Construct an Self::RgbCustom color space from an existing shared Arc<CustomPrimaries>.
Sourcepub fn from_icc(
profile: Arc<[u8]>,
alpha: AlphaMode,
intent: RenderingIntent,
) -> Result<ColorSpace, At<ColorError>>
pub fn from_icc( profile: Arc<[u8]>, alpha: AlphaMode, intent: RenderingIntent, ) -> Result<ColorSpace, At<ColorError>>
Construct an active image color space from a structurally valid ICC profile.
RGB, Gray, CMYK, Lab, XYZ and YCbCr channel counts come from the profile
header. The caller supplies alpha interpretation and rendering intent.
PixelFormat::new checks compatibility with the sample layout. For
CMYK, the layout’s channel order declares the ink polarity.
Use ColorOrigin::from_icc to retain raw profile bytes as metadata.
Sourcepub fn with_alpha(self, alpha: AlphaMode) -> ColorSpace
pub fn with_alpha(self, alpha: AlphaMode) -> ColorSpace
Return a copy with alpha replaced.
Sourcepub fn with_primaries(self, primaries: Primaries) -> ColorSpace
pub fn with_primaries(self, primaries: Primaries) -> ColorSpace
Set standardized primaries on an RGB color space (Rgb or RgbCustom, no-op on non-RGB variants).
Prefer try_with_primaries when applying to an unknown variant
should be detected rather than silently ignored.
Sourcepub fn try_with_primaries(self, primaries: Primaries) -> Option<ColorSpace>
pub fn try_with_primaries(self, primaries: Primaries) -> Option<ColorSpace>
Set standardized primaries on an RGB color space (Rgb or RgbCustom), returning None on non-RGB variants.
Sourcepub fn with_custom_primaries(self, primaries: CustomPrimaries) -> ColorSpace
pub fn with_custom_primaries(self, primaries: CustomPrimaries) -> ColorSpace
Set custom CIE 1931 primaries on an RGB color space (Rgb or RgbCustom, no-op on non-RGB variants).
Prefer try_with_custom_primaries when applying to a non-RGB
variant should be detected rather than silently ignored.
Sourcepub fn try_with_custom_primaries(
self,
primaries: CustomPrimaries,
) -> Option<ColorSpace>
pub fn try_with_custom_primaries( self, primaries: CustomPrimaries, ) -> Option<ColorSpace>
Set custom CIE 1931 primaries on an RGB color space (Rgb or RgbCustom), returning None on non-RGB variants.
Sourcepub const fn primaries(&self) -> Option<Primaries>
pub const fn primaries(&self) -> Option<Primaries>
Return standardized Primaries for Self::Rgb, or None for Self::RgbCustom and non-RGB models.
Sourcepub fn custom_primaries(&self) -> Option<&CustomPrimaries>
pub fn custom_primaries(&self) -> Option<&CustomPrimaries>
Return custom primaries reference for Self::RgbCustom, or None otherwise.
Sourcepub fn effective_custom_primaries(&self) -> Option<CustomPrimaries>
pub fn effective_custom_primaries(&self) -> Option<CustomPrimaries>
Return explicit CustomPrimaries for any known RGB space (Rgb or RgbCustom),
or None for Primaries::Unknown and non-RGB models.
Sourcepub const fn is_rgb(&self) -> bool
pub const fn is_rgb(&self) -> bool
Whether this color space is an RGB space (Rgb or RgbCustom).
Sourcepub const fn transfer(&self) -> Option<Transfer>
pub const fn transfer(&self) -> Option<Transfer>
Return the transfer function of an RGB (Rgb or RgbCustom) or Gray color space.
Sourcepub fn rgb_to_xyz_f64(&self) -> Option<[[f64; 3]; 3]>
pub fn rgb_to_xyz_f64(&self) -> Option<[[f64; 3]; 3]>
Linear RGB → CIE XYZ (Y_white = 1.0) 3×3 matrix for any known RGB space (Rgb or RgbCustom).
Sourcepub fn try_luma_weights(&self) -> Option<[f32; 3]>
pub fn try_luma_weights(&self) -> Option<[f32; 3]>
Linear-light luminance weights [Yr, Yg, Yb] for any known RGB space (Rgb or RgbCustom).
Sourcepub fn rgb_to_xyz_f32(&self, dst_white: WhitePoint) -> Option<[[f32; 3]; 3]>
pub fn rgb_to_xyz_f32(&self, dst_white: WhitePoint) -> Option<[[f32; 3]; 3]>
Bradford-adapted 3×3 matrix converting linear RGB in self (Rgb or RgbCustom) → CIE XYZ (at dst_white).
Sourcepub fn xyz_to_rgb_f32(&self, src_white: WhitePoint) -> Option<[[f32; 3]; 3]>
pub 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 (Rgb or RgbCustom).
Sourcepub fn gamut_matrix_to(&self, dst: &ColorSpace) -> Option<[[f32; 3]; 3]>
pub fn gamut_matrix_to(&self, dst: &ColorSpace) -> Option<[[f32; 3]; 3]>
Exact 3×3 linear-light gamut conversion matrix between any two RGB color spaces
(Rgb or RgbCustom), with automatic Bradford chromatic adaptation across white points.
Sourcepub fn same_rgb_chromaticity(&self, other: &ColorSpace) -> bool
pub fn same_rgb_chromaticity(&self, other: &ColorSpace) -> bool
Whether two RGB color spaces (Rgb or RgbCustom) share identical CIE 1931 primaries
and white point (including when both are Rgb { primaries: Primaries::Unknown, .. }).
Sourcepub fn with_transfer(self, transfer: Transfer) -> ColorSpace
pub fn with_transfer(self, transfer: Transfer) -> ColorSpace
Set transfer on an RGB (Rgb or RgbCustom) or Gray color space (no-op on other variants).
Prefer try_with_transfer when applying to an incompatible
variant should be detected rather than silently ignored.
Sourcepub fn try_with_transfer(self, transfer: Transfer) -> Option<ColorSpace>
pub fn try_with_transfer(self, transfer: Transfer) -> Option<ColorSpace>
Set transfer on an RGB (Rgb or RgbCustom) or Gray color space, returning None on other variants.
Sourcepub const fn range(&self) -> Option<SignalRange>
pub const fn range(&self) -> Option<SignalRange>
Return the signal range of an RGB (Rgb or RgbCustom) or Gray color space (None for non-range-bearing models).
Sourcepub fn with_range(self, range: SignalRange) -> ColorSpace
pub fn with_range(self, range: SignalRange) -> ColorSpace
Set signal range on an RGB (Rgb or RgbCustom) or Gray color space (no-op on other variants).
Prefer try_with_range when applying to an incompatible variant
should be detected rather than silently ignored.
Sourcepub fn try_with_range(self, range: SignalRange) -> Option<ColorSpace>
pub fn try_with_range(self, range: SignalRange) -> Option<ColorSpace>
Set signal range on an RGB (Rgb or RgbCustom) or Gray color space, returning None on other variants.
Sourcepub fn with_diffuse_white(self, diffuse_white: DiffuseWhite) -> ColorSpace
pub fn with_diffuse_white(self, diffuse_white: DiffuseWhite) -> ColorSpace
Attach a DiffuseWhite luminance anchor to an RGB (Rgb or RgbCustom), Gray, or Xyz space
(no-op on other variants).
Prefer try_with_diffuse_white when applying to an incompatible variant
should be detected rather than silently ignored.
Sourcepub fn try_with_diffuse_white(
self,
diffuse_white: DiffuseWhite,
) -> Option<ColorSpace>
pub fn try_with_diffuse_white( self, diffuse_white: DiffuseWhite, ) -> Option<ColorSpace>
Attach a DiffuseWhite luminance anchor to an RGB (Rgb or RgbCustom), Gray, or Xyz
color space, returning None on other variants.
Sourcepub const fn diffuse_white(&self) -> Option<DiffuseWhite>
pub const fn diffuse_white(&self) -> Option<DiffuseWhite>
Return the optional luminance anchor for relative-linear 1.0 (XYZ Y = 1.0).
The anchor scales relative values in luminance conversions, including
values above 1.0. PQ signal values carry their own absolute scale.
Display-rendered HLG uses the peak in its rendering conditions.
Sourcepub fn to_cicp_lossy(&self) -> Option<Cicp>
pub fn to_cicp_lossy(&self) -> Option<Cicp>
Lossily project this color space to a raw ITU-T H.273 RGB Cicp syntax tuple when possible.
Silently drops any explicit DiffuseWhite anchor and collapses HlgMode::Display
rendering parameters into scene-referred (9, 18, 0, true). When lossless round-trip
fidelity of display rendering parameters and diffuse white is required, use
project_cicp.
Sourcepub fn project_cicp(&self) -> Result<Cicp, CicpProjectionError>
pub fn project_cicp(&self) -> Result<Cicp, CicpProjectionError>
Losslessly project this color space to an ITU-T H.273 Cicp tuple, refusing when
CICP cannot represent semantics carried on self (such as HlgMode::Display rendering
parameters, custom primaries, or an explicit DiffuseWhite anchor).
Sourcepub fn project_cicp_tag(&self) -> Result<CicpTag, CicpProjectionError>
pub fn project_cicp_tag(&self) -> Result<CicpTag, CicpProjectionError>
Losslessly project this color space to an ICC.1 cicpType tag (CicpTag),
emitting the 12-byte base form for standardized H.273 primaries or the 44-byte
custom-primaries extension (ICC cicpType Amendment, 2026-10-19) for
Primaries::AdobeRgb and Self::RgbCustom.
Trait Implementations§
Source§impl Clone for ColorSpace
impl Clone for ColorSpace
Source§fn clone(&self) -> ColorSpace
fn clone(&self) -> ColorSpace
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more