From e31675e47758bc79347d801eab636252215fb02e Mon Sep 17 00:00:00 2001 From: 5ohue <86558263+5ohue@users.noreply.github.com> Date: Sun, 12 May 2024 20:32:05 +0300 Subject: [PATCH] Add `levelize_image` function --- src/wand/magick.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index d3a1fdd..27674ca 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -383,6 +383,26 @@ impl MagickWand { } } + /// Applies the reversed [level_image](Self::level_image). It compresses the full range of color values, so + /// that they lie between the given black and white points. Gamma is applied before the values + /// are mapped. It can be used to de-contrast a greyscale image to the exact levels specified. + pub fn levelize_image(&self, black_point: f64, gamma: f64, white_point: f64) -> Result<()> { + let quantum_range = self.quantum_range()?; + + let result = unsafe { + bindings::MagickLevelizeImage( + self.wand, + black_point * quantum_range, + gamma, + white_point * quantum_range, + ) + }; + match result { + MagickTrue => Ok(()), + _ => Err(MagickError("Failed to level the image")), + } + } + //MagickNormalizeImage enhances the contrast of a color image by adjusting the pixels color //to span the entire range of colors available pub fn normalize_image(