Add alias to bindings::MagickBoolean_*

Reduces the amount of repetitive `bindingc::MagickBoolean_*` in wrapper
code
This commit is contained in:
5ohue
2024-05-11 13:57:29 +03:00
parent cac32a9760
commit eb982bbf1d
6 changed files with 79 additions and 78 deletions

View File

@ -16,15 +16,11 @@
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::fmt; use std::fmt;
#[cfg(target_os = "freebsd")]
use libc::size_t;
#[cfg(not(target_os = "freebsd"))]
use size_t;
use bindings; use bindings;
use crate::result::MagickError; use crate::result::MagickError;
use crate::result::Result; use crate::result::Result;
use crate::GravityType;
wand_common!( wand_common!(
DrawingWand, DrawingWand,
@ -91,7 +87,7 @@ impl DrawingWand {
); );
set_get_unchecked!( set_get_unchecked!(
get_gravity, set_gravity, DrawGetGravity, DrawSetGravity, bindings::GravityType get_gravity, set_gravity, DrawGetGravity, DrawSetGravity, GravityType
get_opacity, set_opacity, DrawGetOpacity, DrawSetOpacity, f64 get_opacity, set_opacity, DrawGetOpacity, DrawSetOpacity, f64
get_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, bindings::FillRule get_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, bindings::FillRule
get_clip_units, set_clip_units, DrawGetClipUnits, DrawSetClipUnits, bindings::ClipPathUnits get_clip_units, set_clip_units, DrawGetClipUnits, DrawSetClipUnits, bindings::ClipPathUnits
@ -100,13 +96,13 @@ impl DrawingWand {
get_font_size, set_font_size, DrawGetFontSize, DrawSetFontSize, f64 get_font_size, set_font_size, DrawGetFontSize, DrawSetFontSize, f64
get_font_style, set_font_style, DrawGetFontStyle, DrawSetFontStyle, bindings::StyleType get_font_style, set_font_style, DrawGetFontStyle, DrawSetFontStyle, bindings::StyleType
get_font_weight, set_font_weight, DrawGetFontWeight, DrawSetFontWeight, size_t get_font_weight, set_font_weight, DrawGetFontWeight, DrawSetFontWeight, usize
get_font_stretch, set_font_stretch, DrawGetFontStretch, DrawSetFontStretch, bindings::StretchType get_font_stretch, set_font_stretch, DrawGetFontStretch, DrawSetFontStretch, bindings::StretchType
get_stroke_dash_offset, set_stroke_dash_offset, DrawGetStrokeDashOffset, DrawSetStrokeDashOffset, f64 get_stroke_dash_offset, set_stroke_dash_offset, DrawGetStrokeDashOffset, DrawSetStrokeDashOffset, f64
get_stroke_line_cap, set_stroke_line_cap, DrawGetStrokeLineCap, DrawSetStrokeLineCap, bindings::LineCap get_stroke_line_cap, set_stroke_line_cap, DrawGetStrokeLineCap, DrawSetStrokeLineCap, bindings::LineCap
get_stroke_line_join, set_stroke_line_join, DrawGetStrokeLineJoin, DrawSetStrokeLineJoin, bindings::LineJoin get_stroke_line_join, set_stroke_line_join, DrawGetStrokeLineJoin, DrawSetStrokeLineJoin, bindings::LineJoin
get_stroke_miter_limit, set_stroke_miter_limit, DrawGetStrokeMiterLimit, DrawSetStrokeMiterLimit, size_t get_stroke_miter_limit, set_stroke_miter_limit, DrawGetStrokeMiterLimit, DrawSetStrokeMiterLimit, usize
get_stroke_opacity, set_stroke_opacity, DrawGetStrokeOpacity, DrawSetStrokeOpacity, f64 get_stroke_opacity, set_stroke_opacity, DrawGetStrokeOpacity, DrawSetStrokeOpacity, f64
get_stroke_width, set_stroke_width, DrawGetStrokeWidth, DrawSetStrokeWidth, f64 get_stroke_width, set_stroke_width, DrawGetStrokeWidth, DrawSetStrokeWidth, f64
get_stroke_antialias, set_stroke_antialias, DrawGetStrokeAntialias, DrawSetStrokeAntialias, bindings::MagickBooleanType get_stroke_antialias, set_stroke_antialias, DrawGetStrokeAntialias, DrawSetStrokeAntialias, bindings::MagickBooleanType

View File

@ -130,10 +130,10 @@ macro_rules! set_get_unchecked {
($($get:ident, $set:ident, $c_get:ident, $c_set:ident, $typ:ty )*) => { ($($get:ident, $set:ident, $c_get:ident, $c_set:ident, $typ:ty )*) => {
$( $(
pub fn $get(&self) -> $typ { pub fn $get(&self) -> $typ {
unsafe { ::bindings::$c_get(self.wand) } unsafe { ::bindings::$c_get(self.wand).into() }
} }
pub fn $set(&mut self, v: $typ) { pub fn $set(&mut self, v: $typ) {
unsafe { ::bindings::$c_set(self.wand, v) } unsafe { ::bindings::$c_set(self.wand, v.into()) }
} }
)* )*
pub fn fmt_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result { pub fn fmt_unchecked_settings(&self, f: &mut ::std::fmt::Formatter, prefix: &str) -> ::std::fmt::Result {

View File

@ -27,6 +27,7 @@ use result::MagickError;
use size_t; use size_t;
use crate::result::Result; use crate::result::Result;
use super::{MagickTrue, MagickFalse};
use super::{DrawingWand, PixelWand}; use super::{DrawingWand, PixelWand};
use crate::{ use crate::{
@ -62,7 +63,7 @@ wand_common!(
impl MagickWand { impl MagickWand {
pub fn new_image(&self, columns: usize, rows: usize, pixel_wand: &PixelWand) -> Result<()> { pub fn new_image(&self, columns: usize, rows: usize, pixel_wand: &PixelWand) -> Result<()> {
match unsafe { bindings::MagickNewImage(self.wand, columns.into(), rows.into(), pixel_wand.wand) } { match unsafe { bindings::MagickNewImage(self.wand, columns.into(), rows.into(), pixel_wand.wand) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("Could not create image")), _ => Err(MagickError("Could not create image")),
} }
} }
@ -77,7 +78,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to set resource limit")), _ => Err(MagickError("failed to set resource limit")),
} }
} }
@ -88,7 +89,7 @@ impl MagickWand {
let result = let result =
unsafe { bindings::MagickSetOption(self.wand, c_key.as_ptr(), c_value.as_ptr()) }; unsafe { bindings::MagickSetOption(self.wand, c_key.as_ptr(), c_value.as_ptr()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to set option")), _ => Err(MagickError("failed to set option")),
} }
} }
@ -112,7 +113,7 @@ impl MagickWand {
c_string.as_ptr() as *const _, c_string.as_ptr() as *const _,
) )
} { } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("unable to annotate image")), _ => Err(MagickError("unable to annotate image")),
} }
} }
@ -120,7 +121,7 @@ impl MagickWand {
/// Add all images from another wand to this wand at the current index. /// Add all images from another wand to this wand at the current index.
pub fn add_image(&mut self, other_wand: &MagickWand) -> Result<()> { pub fn add_image(&mut self, other_wand: &MagickWand) -> Result<()> {
match unsafe { bindings::MagickAddImage(self.wand, other_wand.wand) } { match unsafe { bindings::MagickAddImage(self.wand, other_wand.wand) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("unable to add images from another wand")), _ => Err(MagickError("unable to add images from another wand")),
} }
} }
@ -136,7 +137,7 @@ impl MagickWand {
let c_label = CString::new(label).unwrap(); let c_label = CString::new(label).unwrap();
let result = unsafe { bindings::MagickLabelImage(self.wand, c_label.as_ptr()) }; let result = unsafe { bindings::MagickLabelImage(self.wand, c_label.as_ptr()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to add label")), _ => Err(MagickError("failed to add label")),
} }
} }
@ -146,7 +147,7 @@ impl MagickWand {
let result = let result =
unsafe { bindings::MagickWriteImages(self.wand, c_name.as_ptr(), adjoin.to_magick()) }; unsafe { bindings::MagickWriteImages(self.wand, c_name.as_ptr(), adjoin.to_magick()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to write images")), _ => Err(MagickError("failed to write images")),
} }
} }
@ -156,7 +157,7 @@ impl MagickWand {
let c_name = CString::new(path).unwrap(); let c_name = CString::new(path).unwrap();
let result = unsafe { bindings::MagickReadImage(self.wand, c_name.as_ptr()) }; let result = unsafe { bindings::MagickReadImage(self.wand, c_name.as_ptr()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to read image")), _ => Err(MagickError("failed to read image")),
} }
} }
@ -173,7 +174,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to read image")), _ => Err(MagickError("failed to read image")),
} }
} }
@ -184,7 +185,7 @@ impl MagickWand {
let c_name = CString::new(path).unwrap(); let c_name = CString::new(path).unwrap();
let result = unsafe { bindings::MagickPingImage(self.wand, c_name.as_ptr()) }; let result = unsafe { bindings::MagickPingImage(self.wand, c_name.as_ptr()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to ping image")), _ => Err(MagickError("failed to ping image")),
} }
} }
@ -202,7 +203,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to ping image")), _ => Err(MagickError("failed to ping image")),
} }
} }
@ -236,9 +237,9 @@ impl MagickWand {
y: isize, y: isize,
) -> Result<()> { ) -> Result<()> {
let native_clip_to_self = if clip_to_self { let native_clip_to_self = if clip_to_self {
bindings::MagickBooleanType_MagickTrue MagickTrue
} else { } else {
bindings::MagickBooleanType_MagickFalse MagickFalse
}; };
let result = unsafe { let result = unsafe {
bindings::MagickCompositeImage( bindings::MagickCompositeImage(
@ -251,7 +252,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to compose images")), _ => Err(MagickError("failed to compose images")),
} }
} }
@ -272,7 +273,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to compose images")), _ => Err(MagickError("failed to compose images")),
} }
} }
@ -297,7 +298,7 @@ impl MagickWand {
) -> Result<()> { ) -> Result<()> {
let result = unsafe { bindings::MagickClutImage(self.wand, clut_wand.wand, method.into()) }; let result = unsafe { bindings::MagickClutImage(self.wand, clut_wand.wand, method.into()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError( _ => Err(MagickError(
"failed to replace colors in the image from color lookup table", "failed to replace colors in the image from color lookup table",
)), )),
@ -307,7 +308,7 @@ impl MagickWand {
pub fn hald_clut_image(&self, clut_wand: &MagickWand) -> Result<()> { pub fn hald_clut_image(&self, clut_wand: &MagickWand) -> Result<()> {
let result = unsafe { bindings::MagickHaldClutImage(self.wand, clut_wand.wand) }; let result = unsafe { bindings::MagickHaldClutImage(self.wand, clut_wand.wand) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError( _ => Err(MagickError(
"failed to replace colors in the image from color lookup table", "failed to replace colors in the image from color lookup table",
)), )),
@ -323,7 +324,7 @@ impl MagickWand {
pub fn set_size(&self, columns: usize, rows: usize) -> Result<()> { pub fn set_size(&self, columns: usize, rows: usize) -> Result<()> {
let result = unsafe { bindings::MagickSetSize(self.wand, columns.into(), rows.into()) }; let result = unsafe { bindings::MagickSetSize(self.wand, columns.into(), rows.into()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to set size of wand")), _ => Err(MagickError("failed to set size of wand")),
} }
} }
@ -362,7 +363,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("Failed to level the image")), _ => Err(MagickError("Failed to level the image")),
} }
} }
@ -378,7 +379,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("Failed to apply contrast stretch to image")), _ => Err(MagickError("Failed to apply contrast stretch to image")),
} }
} }
@ -399,7 +400,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("Failed to apply ordered dither to image")), _ => Err(MagickError("Failed to apply ordered dither to image")),
} }
} }
@ -423,7 +424,7 @@ impl MagickWand {
) )
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("Failed to apply sigmoidal contrast to image")), _ => Err(MagickError("Failed to apply sigmoidal contrast to image")),
} }
} }
@ -433,7 +434,7 @@ impl MagickWand {
pub fn extend_image(&self, width: usize, height: usize, x: isize, y: isize) -> Result<()> { pub fn extend_image(&self, width: usize, height: usize, x: isize, y: isize) -> Result<()> {
let result = unsafe { bindings::MagickExtentImage(self.wand, width, height, x, y) }; let result = unsafe { bindings::MagickExtentImage(self.wand, width, height, x, y) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to extend image")), _ => Err(MagickError("failed to extend image")),
} }
} }
@ -457,7 +458,7 @@ impl MagickWand {
bindings::MagickProfileImage(self.wand, c_name.as_ptr(), profile_ptr, profile_len) bindings::MagickProfileImage(self.wand, c_name.as_ptr(), profile_ptr, profile_len)
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to profile image")), _ => Err(MagickError("failed to profile image")),
} }
} }
@ -465,7 +466,7 @@ impl MagickWand {
pub fn strip_image(&self) -> Result<()> { pub fn strip_image(&self) -> Result<()> {
let result = unsafe { bindings::MagickStripImage(self.wand) }; let result = unsafe { bindings::MagickStripImage(self.wand) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to strip image")), _ => Err(MagickError("failed to strip image")),
} }
} }
@ -473,17 +474,17 @@ impl MagickWand {
pub fn flip_image(&self) -> Result<()> { pub fn flip_image(&self) -> Result<()> {
let result = unsafe { bindings::MagickFlipImage(self.wand) }; let result = unsafe { bindings::MagickFlipImage(self.wand) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to flip image")), _ => Err(MagickError("failed to flip image")),
} }
} }
pub fn negate_image(&self) -> Result<()> { pub fn negate_image(&self) -> Result<()> {
let result = unsafe { let result = unsafe {
bindings::MagickNegateImage(self.wand, bindings::MagickBooleanType_MagickTrue) bindings::MagickNegateImage(self.wand, MagickTrue)
}; };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to flip image")), _ => Err(MagickError("failed to flip image")),
} }
} }
@ -491,7 +492,7 @@ impl MagickWand {
pub fn flop_image(&self) -> Result<()> { pub fn flop_image(&self) -> Result<()> {
let result = unsafe { bindings::MagickFlopImage(self.wand) }; let result = unsafe { bindings::MagickFlopImage(self.wand) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to flip image")), _ => Err(MagickError("failed to flip image")),
} }
} }
@ -499,7 +500,7 @@ impl MagickWand {
pub fn blur_image(&self, radius: f64, sigma: f64) -> Result<()> { pub fn blur_image(&self, radius: f64, sigma: f64) -> Result<()> {
let result = unsafe { bindings::MagickBlurImage(self.wand, radius, sigma) }; let result = unsafe { bindings::MagickBlurImage(self.wand, radius, sigma) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to blur image")), _ => Err(MagickError("failed to blur image")),
} }
} }
@ -507,7 +508,7 @@ impl MagickWand {
pub fn gaussian_blur_image(&self, radius: f64, sigma: f64) -> Result<()> { pub fn gaussian_blur_image(&self, radius: f64, sigma: f64) -> Result<()> {
let result = unsafe { bindings::MagickGaussianBlurImage(self.wand, radius, sigma) }; let result = unsafe { bindings::MagickGaussianBlurImage(self.wand, radius, sigma) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to gaussian blur image")), _ => Err(MagickError("failed to gaussian blur image")),
} }
} }
@ -515,7 +516,7 @@ impl MagickWand {
/// Adaptively resize the currently selected image. /// Adaptively resize the currently selected image.
pub fn adaptive_resize_image(&self, width: usize, height: usize) -> Result<()> { pub fn adaptive_resize_image(&self, width: usize, height: usize) -> Result<()> {
match unsafe { bindings::MagickAdaptiveResizeImage(self.wand, width, height) } { match unsafe { bindings::MagickAdaptiveResizeImage(self.wand, width, height) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to adaptive-resize image")), _ => Err(MagickError("failed to adaptive-resize image")),
} }
} }
@ -524,7 +525,7 @@ impl MagickWand {
/// filling any empty space with the background color of a given PixelWand /// filling any empty space with the background color of a given PixelWand
pub fn rotate_image(&self, background: &PixelWand, degrees: f64) -> Result<()> { pub fn rotate_image(&self, background: &PixelWand, degrees: f64) -> Result<()> {
match unsafe { bindings::MagickRotateImage(self.wand, background.wand, degrees) } { match unsafe { bindings::MagickRotateImage(self.wand, background.wand, degrees) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to rotate image")), _ => Err(MagickError("failed to rotate image")),
} }
} }
@ -533,7 +534,7 @@ impl MagickWand {
pub fn trim_image(&self, fuzz: f64) -> Result<()> { pub fn trim_image(&self, fuzz: f64) -> Result<()> {
let result = unsafe { bindings::MagickTrimImage(self.wand, fuzz) }; let result = unsafe { bindings::MagickTrimImage(self.wand, fuzz) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to trim image")), _ => Err(MagickError("failed to trim image")),
} }
} }
@ -561,7 +562,7 @@ impl MagickWand {
pub fn reset_image_page(&self, page_geometry: &str) -> Result<()> { pub fn reset_image_page(&self, page_geometry: &str) -> Result<()> {
let c_page_geometry = CString::new(page_geometry).unwrap(); let c_page_geometry = CString::new(page_geometry).unwrap();
let result = unsafe { bindings::MagickResetImagePage(self.wand, c_page_geometry.as_ptr()) }; let result = unsafe { bindings::MagickResetImagePage(self.wand, c_page_geometry.as_ptr()) };
if result == bindings::MagickBooleanType_MagickTrue { if result == MagickTrue {
Ok(()) Ok(())
} else { } else {
Err(MagickError("Resetting page geometry failed.")) Err(MagickError("Resetting page geometry failed."))
@ -592,7 +593,7 @@ impl MagickWand {
let result = unsafe { let result = unsafe {
bindings::MagickSetImageProperty(self.wand, c_name.as_ptr(), c_value.as_ptr()) bindings::MagickSetImageProperty(self.wand, c_name.as_ptr(), c_value.as_ptr())
}; };
if result == bindings::MagickBooleanType_MagickTrue { if result == MagickTrue {
Ok(()) Ok(())
} else { } else {
Err(MagickError("Setting image property failed.")) Err(MagickError("Setting image property failed."))
@ -605,7 +606,7 @@ impl MagickWand {
unsafe { unsafe {
if bindings::MagickGetImagePixelColor(self.wand, x, y, pw.wand) if bindings::MagickGetImagePixelColor(self.wand, x, y, pw.wand)
== bindings::MagickBooleanType_MagickTrue == MagickTrue
{ {
Some(pw) Some(pw)
} else { } else {
@ -625,7 +626,7 @@ impl MagickWand {
&samplingFactors[0], &samplingFactors[0],
) )
} { } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("SetSamplingFactors returned false")), _ => Err(MagickError("SetSamplingFactors returned false")),
} }
} }
@ -657,7 +658,7 @@ impl MagickWand {
/// ///
pub fn sharpen_image(&self, radius: f64, sigma: f64) -> Result<()> { pub fn sharpen_image(&self, radius: f64, sigma: f64) -> Result<()> {
match unsafe { bindings::MagickSharpenImage(self.wand, radius, sigma) } { match unsafe { bindings::MagickSharpenImage(self.wand, radius, sigma) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("SharpenImage returned false")), _ => Err(MagickError("SharpenImage returned false")),
} }
@ -666,7 +667,7 @@ impl MagickWand {
/// Set the background color. /// Set the background color.
pub fn set_background_color(&self, pixel_wand: &PixelWand) -> Result<()> { pub fn set_background_color(&self, pixel_wand: &PixelWand) -> Result<()> {
match unsafe { bindings::MagickSetBackgroundColor(self.wand, pixel_wand.wand) } { match unsafe { bindings::MagickSetBackgroundColor(self.wand, pixel_wand.wand) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("SetBackgroundColor returned false")), _ => Err(MagickError("SetBackgroundColor returned false")),
} }
@ -675,7 +676,7 @@ impl MagickWand {
/// Set the image background color. /// Set the image background color.
pub fn set_image_background_color(&self, pixel_wand: &PixelWand) -> Result<()> { pub fn set_image_background_color(&self, pixel_wand: &PixelWand) -> Result<()> {
match unsafe { bindings::MagickSetImageBackgroundColor(self.wand, pixel_wand.wand) } { match unsafe { bindings::MagickSetImageBackgroundColor(self.wand, pixel_wand.wand) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("SetImageBackgroundColor returned false")), _ => Err(MagickError("SetImageBackgroundColor returned false")),
} }
@ -687,7 +688,7 @@ impl MagickWand {
let mut y_resolution = 0f64; let mut y_resolution = 0f64;
unsafe { unsafe {
if bindings::MagickGetImageResolution(self.wand, &mut x_resolution, &mut y_resolution) if bindings::MagickGetImageResolution(self.wand, &mut x_resolution, &mut y_resolution)
== bindings::MagickBooleanType_MagickTrue == MagickTrue
{ {
Ok((x_resolution, y_resolution)) Ok((x_resolution, y_resolution))
} else { } else {
@ -700,7 +701,7 @@ impl MagickWand {
pub fn set_image_resolution(&self, x_resolution: f64, y_resolution: f64) -> Result<()> { pub fn set_image_resolution(&self, x_resolution: f64, y_resolution: f64) -> Result<()> {
unsafe { unsafe {
if bindings::MagickSetImageResolution(self.wand, x_resolution, y_resolution) if bindings::MagickSetImageResolution(self.wand, x_resolution, y_resolution)
== bindings::MagickBooleanType_MagickTrue == MagickTrue
{ {
Ok(()) Ok(())
} else { } else {
@ -713,7 +714,7 @@ impl MagickWand {
pub fn set_resolution(&self, x_resolution: f64, y_resolution: f64) -> Result<()> { pub fn set_resolution(&self, x_resolution: f64, y_resolution: f64) -> Result<()> {
unsafe { unsafe {
if bindings::MagickSetResolution(self.wand, x_resolution, y_resolution) if bindings::MagickSetResolution(self.wand, x_resolution, y_resolution)
== bindings::MagickBooleanType_MagickTrue == MagickTrue
{ {
Ok(()) Ok(())
} else { } else {
@ -726,7 +727,7 @@ impl MagickWand {
pub fn sepia_tone_image(&self, threshold: f64) -> Result<()> { pub fn sepia_tone_image(&self, threshold: f64) -> Result<()> {
unsafe { unsafe {
if bindings::MagickSepiaToneImage(self.wand, threshold * self.quantum_range()?) if bindings::MagickSepiaToneImage(self.wand, threshold * self.quantum_range()?)
== bindings::MagickBooleanType_MagickTrue == MagickTrue
{ {
Ok(()) Ok(())
} else { } else {
@ -760,7 +761,7 @@ impl MagickWand {
c_map.as_ptr(), c_map.as_ptr(),
bindings::StorageType_CharPixel, bindings::StorageType_CharPixel,
pixels.as_mut_ptr() as *mut c_void, pixels.as_mut_ptr() as *mut c_void,
) == bindings::MagickBooleanType_MagickTrue ) == MagickTrue
{ {
Some(pixels) Some(pixels)
} else { } else {
@ -791,7 +792,7 @@ impl MagickWand {
pub fn crop_image(&self, width: usize, height: usize, x: isize, y: isize) -> Result<()> { pub fn crop_image(&self, width: usize, height: usize, x: isize, y: isize) -> Result<()> {
let result = unsafe { bindings::MagickCropImage(self.wand, width, height, x, y) }; let result = unsafe { bindings::MagickCropImage(self.wand, width, height, x, y) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to crop image")), _ => Err(MagickError("failed to crop image")),
} }
} }
@ -803,7 +804,7 @@ impl MagickWand {
pub fn sample_image(&self, width: usize, height: usize) -> Result<()> { pub fn sample_image(&self, width: usize, height: usize) -> Result<()> {
let result = unsafe { bindings::MagickSampleImage(self.wand, width, height) }; let result = unsafe { bindings::MagickSampleImage(self.wand, width, height) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to sample image")), _ => Err(MagickError("failed to sample image")),
} }
} }
@ -832,7 +833,7 @@ impl MagickWand {
match unsafe { match unsafe {
bindings::MagickLiquidRescaleImage(self.wand, width, height, delta_x, rigidity) bindings::MagickLiquidRescaleImage(self.wand, width, height, delta_x, rigidity)
} { } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to liquid-rescale image")), _ => Err(MagickError("failed to liquid-rescale image")),
} }
} }
@ -840,7 +841,7 @@ impl MagickWand {
/// Implodes the image towards the center by the specified percentage /// Implodes the image towards the center by the specified percentage
pub fn implode(&self, amount: f64, method: bindings::PixelInterpolateMethod) -> Result<()> { pub fn implode(&self, amount: f64, method: bindings::PixelInterpolateMethod) -> Result<()> {
match unsafe { bindings::MagickImplodeImage(self.wand, amount, method) } { match unsafe { bindings::MagickImplodeImage(self.wand, amount, method) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to implode image")), _ => Err(MagickError("failed to implode image")),
} }
} }
@ -865,7 +866,7 @@ impl MagickWand {
}; };
unsafe { unsafe {
bindings::MagickResetIterator(self.wand); bindings::MagickResetIterator(self.wand);
while bindings::MagickNextImage(self.wand) != bindings::MagickBooleanType_MagickFalse { while bindings::MagickNextImage(self.wand) != MagickFalse {
bindings::MagickResizeImage( bindings::MagickResizeImage(
self.wand, self.wand,
new_width.into(), new_width.into(),
@ -891,7 +892,7 @@ impl MagickWand {
/// Returns `true` if successful or `false` if an error occurred. /// Returns `true` if successful or `false` if an error occurred.
pub fn auto_orient(&self) -> bool { pub fn auto_orient(&self) -> bool {
unsafe { unsafe {
bindings::MagickAutoOrientImage(self.wand) == bindings::MagickBooleanType_MagickTrue bindings::MagickAutoOrientImage(self.wand) == MagickTrue
} }
} }
@ -900,7 +901,7 @@ impl MagickWand {
let c_name = CString::new(path).unwrap(); let c_name = CString::new(path).unwrap();
let result = unsafe { bindings::MagickWriteImage(self.wand, c_name.as_ptr()) }; let result = unsafe { bindings::MagickWriteImage(self.wand, c_name.as_ptr()) };
match result { match result {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to write image")), _ => Err(MagickError("failed to write image")),
} }
} }
@ -955,13 +956,13 @@ impl MagickWand {
/// That is, the image is RGB rather than RGBA or CMYK rather than CMYKA /// That is, the image is RGB rather than RGBA or CMYK rather than CMYKA
pub fn get_image_alpha_channel(&self) -> bool { pub fn get_image_alpha_channel(&self) -> bool {
let res = unsafe { bindings::MagickGetImageAlphaChannel(self.wand) }; let res = unsafe { bindings::MagickGetImageAlphaChannel(self.wand) };
res == bindings::MagickBooleanType_MagickTrue res == MagickTrue
} }
/// Renders the drawing wand on the current image /// Renders the drawing wand on the current image
pub fn draw_image(&mut self, drawing_wand: &DrawingWand) -> Result<()> { pub fn draw_image(&mut self, drawing_wand: &DrawingWand) -> Result<()> {
match unsafe { bindings::MagickDrawImage(self.wand, drawing_wand.wand) } { match unsafe { bindings::MagickDrawImage(self.wand, drawing_wand.wand) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("unable to draw image")), _ => Err(MagickError("unable to draw image")),
} }
} }
@ -972,7 +973,7 @@ impl MagickWand {
/// not placed completely flat when scanned /// not placed completely flat when scanned
pub fn deskew_image(&mut self, threshold: f64) -> Result<()> { pub fn deskew_image(&mut self, threshold: f64) -> Result<()> {
match unsafe { bindings::MagickDeskewImage(self.wand, threshold) } { match unsafe { bindings::MagickDeskewImage(self.wand, threshold) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("unable to deskew image")), _ => Err(MagickError("unable to deskew image")),
} }
} }
@ -992,7 +993,7 @@ impl MagickWand {
pub fn evaluate_image(&mut self, op: bindings::MagickEvaluateOperator, val: f64) -> Result<()> { pub fn evaluate_image(&mut self, op: bindings::MagickEvaluateOperator, val: f64) -> Result<()> {
let res = unsafe { bindings::MagickEvaluateImage(self.wand, op, val) }; let res = unsafe { bindings::MagickEvaluateImage(self.wand, op, val) };
match res { match res {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to evaluate image")), _ => Err(MagickError("failed to evaluate image")),
} }
} }
@ -1009,7 +1010,7 @@ impl MagickWand {
match unsafe { match unsafe {
bindings::MagickBorderImage(self.wand, pixel_wand.wand, width, height, compose.into()) bindings::MagickBorderImage(self.wand, pixel_wand.wand, width, height, compose.into())
} { } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("border image returned false")), _ => Err(MagickError("border image returned false")),
} }
@ -1019,7 +1020,7 @@ impl MagickWand {
pub fn shadow_image(&self, alpha: f64, sigma: f64, x: isize, y: isize) -> Result<()> { pub fn shadow_image(&self, alpha: f64, sigma: f64, x: isize, y: isize) -> Result<()> {
unsafe { unsafe {
if bindings::MagickShadowImage(self.wand, alpha, sigma, x, y) if bindings::MagickShadowImage(self.wand, alpha, sigma, x, y)
== bindings::MagickBooleanType_MagickTrue == MagickTrue
{ {
Ok(()) Ok(())
} else { } else {
@ -1052,7 +1053,7 @@ impl MagickWand {
pixels.as_ptr() as *const libc::c_void, pixels.as_ptr() as *const libc::c_void,
) )
} { } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("unable to import pixels")), _ => Err(MagickError("unable to import pixels")),
} }
} }
@ -1069,7 +1070,7 @@ impl MagickWand {
/// See <https://imagemagick.org/api/magick-image.php#MagickNextImage> for more information. /// See <https://imagemagick.org/api/magick-image.php#MagickNextImage> for more information.
pub fn next_image(&self) -> bool { pub fn next_image(&self) -> bool {
let res = unsafe { bindings::MagickNextImage(self.wand) }; let res = unsafe { bindings::MagickNextImage(self.wand) };
res == bindings::MagickBooleanType_MagickTrue res == MagickTrue
} }
/// Automatically performs threshold method to reduce grayscale data /// Automatically performs threshold method to reduce grayscale data
@ -1078,7 +1079,7 @@ impl MagickWand {
/// See <https://imagemagick.org/api/magick-image.php#MagickAutoThresholdImage> for more information. /// See <https://imagemagick.org/api/magick-image.php#MagickAutoThresholdImage> for more information.
pub fn auto_threshold(&self, method: bindings::AutoThresholdMethod) -> Result<()> { pub fn auto_threshold(&self, method: bindings::AutoThresholdMethod) -> Result<()> {
match unsafe { bindings::MagickAutoThresholdImage(self.wand, method) } { match unsafe { bindings::MagickAutoThresholdImage(self.wand, method) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("unable to auto threshold image")), _ => Err(MagickError("unable to auto threshold image")),
} }
} }
@ -1087,7 +1088,7 @@ impl MagickWand {
/// the process. /// the process.
pub fn transform_image_colorspace(&self, colorspace: ColorspaceType) -> Result<()> { pub fn transform_image_colorspace(&self, colorspace: ColorspaceType) -> Result<()> {
match unsafe { bindings::MagickTransformImageColorspace(self.wand, colorspace.into()) } { match unsafe { bindings::MagickTransformImageColorspace(self.wand, colorspace.into()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to transform image colorspace")), _ => Err(MagickError("failed to transform image colorspace")),
} }
} }
@ -1107,7 +1108,7 @@ impl MagickWand {
tree_depth.into(), tree_depth.into(),
dither_method.into(), dither_method.into(),
measure_error.to_magick()) } { measure_error.to_magick()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to quantize image")), _ => Err(MagickError("failed to quantize image")),
} }
} }
@ -1127,7 +1128,7 @@ impl MagickWand {
tree_depth.into(), tree_depth.into(),
dither_method.into(), dither_method.into(),
measure_error.to_magick()) } { measure_error.to_magick()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to quantize images")), _ => Err(MagickError("failed to quantize images")),
} }
} }

View File

@ -22,3 +22,6 @@ mod pixel;
pub use self::drawing::DrawingWand; pub use self::drawing::DrawingWand;
pub use self::magick::MagickWand; pub use self::magick::MagickWand;
pub use self::pixel::{PixelWand, HSL}; pub use self::pixel::{PixelWand, HSL};
use bindings::MagickBooleanType_MagickTrue as MagickTrue;
use bindings::MagickBooleanType_MagickFalse as MagickFalse;

View File

@ -25,6 +25,7 @@ use bindings;
use result::MagickError; use result::MagickError;
use crate::result::Result; use crate::result::Result;
use super::MagickTrue;
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct HSL { pub struct HSL {
@ -48,7 +49,7 @@ wand_common!(
impl PixelWand { impl PixelWand {
pub fn is_similar(&self, other: &PixelWand, fuzz: f64) -> Result<()> { pub fn is_similar(&self, other: &PixelWand, fuzz: f64) -> Result<()> {
match unsafe { bindings::IsPixelWandSimilar(self.wand, other.wand, fuzz) } { match unsafe { bindings::IsPixelWandSimilar(self.wand, other.wand, fuzz) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("not similar")), _ => Err(MagickError("not similar")),
} }
} }
@ -86,7 +87,7 @@ impl PixelWand {
pub fn set_color(&mut self, s: &str) -> Result<()> { pub fn set_color(&mut self, s: &str) -> Result<()> {
let c_string = CString::new(s).map_err(|_| "could not convert to cstring")?; let c_string = CString::new(s).map_err(|_| "could not convert to cstring")?;
match unsafe { bindings::PixelSetColor(self.wand, c_string.as_ptr()) } { match unsafe { bindings::PixelSetColor(self.wand, c_string.as_ptr()) } {
bindings::MagickBooleanType_MagickTrue => Ok(()), MagickTrue => Ok(()),
_ => Err(MagickError("failed to set color")), _ => Err(MagickError("failed to set color")),
} }
} }

View File

@ -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::{magick_wand_genesis, MagickWand, PixelWand};
use magick_rust::MagickError; use magick_rust::MagickError;
// Used to make sure MagickWand is initialized exactly once. Note that we // Used to make sure MagickWand is initialized exactly once. Note that we