Struct quantette::ImagePipeline
source · pub struct ImagePipeline<'a> { /* private fields */ }Expand description
A builder struct to specify options to create a quantized image or an indexed palette from an image.
§Examples
To start, create a ImagePipeline from a RgbImage (note that the image feature is needed):
let img = image::open("some image")?.into_rgb8();
let pipeline = ImagePipeline::try_from(&img)?;Then, you can change different options like the number of colors in the palette:
let pipeline = pipeline
.palette_size(192)
.colorspace(ColorSpace::Oklab)
.quantize_method(QuantizeMethod::kmeans());ImagePipeline has all options that PalettePipeline does,
so you can check its documentation example for more information.
In addition, ImagePipeline has options to control the dither behavior:
let pipeline = pipeline
.palette_size(192)
.colorspace(ColorSpace::Oklab)
.quantize_method(QuantizeMethod::kmeans())
.dither_error_diffusion(0.8);Finally, run the pipeline:
let image = pipeline.quantized_rgbimage();Or, in parallel across multiple threads (needs the threads feature):
let image = pipeline.quantized_rgbimage_par();Implementations§
source§impl<'a> ImagePipeline<'a>
impl<'a> ImagePipeline<'a>
sourcepub fn new(
colors: ColorSlice<'a, Srgb<u8>>,
width: u32,
height: u32
) -> Option<Self>
pub fn new( colors: ColorSlice<'a, Srgb<u8>>, width: u32, height: u32 ) -> Option<Self>
Creates a new ImagePipeline with default options.
Returns None if the length of colors is not equal to width * height.
sourcepub fn palette_size(self, size: impl Into<PaletteSize>) -> Self
pub fn palette_size(self, size: impl Into<PaletteSize>) -> Self
Sets the palette size which determines the (maximum) number of colors to have in the palette.
The default palette size is PaletteSize::MAX.
sourcepub fn colorspace(self, colorspace: ColorSpace) -> Self
pub fn colorspace(self, colorspace: ColorSpace) -> Self
Sets the color space to perform color quantization in.
See ColorSpace for more details.
The default color space is ColorSpace::Srgb.
sourcepub fn quantize_method(
self,
quantize_method: impl Into<QuantizeMethod<Srgb<u8>>>
) -> Self
pub fn quantize_method( self, quantize_method: impl Into<QuantizeMethod<Srgb<u8>>> ) -> Self
Sets the color quantization method to use.
See QuantizeMethod for more details.
The default quantization method is QuantizeMethod::Wu.
sourcepub fn dedup_pixels(self, dedup_pixels: bool) -> Self
pub fn dedup_pixels(self, dedup_pixels: bool) -> Self
Sets whether or not to deduplicate pixels in the image.
It is recommended to keep this option as default, unless the image is very small or
you have reason to believe that the image contains very little redundancy
(i.e., most pixels are their own unique color).
quantette will only deduplicate pixels if it is worth doing so
(i.e., the k-means quantization method is chosen or a color space converision is needed).
The default value is true.
sourcepub fn dither(self, dither: bool) -> Self
pub fn dither(self, dither: bool) -> Self
Sets whether or not to apply dithering to the image.
The current implementation uses Floyd–Steinberg dithering.
The dithering strength/aggresiveness can be controlled via
ImagePipeline::dither_error_diffusion.
The default value is true.
sourcepub fn dither_error_diffusion(self, diffusion: f32) -> Self
pub fn dither_error_diffusion(self, diffusion: f32) -> Self
Sets the error diffusion factor for the dither.
A value of 1.0 diffuses all error to the neighboring pixels and may result in color bleed.
Values less than 1.0 only diffuse part of the error for a more tamed dither.
The given diffusion should be in the range 0.0..=1.0,
otherwise the default error diffusion will be used as a fallback.
The default value is FloydSteinberg::DEFAULT_ERROR_DIFFUSION.
source§impl<'a> ImagePipeline<'a>
impl<'a> ImagePipeline<'a>
source§impl<'a> ImagePipeline<'a>
impl<'a> ImagePipeline<'a>
sourcepub fn quantized_rgbimage(self) -> RgbImage
pub fn quantized_rgbimage(self) -> RgbImage
Runs the pipeline and returns the quantized image.
source§impl<'a> ImagePipeline<'a>
impl<'a> ImagePipeline<'a>
source§impl<'a> ImagePipeline<'a>
impl<'a> ImagePipeline<'a>
sourcepub fn quantized_rgbimage_par(self) -> RgbImage
pub fn quantized_rgbimage_par(self) -> RgbImage
Runs the pipeline in parallel and returns the quantized image.
Trait Implementations§
source§impl<'a> Clone for ImagePipeline<'a>
impl<'a> Clone for ImagePipeline<'a>
source§fn clone(&self) -> ImagePipeline<'a>
fn clone(&self) -> ImagePipeline<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a> Debug for ImagePipeline<'a>
impl<'a> Debug for ImagePipeline<'a>
source§impl<'a> From<ImagePipeline<'a>> for PalettePipeline<'a>
impl<'a> From<ImagePipeline<'a>> for PalettePipeline<'a>
source§fn from(pipeline: ImagePipeline<'a>) -> Self
fn from(pipeline: ImagePipeline<'a>) -> Self
Auto Trait Implementations§
impl<'a> Freeze for ImagePipeline<'a>
impl<'a> RefUnwindSafe for ImagePipeline<'a>
impl<'a> Send for ImagePipeline<'a>
impl<'a> Sync for ImagePipeline<'a>
impl<'a> Unpin for ImagePipeline<'a>
impl<'a> UnwindSafe for ImagePipeline<'a>
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
source§fn into_color(self) -> U
fn into_color(self) -> U
source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more