From 7adf1981f42c3eb1dd8694f1dade20ff606f1b82 Mon Sep 17 00:00:00 2001 From: yoghurt Date: Wed, 17 Apr 2024 23:34:10 +0200 Subject: [PATCH] Added MagickNormalizeImage and MagickOrderedDitherImage --- src/wand/magick.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 2a4f4a4..476f0d1 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -386,6 +386,43 @@ impl MagickWand { } } + //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( + &self, + ) -> Result<()> { + let result = unsafe { + bindings::MagickNormalizeImage( + self.wand, + ) + }; + match result { + bindings::MagickBooleanType_MagickTrue => Ok(()), + _ => Err(MagickError("Failed to apply contrast stretch to image")), + } + } + + //MagickOrderedDitherImage performs an ordered dither based on a number of pre-defined + //dithering threshold maps, but over multiple intensity levels, which can be different for + //different channels, according to the input arguments. + pub fn ordered_dither_image( + &self, + threshold_map: &str, + ) -> Result<()> { + let c_threshold_map = CString::new(threshold_map).unwrap(); + + let result = unsafe { + bindings::MagickOrderedDitherImage( + self.wand, + c_threshold_map.as_ptr(), + ) + }; + match result { + bindings::MagickBooleanType_MagickTrue => Ok(()), + _ => Err(MagickError("Failed to apply ordered dither to image")), + } + } + /// Apply sigmoidal contrast to the image /// Midpoint is a number in range [0, 1] pub fn sigmoidal_contrast_image(