Add MetricType type
This commit is contained in:
@ -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::{ColorspaceType, DitherMethod, FilterType, GravityType, MetricType};
|
pub use bindings::{ColorspaceType, DitherMethod, FilterType, GravityType};
|
||||||
pub use conversions::ToMagick;
|
pub use conversions::ToMagick;
|
||||||
pub use result::MagickError;
|
pub use result::MagickError;
|
||||||
use result::Result;
|
use result::Result;
|
||||||
|
|||||||
29
src/types/metric_type.rs
Normal file
29
src/types/metric_type.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use crate::bindings;
|
||||||
|
|
||||||
|
pub enum MetricType {
|
||||||
|
Undefined = bindings::MetricType_UndefinedErrorMetric as isize,
|
||||||
|
Absolute = bindings::MetricType_AbsoluteErrorMetric as isize,
|
||||||
|
Fuzz = bindings::MetricType_FuzzErrorMetric as isize,
|
||||||
|
MeanAbsolute = bindings::MetricType_MeanAbsoluteErrorMetric as isize,
|
||||||
|
MeanErrorPerPixel = bindings::MetricType_MeanErrorPerPixelErrorMetric as isize,
|
||||||
|
MeanSquared = bindings::MetricType_MeanSquaredErrorMetric as isize,
|
||||||
|
NormalizedCrossCorrelation = bindings::MetricType_NormalizedCrossCorrelationErrorMetric as isize,
|
||||||
|
PeakAbsolute = bindings::MetricType_PeakAbsoluteErrorMetric as isize,
|
||||||
|
PeakSignalToNoiseRatio = bindings::MetricType_PeakSignalToNoiseRatioErrorMetric as isize,
|
||||||
|
PerceptualHash = bindings::MetricType_PerceptualHashErrorMetric as isize,
|
||||||
|
RootMeanSquared = bindings::MetricType_RootMeanSquaredErrorMetric as isize,
|
||||||
|
StructuralSimilarity = bindings::MetricType_StructuralSimilarityErrorMetric as isize,
|
||||||
|
StructuralDissimilarity = bindings::MetricType_StructuralDissimilarityErrorMetric as isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for MetricType {
|
||||||
|
fn default() -> Self {
|
||||||
|
return MetricType::Absolute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MetricType> for bindings::MetricType {
|
||||||
|
fn from(value: MetricType) -> Self {
|
||||||
|
return value as bindings::MetricType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,7 +29,7 @@ use {size_t, ssize_t};
|
|||||||
use crate::result::Result;
|
use crate::result::Result;
|
||||||
|
|
||||||
use super::{DrawingWand, PixelWand};
|
use super::{DrawingWand, PixelWand};
|
||||||
use crate::{CompositeOperator, ResourceType};
|
use crate::{CompositeOperator, MetricType, ResourceType};
|
||||||
|
|
||||||
wand_common!(
|
wand_common!(
|
||||||
MagickWand,
|
MagickWand,
|
||||||
@ -202,11 +202,11 @@ impl MagickWand {
|
|||||||
pub fn compare_images(
|
pub fn compare_images(
|
||||||
&self,
|
&self,
|
||||||
reference: &MagickWand,
|
reference: &MagickWand,
|
||||||
metric: bindings::MetricType,
|
metric: MetricType,
|
||||||
) -> (f64, Option<MagickWand>) {
|
) -> (f64, Option<MagickWand>) {
|
||||||
let mut distortion: f64 = 0.0;
|
let mut distortion: f64 = 0.0;
|
||||||
let result = unsafe {
|
let result = unsafe {
|
||||||
bindings::MagickCompareImages(self.wand, reference.wand, metric, &mut distortion)
|
bindings::MagickCompareImages(self.wand, reference.wand, metric.into(), &mut distortion)
|
||||||
};
|
};
|
||||||
let wand = if result.is_null() {
|
let wand = if result.is_null() {
|
||||||
None
|
None
|
||||||
|
|||||||
46
tests/lib.rs
46
tests/lib.rs
@ -22,7 +22,7 @@ use std::io::Read;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
|
||||||
use magick_rust::{bindings, magick_wand_genesis, MagickWand, PixelWand};
|
use magick_rust::{bindings, magick_wand_genesis, CompositeOperator, MagickWand, PixelWand};
|
||||||
use magick_rust::{MagickError, ToMagick};
|
use magick_rust::{MagickError, ToMagick};
|
||||||
|
|
||||||
// Used to make sure MagickWand is initialized exactly once. Note that we
|
// Used to make sure MagickWand is initialized exactly once. Note that we
|
||||||
@ -209,7 +209,7 @@ fn test_compare_images() {
|
|||||||
wand2.auto_orient();
|
wand2.auto_orient();
|
||||||
|
|
||||||
let (distortion, diff) =
|
let (distortion, diff) =
|
||||||
wand1.compare_images(&wand2, bindings::MetricType_RootMeanSquaredErrorMetric);
|
wand1.compare_images(&wand2, magick_rust::MetricType::RootMeanSquared);
|
||||||
assert!(distortion < 0.01);
|
assert!(distortion < 0.01);
|
||||||
assert!(diff.is_some());
|
assert!(diff.is_some());
|
||||||
}
|
}
|
||||||
@ -417,6 +417,48 @@ fn test_auto_gamma() {
|
|||||||
assert!(wand.auto_gamma().is_ok());
|
assert!(wand.auto_gamma().is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_image_compose() {
|
||||||
|
START.call_once(|| {
|
||||||
|
magick_wand_genesis();
|
||||||
|
});
|
||||||
|
let wand = MagickWand::new();
|
||||||
|
wand.new_image(4, 4, &PixelWand::new()).unwrap();
|
||||||
|
|
||||||
|
let operators = [
|
||||||
|
CompositeOperator::Alpha,
|
||||||
|
CompositeOperator::MinusDst,
|
||||||
|
CompositeOperator::Over,
|
||||||
|
CompositeOperator::Xor,
|
||||||
|
CompositeOperator::Bumpmap,
|
||||||
|
CompositeOperator::ChangeMask,
|
||||||
|
CompositeOperator::Clear,
|
||||||
|
CompositeOperator::ColorBurn,
|
||||||
|
CompositeOperator::ColorDodge,
|
||||||
|
CompositeOperator::Colorize,
|
||||||
|
CompositeOperator::CopyBlack,
|
||||||
|
CompositeOperator::CopyBlue,
|
||||||
|
CompositeOperator::Copy,
|
||||||
|
CompositeOperator::CopyCyan,
|
||||||
|
CompositeOperator::CopyGreen,
|
||||||
|
CompositeOperator::CopyMagenta,
|
||||||
|
CompositeOperator::CopyAlpha,
|
||||||
|
CompositeOperator::CopyRed,
|
||||||
|
CompositeOperator::CopyYellow,
|
||||||
|
CompositeOperator::Darken,
|
||||||
|
CompositeOperator::DarkenIntensity,
|
||||||
|
CompositeOperator::Difference,
|
||||||
|
CompositeOperator::Displace,
|
||||||
|
CompositeOperator::Dissolve,
|
||||||
|
CompositeOperator::Distort,
|
||||||
|
CompositeOperator::DivideDst,
|
||||||
|
];
|
||||||
|
for op in operators.iter() {
|
||||||
|
wand.set_image_compose(*op).unwrap();
|
||||||
|
assert_eq!(*op, wand.get_image_compose());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_import_export_pixels_roundtrip() {
|
fn test_import_export_pixels_roundtrip() {
|
||||||
START.call_once(|| {
|
START.call_once(|| {
|
||||||
|
|||||||
Reference in New Issue
Block a user