Merge pull request #44 from magiclen/master
Binding for set_image_background_color and sharpen_image
This commit is contained in:
@ -362,6 +362,38 @@ impl MagickWand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sharpens an image. We convolve the image with a Gaussian operator of the
|
||||||
|
/// given radius and standard deviation (sigma). For reasonable results, the
|
||||||
|
/// radius should be larger than sigma. Use a radius of 0 and SharpenImage()
|
||||||
|
/// selects a suitable radius for you.
|
||||||
|
///
|
||||||
|
/// radius: the radius of the Gaussian, in pixels, not counting the center pixel.
|
||||||
|
///
|
||||||
|
/// sigma: the standard deviation of the Gaussian, in pixels.
|
||||||
|
///
|
||||||
|
pub fn sharpen_image(&self, radius: f64, sigma: f64) -> Result<(), &'static str> {
|
||||||
|
match unsafe { bindings::MagickSharpenImage(self.wand, radius, sigma) } {
|
||||||
|
|
||||||
|
bindings::MagickBooleanType::MagickTrue => Ok(()),
|
||||||
|
|
||||||
|
_ => Err("SharpenImage returned false")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the image background color.
|
||||||
|
pub fn set_image_background_color(&self, pixel_wand: &PixelWand) -> Result<(), &'static str> {
|
||||||
|
|
||||||
|
match unsafe { bindings::MagickSetImageBackgroundColor(self.wand, pixel_wand.wand) } {
|
||||||
|
|
||||||
|
bindings::MagickBooleanType::MagickTrue => Ok(()),
|
||||||
|
|
||||||
|
_ => Err("SetImageBackgroundColor returned false")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the image resolution as a pair (horizontal resolution, vertical resolution)
|
/// Returns the image resolution as a pair (horizontal resolution, vertical resolution)
|
||||||
pub fn get_image_resolution(&self) -> Result<(f64, f64), &'static str> {
|
pub fn get_image_resolution(&self) -> Result<(f64, f64), &'static str> {
|
||||||
let mut x_resolution = 0f64;
|
let mut x_resolution = 0f64;
|
||||||
|
|||||||
BIN
tests/data/rust.png
Normal file
BIN
tests/data/rust.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
36
tests/lib.rs
36
tests/lib.rs
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
extern crate magick_rust;
|
extern crate magick_rust;
|
||||||
|
|
||||||
use magick_rust::{MagickWand, magick_wand_genesis, MetricType, ColorspaceType, FilterType, DitherMethod};
|
use magick_rust::{MagickWand, magick_wand_genesis, MetricType, ColorspaceType, FilterType, DitherMethod, PixelWand, bindings};
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -263,3 +263,37 @@ fn test_color_reduction() {
|
|||||||
assert_eq!(wand.get_image_width() * wand.get_image_height(),
|
assert_eq!(wand.get_image_width() * wand.get_image_height(),
|
||||||
histogram.iter().fold(0, |total_colors, wand| total_colors + wand.get_color_count()));
|
histogram.iter().fold(0, |total_colors, wand| total_colors + wand.get_color_count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_set_image_background_color() {
|
||||||
|
START.call_once(|| {
|
||||||
|
|
||||||
|
magick_wand_genesis();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
let wand = MagickWand::new();
|
||||||
|
|
||||||
|
assert!(wand.read_image("tests/data/rust.png").is_ok());
|
||||||
|
|
||||||
|
|
||||||
|
let mut pw = PixelWand::new();
|
||||||
|
|
||||||
|
pw.set_color("#0000FF").unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
wand.set_image_background_color(&pw).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
wand.set_image_alpha_channel(bindings::AlphaChannelOption::RemoveAlphaChannel).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
let blob = wand.write_image_blob("rgb").unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
assert_eq!(0u8, blob[0]);
|
||||||
|
|
||||||
|
assert_eq!(0u8, blob[1]);
|
||||||
|
|
||||||
|
assert_eq!(255u8, blob[2]);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user