pub struct CicpTag { /* private fields */ }Expand description
Full re-export of zenpixels core types (zero module name collisions!).
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-byteCicptuple. - 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 isRGBorYCbr(ICCcicpTypeAmendment §4.1 & §4.3 Table 32). Bytes12..44encode eight signeds15Fixed16NumberCIE 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
impl CicpTag
Sourcepub const BASE_TAG_LEN: usize = 12
pub const BASE_TAG_LEN: usize = 12
Byte length of the base ICC.1:2022 §10.3 cicpType tag (12 bytes).
Sourcepub const EXTENDED_TAG_LEN: usize = 44
pub const EXTENDED_TAG_LEN: usize = 44
Byte length of the extended cicpType tag carrying eight s15Fixed16Number
custom chromaticities (12 + 32 = 44 bytes).
Sourcepub const fn from_cicp(cicp: Cicp) -> CicpTag
pub const fn from_cicp(cicp: Cicp) -> CicpTag
Construct a 12-byte base cicpType tag with no custom-primaries extension.
Sourcepub const fn with_custom_primaries(
primaries: CustomPrimaries,
transfer_characteristics: u8,
matrix_coefficients: u8,
full_range: bool,
) -> CicpTag
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).
Sourcepub const fn from_primaries_and_cicp(
primaries: Primaries,
transfer_characteristics: u8,
matrix_coefficients: u8,
full_range: bool,
) -> Option<CicpTag>
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.
Sourcepub fn from_color_space(
color: &ColorSpace,
) -> Result<CicpTag, CicpProjectionError>
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.
Sourcepub const fn cicp(self) -> Cicp
pub const fn cicp(self) -> Cicp
Underlying 4-byte H.273 Cicp tuple (color_primaries == 2 when extended).
Sourcepub const fn custom_primaries(self) -> Option<CustomPrimaries>
pub const fn custom_primaries(self) -> Option<CustomPrimaries>
Embedded custom primaries from bytes 12..44, if present.
Sourcepub const fn primaries(self) -> Option<Primaries>
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).
Sourcepub const fn effective_custom_primaries(self) -> Option<CustomPrimaries>
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.
Sourcepub const fn encoded_len(self) -> usize
pub const fn encoded_len(self) -> usize
Encoded ICC cicpType tag length in bytes: 12 (base) or 44 (extended).
Sourcepub fn to_color_space(
self,
alpha: AlphaMode,
) -> Result<ColorSpace, At<CicpError>>
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).
Sourcepub fn from_tag_bytes(tag_bytes: &[u8]) -> Result<CicpTag, At<CicpError>>
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 bytes4..8, orVideoFullRangeFlag > 1. - When
ColourPrimaries != 2, rejects declared lengths!= 12(§4.3 NOTE 1). - When
ColourPrimaries == 2andtag_bytes.len() == 12, returnscustom_primaries = None(§4.3 NOTE 2). - When
ColourPrimaries == 2andtag_bytes.len() > 12, requires at least 44 bytes and validates bytes12..44as eights15Fixed16Numberchromaticities.
Sourcepub const fn to_base_tag_bytes(self) -> [u8; 12]
pub const fn to_base_tag_bytes(self) -> [u8; 12]
Encode the 12-byte base cicpType header + 4-byte CICP payload.
Sourcepub const fn to_extended_tag_bytes(self) -> Option<[u8; 44]>
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.
Sourcepub fn write_tag_bytes(self, dst: &mut [u8]) -> Option<usize>
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()).
Sourcepub fn to_tag_bytes_vec(self) -> Vec<u8> ⓘ
pub fn to_tag_bytes_vec(self) -> Vec<u8> ⓘ
Encode the cicpType tag into an owned Vec<u8> (12 or 44 bytes).
Sourcepub fn from_icc(icc_bytes: &[u8]) -> Option<CicpTag>
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.