Add DitherMethod type
This commit is contained in:
@ -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;
|
||||
|
||||
22
src/types/dither_method.rs
Normal file
22
src/types/dither_method.rs
Normal 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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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")),
|
||||
|
||||
@ -292,7 +292,7 @@ fn test_color_reduction() {
|
||||
6,
|
||||
magick_rust::ColorspaceType::RGB,
|
||||
1,
|
||||
bindings::DitherMethod_UndefinedDitherMethod,
|
||||
magick_rust::DitherMethod::Undefined,
|
||||
false
|
||||
)
|
||||
.is_ok());
|
||||
|
||||
Reference in New Issue
Block a user