Skip to main content

ConvertPolicy

Struct ConvertPolicy 

Source
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

Source

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.

Source

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.

Source

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

Sets how an alpha channel the target cannot hold is handled.

Source

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

Sets how samples narrower than the source’s are produced.

Source

pub const fn with_luma(self, policy: LumaPolicy) -> Self

Sets which luma coefficients reduce colour to grey.

Source

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.

Source

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.

Source

pub const fn alpha(self) -> AlphaPolicy

How an alpha channel the target cannot hold is handled.

Source

pub const fn depth(self) -> DepthPolicy

How samples narrower than the source’s are produced.

Source

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.

Source

pub const fn background(self) -> [u16; 3]

The full-range background colour AlphaPolicy::CompositeOver composites against.

Source

pub const fn threshold(self) -> u16

The full-range luma at or above which a bilevel target records white.

Trait Implementations§

Source§

impl Clone for ConvertPolicy

Source§

fn clone(&self) -> Self

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 ConvertPolicy

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

Returns the “default value” for a type. Read more
Source§

impl Eq for ConvertPolicy

Source§

impl Hash for ConvertPolicy

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

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 ConvertPolicy

Source§

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

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

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.