From 5c5015a10ebf0d46c93e560bb5407c2357d33504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20R=C3=B6nnkvist?= Date: Wed, 25 Mar 2020 15:57:10 +0100 Subject: [PATCH 1/3] Bindings for MagickLevelImage --- src/wand/magick.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index f710a07..25b579e 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -251,6 +251,20 @@ impl MagickWand { } } + pub fn level_image( + &self, + black_point: f64, + gamma: f64, + white_point: f64, + ) -> Result<(), &'static str> { + let result = + unsafe { bindings::MagickLevelImage(self.wand, black_point, gamma, white_point) }; + match result { + bindings::MagickBooleanType_MagickTrue => Ok(()), + _ => Err("failed to set size of wand"), + } + } + /// Extend the image as defined by the geometry, gravity, and wand background color. Set the /// (x,y) offset of the geometry to move the original wand relative to the extended wand. pub fn extend_image( From 36c145d4c48e3966f8c6f9272a9147e0c4c736e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20R=C3=B6nnkvist?= Date: Thu, 26 Mar 2020 10:13:54 +0100 Subject: [PATCH 2/3] fix: black and white point should be set relative to quantum range --- src/wand/magick.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 25b579e..8475bc5 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -257,8 +257,14 @@ impl MagickWand { gamma: f64, white_point: f64, ) -> Result<(), &'static str> { - let result = - unsafe { bindings::MagickLevelImage(self.wand, black_point, gamma, white_point) }; + let result = unsafe { + bindings::MagickLevelImage( + self.wand, + black_point * bindings::QuantumRange, + gamma, + white_point * bindings::QuantumRange, + ) + }; match result { bindings::MagickBooleanType_MagickTrue => Ok(()), _ => Err("failed to set size of wand"), From fa563b8fb611e1e9755b1a28f444bed00dca4744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20R=C3=B6nnkvist?= Date: Tue, 21 Apr 2020 09:09:59 +0200 Subject: [PATCH 3/3] docs: describe the quantomrange use in level_image --- src/wand/magick.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 8475bc5..c298824 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -251,6 +251,8 @@ impl MagickWand { } } + // Level an image. Black and white points are multiplied with QuantumRange to + // decrease dependencies on the end user. pub fn level_image( &self, black_point: f64,