Skip to main content

ColorSpace

Enum ColorSpace 

Source
#[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
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.
§

Rgb

Standard tristimulus RGB color space (standardized 1-byte Primaries).

Fields

§primaries: Primaries

Chromaticity primaries.

§transfer: Transfer

Non-linear or linear transfer function.

§range: SignalRange

Full or narrow studio signal range.

§alpha: AlphaMode

Alpha or padding interpretation.

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

§transfer: Transfer

Non-linear or linear transfer function.

§range: SignalRange

Full or narrow studio signal range.

§alpha: AlphaMode

Alpha or padding interpretation.

§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

§transfer: Transfer

Transfer function.

§range: SignalRange

Full or narrow range.

§alpha: AlphaMode

Alpha interpretation (None, Opaque, Straight, Premultiplied).

§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: WhitePoint

Reference white point (e.g. WhitePoint::D65, WhitePoint::E, WhitePoint::D50).

§alpha: AlphaMode

Alpha interpretation (None, Opaque, Straight, Premultiplied).

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

Fields

§alpha: AlphaMode

Alpha interpretation (None, Opaque, Straight, Premultiplied).

§

Perceptual

Additional perceptual or cylindrical color space (Oklch, CieLab, Jzazbz, Hsl, Hsv, …).

Fields

§space: PerceptualSpace

Which perceptual/cylindrical model the channels represent.

§alpha: AlphaMode

Alpha interpretation.

§

Cmyk

Subtractive printer ink (CMYK) — requires an explicit CMS backend and ICC profile to convert to display color.

Fields

§inverted: bool

Whether ink polarity is inverted (max = no ink, Adobe JPEG/JXL convention).

§alpha: AlphaMode

Alpha interpretation (None for 4-channel CMYK).

§icc: Option<Arc<[u8]>>

Authoritative CMYK ICC profile bytes, if attached.

§

Icc

Arbitrary authoritative ICC profile — no conflicting CICP primaries/transfer alongside it.

Fields

§profile: Arc<[u8]>

Raw ICC profile bytes.

§color_channels: u8

Number of color channels excluding alpha/padding (e.g. 3 for RGB, 1 for Gray, 4 for CMYK).

§alpha: AlphaMode

Alpha interpretation.

§intent: RenderingIntent

Preferred rendering intent.

§

Untagged

Non-color numeric data (depth maps, normals, masks, generic signed/wide payloads).

Fields

§total_channels: u8

Total channel count including any alpha slot.

§alpha: AlphaMode

Alpha interpretation (None for pure numeric data).

Implementations§

Source§

impl ColorSpace

Source

pub const SRGB: ColorSpace

Standard full-range sRGB (opaque / no alpha).

Source

pub const SRGB_ALPHA: ColorSpace

Standard full-range sRGB with straight alpha.

Source

pub const LINEAR_SRGB: ColorSpace

Linear-light BT.709 / sRGB (no alpha).

Source

pub const LINEAR_SRGB_ALPHA: ColorSpace

Linear-light BT.709 / sRGB with straight alpha.

Source

pub const DISPLAY_P3: ColorSpace

Display P3 with sRGB transfer (no alpha).

Source

pub const DISPLAY_P3_ALPHA: ColorSpace

Display P3 with sRGB transfer and straight alpha.

Source

pub const BT2100_PQ: ColorSpace

BT.2100 PQ HDR (BT.2020 primaries, ST 2084 PQ, full range, no alpha).

Source

pub const BT2100_HLG_SCENE: ColorSpace

BT.2100 HLG HDR scene-referred (no display OOTF selected yet).

Source

pub const BT2100_HLG_1000: ColorSpace

BT.2100 HLG HDR with explicit 1000-nit reference display rendering.

Source

pub const GRAY_SRGB: ColorSpace

Grayscale with sRGB transfer (no alpha).

Source

pub const GRAY_LINEAR: ColorSpace

Linear grayscale (no alpha).

Source

pub const OKLAB: ColorSpace

Oklab perceptual space (CIE XYZ D65-anchored, no alpha).

Source

pub const OKLABA: ColorSpace

Oklab + straight alpha.

Source

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.

Source

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

Source

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.

Source

pub const fn alpha(&self) -> AlphaMode

Return the alpha mode of this color space.

Source

pub fn with_alpha(self, alpha: AlphaMode) -> ColorSpace

Return a copy with alpha replaced.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn primaries(&self) -> Option<Primaries>

Return standardized Primaries for Self::Rgb, or None for Self::RgbCustom and non-RGB models.

Source

pub fn custom_primaries(&self) -> Option<&CustomPrimaries>

Return custom primaries reference for Self::RgbCustom, or None otherwise.

Source

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.

Source

pub const fn is_rgb(&self) -> bool

Whether this color space is an RGB space (Rgb or RgbCustom).

Source

pub const fn transfer(&self) -> Option<Transfer>

Return the transfer function of an RGB (Rgb or RgbCustom) or Gray color space.

Source

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

Source

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

Linear-light luminance weights [Yr, Yg, Yb] for any known RGB space (Rgb or RgbCustom).

Source

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

Source

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

Source

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.

Source

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, .. }).

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub const fn is_hdr(&self) -> bool

Whether this color space is HDR (Pq or Hlg).

Trait Implementations§

Source§

impl Clone for ColorSpace

Source§

fn clone(&self) -> ColorSpace

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 ColorSpace

Source§

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

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

impl Eq for ColorSpace

Source§

impl Hash for ColorSpace

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 ColorSpace

Source§

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

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.