Skip to main content

ConvertPolicy

Struct ConvertPolicy 

Source
#[non_exhaustive]
pub struct ConvertPolicy {
Show 16 fields pub depth: DepthPolicy, pub alpha: AlphaPolicy, pub gamut: GamutPolicy, pub range: RangePolicy, pub luma: LumaCoefficients, pub luma_domain: LumaDomain, pub diffuse_white: Option<DiffuseWhite>, pub sdr_peak: Nits, pub hlg_rendering: Option<HlgRendering>, pub tone_mapper: Option<Arc<dyn ToneMapper>>, pub cms: Option<Arc<dyn CmsBackend>>, pub accelerators: Option<Accelerators>, pub source_claims: SampleClaims, pub tone_map_hdr_to_sdr: bool, pub allow_icc_substitution: bool, pub allow_approximate: bool,
}
Expand description

Cohesive conversion policy controlling precision, alpha, gamut, signal range, HDR anchors, tone mapping, CMS fallback, and SIMD acceleration.

§Preset Defaults

Fieldlossless() / default()working_linear()permissive()display_sdr(white, peak)
depthForbidRoundRoundRound
alphaForbidDiscardIfOpaqueDiscardUncheckedCompositeOnto(BLACK)
gamutPreserveExtendedPreserveExtendedClipClip
rangeForbidConvertConvertConvert
diffuse_whiteNoneSome(BT2408)NoneSome(white)
hlg_renderingNoneNoneNoneSome(REFERENCE_1000_NIT)
tone_map_hdr_to_sdrfalsefalsefalsetrue
allow_icc_substitutionfalsetruetruetrue
allow_approximatefalsefalsefalsefalse

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§depth: DepthPolicy

Depth/quantization behavior.

§alpha: AlphaPolicy

Alpha removal / compositing behavior.

§gamut: GamutPolicy

Gamut narrowing / extended-range behavior.

§range: RangePolicy

Explicit Full ↔ Narrow range conversion policy.

§luma: LumaCoefficients

RGB → Gray luma weights.

§luma_domain: LumaDomain

Domain in which RGB → Gray weights are evaluated (Encoded Y’ default vs LinearLight Y).

§diffuse_white: Option<DiffuseWhite>

Relative-linear 1.0 diffuse white anchor (required when crossing PQ ↔ relative light unless carried on ColorSpace).

§sdr_peak: Nits

Target SDR peak luminance in cd/m² for HDR → SDR tone mapping (default 100.0 cd/m²).

§hlg_rendering: Option<HlgRendering>

Explicit HLG display rendering override when source/dest carries HlgMode::Scene.

§tone_mapper: Option<Arc<dyn ToneMapper>>

Optional custom HDR → SDR tone mapper (defaults to built-in Bt2446A when bt2446a feature is enabled).

§cms: Option<Arc<dyn CmsBackend>>

Optional CMS backend for arbitrary ColorSpace::Icc or ColorSpace::Cmyk transforms.

§accelerators: Option<Accelerators>

Optional hermetic accelerator table override (when None, consults the process registry / fast feature default).

§source_claims: SampleClaims

Caller-asserted source sample facts (merged with buffer facts in ImagePlan).

§tone_map_hdr_to_sdr: bool

Whether to apply tone mapping when converting HDR → SDR (true in display_sdr(), false in lossless()/working_linear()).

§allow_icc_substitution: bool

Whether recognized matrix+TRC ICC profiles may substitute directly into native math (for non-absolute intents) instead of requiring a CMS backend.

Default is true in permissive()/working_linear()/display_sdr(), and false in lossless().

§allow_approximate: bool

Whether opt-in fast fixed-point approximations (max error <= 1 LSB vs exact float, e.g. Q13/Q14 integer LUT U8 sRGB-matrix fast path) may be selected.

Default is false (exact 0-bit parity with the float strip pipeline).

Implementations§

Source§

impl ConvertPolicy

Source

pub fn lossless() -> Self

Strict lossless-permission policy: forbids depth reduction, alpha loss, gamut clipping, RGB→Gray chroma loss (unless proven grayscale), and range scaling.

Allows lossless widening (U8 → U16 → F32), channel reordering (RGB ↔ BGR), adding opaque alpha, and floating-point extended-gamut preservation. Note that lossless() describes loss-permission settings rather than mathematical invertibility of arbitrary floating-point color transforms.

Source

pub fn working_linear() -> Self

