Struct fast_image_resize::PixelComponentMapper
source · 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
impl PixelComponentMapper
sourcepub fn new<FF, BF>(forward_map_func: FF, backward_map_func: BF) -> Self
pub fn new<FF, BF>(forward_map_func: FF, backward_map_func: BF) -> Self
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,
);
sourcepub fn forward_map(
&self,
src_image: &DynamicImageView<'_>,
dst_image: &mut DynamicImageViewMut<'_>
) -> Result<(), MappingError>
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.
pub fn forward_map_inplace( &self, image: &mut DynamicImageViewMut<'_> ) -> Result<(), MappingError>
sourcepub fn backward_map(
&self,
src_image: &DynamicImageView<'_>,
dst_image: &mut DynamicImageViewMut<'_>
) -> Result<(), MappingError>
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.