From b47d2e64c5852bd6a66e6e70fcd5cf378cee2173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20=C5=9Awi=C4=99cicki?= Date: Fri, 18 May 2018 13:50:56 +0000 Subject: [PATCH 1/3] Add ping_image and ping_image_blob functions. --- src/wand/magick.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 20de36b..ae85cc2 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -108,9 +108,9 @@ impl MagickWand { } /// Read the image data from the vector of bytes. - pub fn read_image_blob(&self, data: &Vec) -> Result<(), &'static str> { - let int_slice = &data[..]; - let size = data.len(); + pub fn read_image_blob>(&self, data: T) -> Result<(), &'static str> { + let int_slice = data.as_ref(); + let size = int_slice.len(); let result = unsafe { bindings::MagickReadImageBlob( self.wand, int_slice.as_ptr() as *const c_void, size as size_t) @@ -121,6 +121,34 @@ impl MagickWand { } } + /// Same as read_image, but reads only the width, height, size and format of an image, + /// without reading data. + pub fn ping_image(&self, path: &str) -> Result<(), &'static str> { + let c_name = CString::new(path).unwrap(); + let result = unsafe { + bindings::MagickPingImage(self.wand, c_name.as_ptr()) + }; + match result { + bindings::MagickBooleanType::MagickTrue => Ok(()), + _ => Err("failed to ping image") + } + } + + /// Same as read_image, but reads only the width, height, size and format of an image, + /// without reading data. + pub fn ping_image_blob>(&self, data: T) -> Result<(), &'static str> { + let int_slice = data.as_ref(); + let size = int_slice.len(); + let result = unsafe { + bindings::MagickPingImageBlob( + self.wand, int_slice.as_ptr() as *const c_void, size as size_t) + }; + match result { + bindings::MagickBooleanType::MagickTrue => Ok(()), + _ => Err("failed to ping image") + } + } + /// 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) { From 631725121a4f815a428b300ca548a6e878565e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20=C5=9Awi=C4=99cicki?= Date: Fri, 18 May 2018 13:51:11 +0000 Subject: [PATCH 2/3] Add reset_image_page function. --- src/wand/magick.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index ae85cc2..343b192 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -265,6 +265,19 @@ impl MagickWand { (width, height, x, y) } + /// Reset the Wand page canvas and position. + pub fn reset_image_page(&self, page_geometry: &str) -> Result<(), &'static str> { + let c_page_geometry = CString::new(page_geometry).unwrap(); + let result = unsafe { + bindings::MagickResetImagePage(self.wand, c_page_geometry.as_ptr()) + }; + if result == bindings::MagickBooleanType::MagickTrue { + Ok(()) + } else { + Err("Resetting page geometry failed.") + } + } + /// Retrieve the named image property value. pub fn get_image_property(&self, name: &str) -> Result { let c_name = CString::new(name).unwrap(); From 88ceb3a4af33ab524a2d4ee959688a5f8e3617b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82a=C5=BCej=20=C5=9Awi=C4=99cicki?= Date: Fri, 18 May 2018 13:51:28 +0000 Subject: [PATCH 3/3] Add set_image_alpha_channel function --- src/wand/magick.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 343b192..28bd0b0 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -538,6 +538,10 @@ impl MagickWand { MagickTransformImageColorspace => transform_image_colorspace( colorspace: bindings::ColorspaceType) + /// Set the image alpha channel mode. + MagickSetImageAlphaChannel => set_image_alpha_channel( + alpha_channel: bindings::AlphaChannelOption) + /// Reduce the number of colors in the image. MagickQuantizeImage => quantize_image( number_of_colors: size_t, colorspace: bindings::ColorspaceType,