From 043616a87a5fec40e1987a14564209dc9e3f3b6c Mon Sep 17 00:00:00 2001 From: 5ohue <86558263+5ohue@users.noreply.github.com> Date: Sat, 11 May 2024 23:33:57 +0300 Subject: [PATCH] Add `AutoThresholdMethod` type --- src/types/auto_threshold_method.rs | 22 ++++++++++++++++++++++ src/types/mod.rs | 2 ++ src/wand/magick.rs | 5 +++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/types/auto_threshold_method.rs diff --git a/src/types/auto_threshold_method.rs b/src/types/auto_threshold_method.rs new file mode 100644 index 0000000..3bb7e7a --- /dev/null +++ b/src/types/auto_threshold_method.rs @@ -0,0 +1,22 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum AutoThresholdMethod { + Undefined = bindings::AutoThresholdMethod_UndefinedThresholdMethod, + Kapur = bindings::AutoThresholdMethod_KapurThresholdMethod, + OTSU = bindings::AutoThresholdMethod_OTSUThresholdMethod, + Triangle = bindings::AutoThresholdMethod_TriangleThresholdMethod, +} + +impl Default for AutoThresholdMethod { + fn default() -> Self { + return AutoThresholdMethod::Undefined; + } +} + +impl From for bindings::AutoThresholdMethod { + fn from(value: AutoThresholdMethod) -> Self { + return value as bindings::AutoThresholdMethod; + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 496bcef..6a847c8 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,5 +1,6 @@ mod align_type; mod alpha_channel_option; +mod auto_threshold_method; mod clip_path_units; mod colorspace_type; mod composite_operator; @@ -29,6 +30,7 @@ mod style_type; pub use self::align_type::AlignType; pub use self::alpha_channel_option::AlphaChannelOption; +pub use self::auto_threshold_method::AutoThresholdMethod; pub use self::clip_path_units::ClipPathUnits; pub use self::colorspace_type::ColorspaceType; pub use self::composite_operator::CompositeOperator; diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 085a8d9..2649e83 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -32,6 +32,7 @@ use super::{MagickTrue, MagickFalse}; use super::{DrawingWand, PixelWand}; use crate::{ AlphaChannelOption, + AutoThresholdMethod, ColorspaceType, CompositeOperator, CompressionType, @@ -1286,8 +1287,8 @@ impl MagickWand { /// down to a binary black & white image. Included algorithms are /// Kapur, Otsu, and Triangle methods. /// See for more information. - pub fn auto_threshold(&self, method: bindings::AutoThresholdMethod) -> Result<()> { - match unsafe { bindings::MagickAutoThresholdImage(self.wand, method) } { + pub fn auto_threshold(&self, method: AutoThresholdMethod) -> Result<()> { + match unsafe { bindings::MagickAutoThresholdImage(self.wand, method.into()) } { MagickTrue => Ok(()), _ => Err(MagickError("unable to auto threshold image")), }