diff --git a/src/lib.rs b/src/lib.rs index 35bda30..3c97af8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ use libc::size_t; #[cfg(not(target_os = "freebsd"))] use libc::ssize_t; -pub use bindings::{DitherMethod, FilterType, GravityType}; +pub use bindings::{FilterType, GravityType}; pub use conversions::ToMagick; pub use result::MagickError; use result::Result; diff --git a/src/types/dither_method.rs b/src/types/dither_method.rs new file mode 100644 index 0000000..0c822a7 --- /dev/null +++ b/src/types/dither_method.rs @@ -0,0 +1,22 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum DitherMethod { + Undefined = bindings::DitherMethod_UndefinedDitherMethod, + No = bindings::DitherMethod_NoDitherMethod, + Riemersma = bindings::DitherMethod_RiemersmaDitherMethod, + FloydSteinberg = bindings::DitherMethod_FloydSteinbergDitherMethod, +} + +impl Default for DitherMethod { + fn default() -> Self { + return DitherMethod::No; + } +} + +impl From for bindings::DitherMethod { + fn from(value: DitherMethod) -> Self { + return value as bindings::DitherMethod; + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index ce1fe30..e62676a 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,9 +1,11 @@ mod colorspace_type; mod composite_operator; +mod dither_method; mod metric_type; mod resource_type; pub use self::colorspace_type::ColorspaceType; pub use self::composite_operator::CompositeOperator; +pub use self::dither_method::DitherMethod; pub use self::metric_type::MetricType; pub use self::resource_type::ResourceType; diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 8f8533a..6348e1a 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -32,6 +32,7 @@ use super::{DrawingWand, PixelWand}; use crate::{ ColorspaceType, CompositeOperator, + DitherMethod, MetricType, ResourceType }; @@ -1106,14 +1107,14 @@ impl MagickWand { number_of_colors: size_t, colorspace: ColorspaceType, tree_depth: size_t, - dither_method: bindings::DitherMethod, + dither_method: DitherMethod, measure_error: bool) -> Result<()> { match unsafe { bindings::MagickQuantizeImage( self.wand, number_of_colors, colorspace.into(), tree_depth, - dither_method, + dither_method.into(), measure_error.to_magick()) } { bindings::MagickBooleanType_MagickTrue => Ok(()), _ => Err(MagickError("failed to quantize image")), @@ -1126,14 +1127,14 @@ impl MagickWand { number_of_colors: size_t, colorspace: ColorspaceType, tree_depth: size_t, - dither_method: bindings::DitherMethod, + dither_method: DitherMethod, measure_error: bool) -> Result<()> { match unsafe { bindings::MagickQuantizeImages( self.wand, number_of_colors, colorspace.into(), tree_depth, - dither_method, + dither_method.into(), measure_error.to_magick()) } { bindings::MagickBooleanType_MagickTrue => Ok(()), _ => Err(MagickError("failed to quantize images")), diff --git a/tests/lib.rs b/tests/lib.rs index 4c3824e..e13fb08 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -292,7 +292,7 @@ fn test_color_reduction() { 6, magick_rust::ColorspaceType::RGB, 1, - bindings::DitherMethod_UndefinedDitherMethod, + magick_rust::DitherMethod::Undefined, false ) .is_ok());