Add DitherMethod type

This commit is contained in:
5ohue
2024-05-09 21:42:51 +03:00
parent e419039647
commit cfbdbd4c0e
5 changed files with 31 additions and 6 deletions

View File

@ -36,7 +36,7 @@ use libc::size_t;
#[cfg(not(target_os = "freebsd"))] #[cfg(not(target_os = "freebsd"))]
use libc::ssize_t; use libc::ssize_t;
pub use bindings::{DitherMethod, FilterType, GravityType}; pub use bindings::{FilterType, GravityType};
pub use conversions::ToMagick; pub use conversions::ToMagick;
pub use result::MagickError; pub use result::MagickError;
use result::Result; use result::Result;

View File

@ -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<DitherMethod> for bindings::DitherMethod {
fn from(value: DitherMethod) -> Self {
return value as bindings::DitherMethod;
}
}

View File

@ -1,9 +1,11 @@
mod colorspace_type; mod colorspace_type;
mod composite_operator; mod composite_operator;
mod dither_method;
mod metric_type; mod metric_type;
mod resource_type; mod resource_type;
pub use self::colorspace_type::ColorspaceType; pub use self::colorspace_type::ColorspaceType;
pub use self::composite_operator::CompositeOperator; pub use self::composite_operator::CompositeOperator;
pub use self::dither_method::DitherMethod;
pub use self::metric_type::MetricType; pub use self::metric_type::MetricType;
pub use self::resource_type::ResourceType; pub use self::resource_type::ResourceType;

View File

@ -32,6 +32,7 @@ use super::{DrawingWand, PixelWand};
use crate::{ use crate::{
ColorspaceType, ColorspaceType,
CompositeOperator, CompositeOperator,
DitherMethod,
MetricType, MetricType,
ResourceType ResourceType
}; };
@ -1106,14 +1107,14 @@ impl MagickWand {
number_of_colors: size_t, number_of_colors: size_t,
colorspace: ColorspaceType, colorspace: ColorspaceType,
tree_depth: size_t, tree_depth: size_t,
dither_method: bindings::DitherMethod, dither_method: DitherMethod,
measure_error: bool) -> Result<()> { measure_error: bool) -> Result<()> {
match unsafe { bindings::MagickQuantizeImage( match unsafe { bindings::MagickQuantizeImage(
self.wand, self.wand,
number_of_colors, number_of_colors,
colorspace.into(), colorspace.into(),
tree_depth, tree_depth,
dither_method, dither_method.into(),
measure_error.to_magick()) } { measure_error.to_magick()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), bindings::MagickBooleanType_MagickTrue => Ok(()),
_ => Err(MagickError("failed to quantize image")), _ => Err(MagickError("failed to quantize image")),
@ -1126,14 +1127,14 @@ impl MagickWand {
number_of_colors: size_t, number_of_colors: size_t,
colorspace: ColorspaceType, colorspace: ColorspaceType,
tree_depth: size_t, tree_depth: size_t,
dither_method: bindings::DitherMethod, dither_method: DitherMethod,
measure_error: bool) -> Result<()> { measure_error: bool) -> Result<()> {
match unsafe { bindings::MagickQuantizeImages( match unsafe { bindings::MagickQuantizeImages(
self.wand, self.wand,
number_of_colors, number_of_colors,
colorspace.into(), colorspace.into(),
tree_depth, tree_depth,
dither_method, dither_method.into(),
measure_error.to_magick()) } { measure_error.to_magick()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), bindings::MagickBooleanType_MagickTrue => Ok(()),
_ => Err(MagickError("failed to quantize images")), _ => Err(MagickError("failed to quantize images")),

View File

@ -292,7 +292,7 @@ fn test_color_reduction() {
6, 6,
magick_rust::ColorspaceType::RGB, magick_rust::ColorspaceType::RGB,
1, 1,
bindings::DitherMethod_UndefinedDitherMethod, magick_rust::DitherMethod::Undefined,
false false
) )
.is_ok()); .is_ok());