From 7d805d9a8315bc06d5b55e9cc3b3cc2845b45877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20R=C3=B6nnkvist?= Date: Wed, 25 Mar 2020 14:26:41 +0100 Subject: [PATCH 1/2] Binding for MagickSetSize --- src/wand/magick.rs | 8 ++++++++ tests/lib.rs | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 8c557bb..14fc53e 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -230,6 +230,14 @@ impl MagickWand { } } + pub fn set_size(&self, columns: size_t, rows: size_t) -> Result<(), &'static str> { + let result = unsafe { bindings::MagickSetSize(self.wand, columns, rows) }; + match result { + bindings::MagickBooleanType_MagickTrue => Ok(()), + _ => Err("failed to set size of wand"), + } + } + /// Extend the image as defined by the geometry, gravity, and wand background color. Set the /// (x,y) offset of the geometry to move the original wand relative to the extended wand. pub fn extend_image( diff --git a/tests/lib.rs b/tests/lib.rs index 7e459c6..2a7bacc 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -319,3 +319,9 @@ fn test_set_background_color() { assert_eq!(0u8, blob[2]); assert_eq!(0u8, blob[3]); } + +#[test] +fn test_set_size() { + let wand = MagickWand::new(); + assert!(wand.set_size(100, 100).is_ok()); +} From 97d620beb8ddbdf400b8fdf0b06ce7163ba88459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20R=C3=B6nnkvist?= Date: Wed, 25 Mar 2020 14:27:33 +0100 Subject: [PATCH 2/2] Binding for MagickClutImage --- src/wand/magick.rs | 13 +++++++++++++ tests/lib.rs | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 14fc53e..f710a07 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -230,6 +230,19 @@ impl MagickWand { } } + // Replaces colors in the image from a color lookup table. + pub fn clut_image( + &self, + clut_wand: &MagickWand, + method: bindings::PixelInterpolateMethod, + ) -> Result<(), &'static str> { + let result = unsafe { bindings::MagickClutImage(self.wand, clut_wand.wand, method) }; + match result { + bindings::MagickBooleanType_MagickTrue => Ok(()), + _ => Err("failed to replace colors in the image from color lookup table"), + } + } + pub fn set_size(&self, columns: size_t, rows: size_t) -> Result<(), &'static str> { let result = unsafe { bindings::MagickSetSize(self.wand, columns, rows) }; match result { diff --git a/tests/lib.rs b/tests/lib.rs index 2a7bacc..91482ee 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -325,3 +325,24 @@ fn test_set_size() { let wand = MagickWand::new(); assert!(wand.set_size(100, 100).is_ok()); } + +#[test] +fn test_clut_image() { + START.call_once(|| { + magick_wand_genesis(); + }); + let wand = MagickWand::new(); + assert!(wand.read_image("tests/data/IMG_5745.JPG").is_ok()); + + let mut gradient = MagickWand::new(); + assert!(gradient.set_size(128, 20).is_ok()); + assert!(gradient.set_option("gradient:angle", "90").is_ok()); + assert!(gradient.read_image("gradient:black-yellow").is_ok()); + + assert!(wand + .clut_image( + &gradient, + bindings::PixelInterpolateMethod_BilinearInterpolatePixel + ) + .is_ok()); +}