pub struct PixelComponentMapper { /* private fields */ }
Expand description

Mapper of pixel’s components.

This structure holds tables for mapping values of pixel’s components in forward and backward directions.

Supported all pixel types exclude I32 and F32.

Source and destination images may have different bit depth of one pixel component. But count of components must be equal. For example, you may convert U8x3 image with sRGB colorspace into U16x3 image with linear colorspace.

Alpha channel from such pixel types as U8x2, U8x4, U16x2 and U16x4 is not mapped with tables. This component is transformed into destination component type with help of IntoPixelComponent trait.

Implementations§

source§

impl PixelComponentMapper

source

pub fn new<FF, BF>(forward_map_func: FF, backward_map_func: BF) -> Self
where FF: Fn(f32) -> f32, BF: Fn(f32) -> f32,

Create an instance of the structure by filling its tables with given functions.

Each function takes one argument with the value of the pixel component converted into f32 in the range [0.0, 1.0]. The return value must also be f32 in the range [0.0, 1.0].

Example:

fn gamma_into_linear(input: f32) -> f32 {
    input.powf(2.2)
}

fn linear_into_gamma(input: f32) -> f32 {
    input.powf(1.0 / 2.2)
}

let gamma22_to_linear = PixelComponentMapper::new(
    gamma_into_linear,
    linear_into_gamma,
);
source

pub fn forward_map( &self, src_image: &DynamicImageView<'_>, dst_image: &mut DynamicImageViewMut<'_> ) -> Result<(), MappingError>

Mapping in the forward direction of pixel’s components of source image into corresponding components of destination image.

source

pub fn forward_map_inplace( &self, image: &mut DynamicImageViewMut<'_> ) -> Result<(), MappingError>

source

pub fn backward_map( &self, src_image: &DynamicImageView<'_>, dst_image: &mut DynamicImageViewMut<'_> ) -> Result<(), MappingError>

Mapping in the backward direction of pixel’s components of source image into corresponding components of destination image.

source

pub fn backward_map_inplace( &self, image: &mut DynamicImageViewMut<'_> ) -> Result<(), MappingError>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.