Skip to main content

CicpTag

Struct CicpTag 

Source
pub struct CicpTag { /* private fields */ }
Expand description

ICC.1:2022 §10.3 cicpType tag payload, including the ICC custom-primaries amendment (approved 2026-10-19).

  • Base 12-byte form: 'cicp' + 4 zero reserved bytes + 4-byte Cicp tuple.
  • Extended 44-byte form: valid only when cicp.color_primaries == 2 (Unspecified) in an ICC v4+ Input (scnr), Display (mntr), or ColorSpace (spac) profile whose header data colour space is RGB or YCbr (ICC cicpType Amendment §4.1 & §4.3 Table 32). Bytes 12..44 encode eight signed s15Fixed16Number CIE 1931 (x, y) coordinates [xR, yR, xG, yG, xB, yB, xw, yw], supporting negative chromaticities such as ACES AP0 (y_B = -0.0770).

The invariant custom_primaries.is_some() => cicp.color_primaries == 2 is enforced by construction.

§s15Fixed16Number wire quantization

Encoding the 44-byte extended form quantizes each CIE 1931 (x, y) coordinate to signed s15Fixed16Number (1 / 65536 ≈ 1.53e-5), so a decimal f32 preset such as 0.7347 decodes back as 48149 / 65536 ≈ 0.73469543. Wire bytes and CustomPrimaries::to_s15fixed16 round-trip bit-exact; compare those (or a 1 / 65536 tolerance) rather than raw decimal f32 presets after serialization.

Implementations§

Source§

impl CicpTag

Source

pub const BASE_TAG_LEN: usize = 12

Byte length of the base ICC.1:2022 §10.3 cicpType tag (12 bytes).

Source

pub const EXTENDED_TAG_LEN: usize = 44

Byte length of the extended cicpType tag carrying eight s15Fixed16Number custom chromaticities (12 + 32 = 44 bytes).

Source

pub const fn from_cicp(cicp: Cicp) -> CicpTag

Construct a 12-byte base cicpType tag with no custom-primaries extension.

Source

pub const fn with_custom_primaries( primaries: CustomPrimaries, transfer_characteristics: u8, matrix_coefficients: u8, full_range: bool, ) -> CicpTag

Construct a 44-byte extended cicpType tag (ColourPrimaries = 2 + custom CIE 1931 primaries and white point).

Source

pub const fn from_primaries_and_cicp( primaries: Primaries, transfer_characteristics: u8, matrix_coefficients: u8, full_range: bool, ) -> Option<CicpTag>

Construct a cicpType tag from any known standardized Primaries (emitting the 12-byte form when standardized in H.273 Table 2, or the 44-byte custom-primaries form for Primaries::AdobeRgb).

Returns None for Primaries::Unknown. For arbitrary CustomPrimaries, use Self::with_custom_primaries.

Source

pub fn from_color_space( color: &ColorSpace, ) -> Result<CicpTag, CicpProjectionError>

Losslessly project an RGB ColorSpace (Rgb or RgbCustom) to an ICC cicpType tag, using the 12-byte enumerated form when standardized or the 44-byte custom-primaries form for Primaries::AdobeRgb and ColorSpace::RgbCustom.

Refuses HlgMode::Display, explicit DiffuseWhite, non-RGB color spaces, Primaries::Unknown, and non-H.273 transfers.

Source

pub const fn cicp(self) -> Cicp

Underlying 4-byte H.273 Cicp tuple (color_primaries == 2 when extended).

Source

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

Embedded custom primaries from bytes 12..44, if present.

Source

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

Standardized Primaries from the H.273 ColourPrimaries code when no custom-primaries extension is present (None when extended with custom primaries or unmapped).

Source

pub const fn effective_custom_primaries(self) -> Option<CustomPrimaries>

Resolved explicit CustomPrimaries: returns the embedded 32-byte extension directly when present, or converts standardized H.273 primaries via Primaries::to_custom.

Source

pub const fn encoded_len(self) -> usize

Encoded ICC cicpType tag length in bytes: 12 (base) or 44 (extended).

Source

pub fn to_color_space( self, alpha: AlphaMode, ) -> Result<ColorSpace, At<CicpError>>

Project an Identity-matrix (MC == 0) cicpType tag into ColorSpace::Rgb or ColorSpace::RgbCustom (when the 32-byte custom-primaries extension is present).

Source

pub fn from_tag_bytes(tag_bytes: &[u8]) -> Result<CicpTag, At<CicpError>>

Strictly decode raw ICC cicpType tag bytes (12-byte base or 44-byte extended) per ICC.1:2022 §10.3 and the 2026-10-19 custom-primaries amendment.

  • Rejects lengths < 12, wrong 'cicp' signature, non-zero reserved bytes 4..8, or VideoFullRangeFlag > 1.
  • When ColourPrimaries != 2, rejects declared lengths != 12 (§4.3 NOTE 1).
  • When ColourPrimaries == 2 and tag_bytes.len() == 12, returns custom_primaries = None (§4.3 NOTE 2).
  • When ColourPrimaries == 2 and tag_bytes.len() > 12, requires at least 44 bytes and validates bytes 12..44 as eight s15Fixed16Number chromaticities.
Source

pub const fn to_base_tag_bytes(self) -> [u8; 12]

Encode the 12-byte base cicpType header + 4-byte CICP payload.

Source

pub const fn to_extended_tag_bytes(self) -> Option<[u8; 44]>

Encode the full 44-byte extended cicpType payload when custom_primaries is present, or None for 12-byte base tags.

Source

pub fn write_tag_bytes(self, dst: &mut [u8]) -> Option<usize>

Write the encoded cicpType tag (12 or 44 bytes) into dst without allocating, returning the number of bytes written (None if dst.len() < self.encoded_len()).

Source

pub fn to_tag_bytes_vec(self) -> Vec<u8> ⓘ

Encode the cicpType tag into an owned Vec<u8> (12 or 44 bytes).

Source

pub fn from_icc(icc_bytes: &[u8]) -> Option<CicpTag>

Extract the cicp tag from an ICC v4+ profile (Input scnr, Display mntr, or ColorSpace spac), parsing the optional 32-byte custom-primaries extension when ColourPrimaries == 2, declared tag length is >= 44, and the profile’s header data colour space is RGB or YCbr (ICC cicpType Amendment §4.1 & §4.3).

When the profile header’s data colour space is XYZ (or non-RGB/YCbCr), the custom-primaries extension does not apply (§4.1 NOTE) and custom_primaries() is None.

Trait Implementations§

Source§

impl Clone for CicpTag

Source§

fn clone(&self) -> CicpTag

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 Copy for CicpTag

Source§

impl Debug for CicpTag

Source§

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

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

impl Display for CicpTag

Source§

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

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

impl Eq for CicpTag

Source§

impl From<Cicp> for CicpTag

Source§

fn from(cicp: Cicp) -> CicpTag

Converts to this type from the input type.
Source§

impl Hash for CicpTag

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 CicpTag

Source§

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

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