Linear-light working-space policy: preserves extended values, defaults diffuse white to ITU-R BT.2408 (203 cd/m², override via .with_diffuse_white(...)), and disables tone mapping.

Use ConvertPolicy::permissive or ConvertPolicy::lossless when unanchored PQ ↔ relative routes must fail with ConvertError::MissingHdrAnchor unless a diffuse white is explicitly provided.

Source

pub fn display_sdr(white: DiffuseWhite, sdr_peak: Nits) -> Self

Display-referred SDR output policy: enables HDR → SDR tone mapping, rounds depth, converts narrow range, and clips/compresses gamut.

Source

pub fn permissive() -> Self

Permissive general-purpose policy (rounds depth, clips gamut, converts narrow range, discards alpha unchecked unless configured).

Source

pub fn with_depth(self, depth: DepthPolicy) -> Self

Set depth reduction policy (Forbid, Round, Truncate, OrderedDither).

Source

pub fn with_alpha(self, alpha: AlphaPolicy) -> Self

Set alpha removal/compositing policy.

Source

pub fn with_gamut(self, gamut: GamutPolicy) -> Self

Set gamut narrowing / extended-range policy.

Source

pub fn with_range(self, range: RangePolicy) -> Self

Set explicit Full ↔ Narrow signal range conversion policy.

Source

pub fn with_luma(self, luma: LumaCoefficients) -> Self

Set RGB → Gray luminance weights.

Source

pub fn with_luma_domain(self, domain: LumaDomain) -> Self

Set RGB → Gray evaluation domain (LumaDomain::Encoded Y’ default vs LumaDomain::LinearLight Y).

Source

pub fn with_diffuse_white(self, white: DiffuseWhite) -> Self

Set relative-linear 1.0 diffuse white anchor (e.g. DiffuseWhite::BT2408 = 203 nits).

Source

pub fn with_sdr_peak(self, peak: Nits) -> Self

Set target SDR peak luminance in cd/m² for HDR → SDR tone mapping.

Source

pub fn with_hlg_rendering(self, rendering: HlgRendering) -> Self

Set explicit BT.2100-3 HLG display rendering conditions.

Source

pub fn with_tone_mapping(self, enable: bool) -> Self

Enable or disable HDR → SDR tone mapping.

Source

pub fn with_tone_mapper(self, mapper: Arc<dyn ToneMapper>) -> Self

Attach a custom ToneMapper and enable HDR → SDR tone mapping.

Source

pub fn with_cms(self, cms: Arc<dyn CmsBackend>) -> Self

Attach a CmsBackend for arbitrary ICC profiles and CMYK conversions.

Source

pub fn with_color_services(self, services: &ColorServices) -> Self

Apply a shared ColorServices bundle to this policy.

  • CmsChoice::Inherit: leaves cms and allow_icc_substitution unchanged.
  • CmsChoice::StrictNoIcc: clears cms and sets allow_icc_substitution = false, permitting validated same-profile ICC carriage and known-space math while refusing both CMS evaluation and inferred matrix+TRC ICC substitution.
  • CmsChoice::Use: installs the binding’s CmsBackend.
  • services.tone_mapper: attaches the tone mapper if present without altering tone_map_hdr_to_sdr.

Apply with_color_services last when composing a policy: subsequent calls to with_cms or with_icc_substitution overwrite the fields set here.

Source

pub fn with_accelerators(self, accel: Accelerators) -> Self

Override the SIMD accelerator table hermetically for plans built with this policy.

Source

pub fn with_source_claims(self, facts: SampleClaims) -> Self

Supply proven source SampleClaims for row-level plans without buffer headers (merged with runtime buffer facts in ImagePlan).

Source

pub fn with_icc_substitution(self, allow: bool) -> Self

Control whether recognized matrix+TRC ICC profiles may substitute into native math.

Source

pub fn with_approximate(self, allow: bool) -> Self

Control whether fast fixed-point approximations (max error <= 1 LSB vs exact float) may be used on supported U8 color-matrix routes (default false).

Trait Implementations§

Source§

impl Clone for ConvertPolicy

Source§

fn clone(&self) -> ConvertPolicy

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 ConvertPolicy

Source§

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

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

impl Default for ConvertPolicy

Source§

fn default() -> Self

Defaults to ConvertPolicy::lossless so callers never silently discard alpha, narrow bit depth, clip gamut, or rescale signal range without opting in.

Use ConvertPolicy::permissive, ConvertPolicy::working_linear, or ConvertPolicy::display_sdr when lossy conversion is desired.

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.