pub struct ConvertPolicy { /* private fields */ }Expand description
The lossy decisions a conversion is permitted to make, plus the parameters those decisions need.
Plain Copy data whose fields are reached through accessors, so it stays mechanically portable
to C. Build one by starting from ConvertPolicy::lossless or ConvertPolicy::permissive
and overriding what you need; every with_* setter and every getter is const.
use gamut_core::convert::{AlphaPolicy, ConvertPolicy, LumaPolicy};
let policy = ConvertPolicy::lossless()
.with_alpha(AlphaPolicy::CompositeOver)
.with_background([u16::MAX; 3]) // composite over white
.with_luma(LumaPolicy::Bt709);Implementations§
Source§impl ConvertPolicy
impl ConvertPolicy
Sourcepub const fn lossless() -> Self
pub const fn lossless() -> Self
Permits no loss at all: every narrowing conversion is refused.
The default, and what every gamut decoder uses unless the caller says otherwise, so a typed decode never quietly discards part of the file.
Sourcepub const fn permissive() -> Self
pub const fn permissive() -> Self
Permits every loss this module can express, with conventional defaults.
Alpha is dropped, samples rescale to the target width, and colour reduces to luma with
LumaPolicy::Bt709. Suited to an application that just wants pixels in a fixed layout —
gamut-cli uses this. Prefer naming the individual policies when the choice matters.
Sourcepub const fn with_alpha(self, policy: AlphaPolicy) -> Self
pub const fn with_alpha(self, policy: AlphaPolicy) -> Self
Sets how an alpha channel the target cannot hold is handled.
Sourcepub const fn with_depth(self, policy: DepthPolicy) -> Self
pub const fn with_depth(self, policy: DepthPolicy) -> Self
Sets how samples narrower than the source’s are produced.
Sourcepub const fn with_luma(self, policy: LumaPolicy) -> Self
pub const fn with_luma(self, policy: LumaPolicy) -> Self
Sets which luma coefficients reduce colour to grey.
Sourcepub const fn with_background(self, rgb: [u16; 3]) -> Self
pub const fn with_background(self, rgb: [u16; 3]) -> Self
Sets the background colour AlphaPolicy::CompositeOver composites against.
Full-range RGB regardless of the layouts involved, so one value reads the same for 8- and
16-bit targets: [0; 3] is black (the default) and [u16::MAX; 3] is white.
Sourcepub const fn with_threshold(self, threshold: u16) -> Self
pub const fn with_threshold(self, threshold: u16) -> Self
Sets the full-range luma at or above which a bilevel target records white.
Defaults to half of full scale.
Sourcepub const fn alpha(self) -> AlphaPolicy
pub const fn alpha(self) -> AlphaPolicy
How an alpha channel the target cannot hold is handled.
Sourcepub const fn depth(self) -> DepthPolicy
pub const fn depth(self) -> DepthPolicy
How samples narrower than the source’s are produced.
Sourcepub const fn luma(self) -> LumaPolicy
pub const fn luma(self) -> LumaPolicy
Which luma coefficients reduce colour to grey.
A decoder that must choose what to ask its backend for — rather than converting after the fact — reads this to decide whether a colour-to-grey request is worth attempting at all.
Sourcepub const fn background(self) -> [u16; 3]
pub const fn background(self) -> [u16; 3]
The full-range background colour AlphaPolicy::CompositeOver composites against.