Add compare_images method

This commit is contained in:
gentoo90
2017-05-16 16:43:08 +03:00
parent 4a5b6935ed
commit c50b3e27de
3 changed files with 35 additions and 1 deletions

View File

@ -37,6 +37,7 @@ mod conversions;
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
pub use wand::*;
pub use bindings::MetricType;
use libc::size_t;
#[cfg(not(target_os = "freebsd"))]

View File

@ -122,6 +122,22 @@ impl MagickWand {
}
}
/// Compare two images and return tuple `(distortion, diffImage)`
/// `diffImage` is `None` if `distortion == 0`
pub fn compare_images(&self, reference: &MagickWand, metric: bindings::MetricType) -> (f64, Option<MagickWand>) {
let mut distortion: f64 = 0.0;
let result = unsafe {
bindings::MagickCompareImages(self.wand, reference.wand, metric, &mut distortion)
};
let wand = if result.is_null() {
None
}
else {
Some(MagickWand { wand: result })
};
(distortion, wand)
}
/// Retrieve the width of the image.
pub fn get_image_width(&self) -> usize {
unsafe {