Add AlphaChannelOption type
This commit is contained in:
52
src/types/alpha_channel_option.rs
Normal file
52
src/types/alpha_channel_option.rs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
use crate::bindings;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(u32)]
|
||||||
|
pub enum AlphaChannelOption {
|
||||||
|
Undefined = bindings::AlphaChannelOption_UndefinedAlphaChannel,
|
||||||
|
Activate = bindings::AlphaChannelOption_ActivateAlphaChannel,
|
||||||
|
Associate = bindings::AlphaChannelOption_AssociateAlphaChannel,
|
||||||
|
Background = bindings::AlphaChannelOption_BackgroundAlphaChannel,
|
||||||
|
Copy = bindings::AlphaChannelOption_CopyAlphaChannel,
|
||||||
|
Deactivate = bindings::AlphaChannelOption_DeactivateAlphaChannel,
|
||||||
|
Discrete = bindings::AlphaChannelOption_DiscreteAlphaChannel,
|
||||||
|
Disassociate = bindings::AlphaChannelOption_DisassociateAlphaChannel,
|
||||||
|
Extract = bindings::AlphaChannelOption_ExtractAlphaChannel,
|
||||||
|
Off = bindings::AlphaChannelOption_OffAlphaChannel,
|
||||||
|
On = bindings::AlphaChannelOption_OnAlphaChannel,
|
||||||
|
Opaque = bindings::AlphaChannelOption_OpaqueAlphaChannel,
|
||||||
|
Remove = bindings::AlphaChannelOption_RemoveAlphaChannel,
|
||||||
|
Set = bindings::AlphaChannelOption_SetAlphaChannel,
|
||||||
|
Shape = bindings::AlphaChannelOption_ShapeAlphaChannel,
|
||||||
|
Transparent = bindings::AlphaChannelOption_TransparentAlphaChannel,
|
||||||
|
OffIfOpaque = bindings::AlphaChannelOption_OffIfOpaqueAlphaChannel,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AlphaChannelOption {
|
||||||
|
fn default() -> Self {
|
||||||
|
return AlphaChannelOption::Undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AlphaChannelOption> for bindings::AlphaChannelOption {
|
||||||
|
fn from(value: AlphaChannelOption) -> Self {
|
||||||
|
return value as bindings::AlphaChannelOption;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<bindings::AlphaChannelOption> for AlphaChannelOption {
|
||||||
|
fn from(value: bindings::AlphaChannelOption) -> Self {
|
||||||
|
/*
|
||||||
|
* SAFETY:
|
||||||
|
*
|
||||||
|
* `AlphaChannelOption` has the same repr as `bindings::AlphaChannelOption` - u32
|
||||||
|
*
|
||||||
|
* If `value` is less than OffIfOpaque than it is in the vaild range and can be safely
|
||||||
|
* reinterpreted as `AlphaChannelOption`
|
||||||
|
*/
|
||||||
|
if value <= bindings::AlphaChannelOption_OffIfOpaqueAlphaChannel {
|
||||||
|
return unsafe { std::mem::transmute(value) };
|
||||||
|
}
|
||||||
|
return AlphaChannelOption::default();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
mod alpha_channel_option;
|
||||||
mod colorspace_type;
|
mod colorspace_type;
|
||||||
mod composite_operator;
|
mod composite_operator;
|
||||||
mod dither_method;
|
mod dither_method;
|
||||||
@ -7,6 +8,7 @@ mod pixel_interpolate_method;
|
|||||||
mod metric_type;
|
mod metric_type;
|
||||||
mod resource_type;
|
mod resource_type;
|
||||||
|
|
||||||
|
pub use self::alpha_channel_option::AlphaChannelOption;
|
||||||
pub use self::colorspace_type::ColorspaceType;
|
pub use self::colorspace_type::ColorspaceType;
|
||||||
pub use self::composite_operator::CompositeOperator;
|
pub use self::composite_operator::CompositeOperator;
|
||||||
pub use self::dither_method::DitherMethod;
|
pub use self::dither_method::DitherMethod;
|
||||||
|
|||||||
@ -258,7 +258,7 @@ macro_rules! mutations {
|
|||||||
$(
|
$(
|
||||||
$(#[$attr])*
|
$(#[$attr])*
|
||||||
pub fn $fun(&self $(, $arg: $ty)*) -> Result<()> {
|
pub fn $fun(&self $(, $arg: $ty)*) -> Result<()> {
|
||||||
match unsafe { bindings::$c_fun(self.wand $(, $arg)*) } {
|
match unsafe { bindings::$c_fun(self.wand $(, $arg.into())*) } {
|
||||||
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||||
_ => Err(MagickError(concat!(stringify!($c_fun), " invocation failed")))
|
_ => Err(MagickError(concat!(stringify!($c_fun), " invocation failed")))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@ use crate::result::Result;
|
|||||||
|
|
||||||
use super::{DrawingWand, PixelWand};
|
use super::{DrawingWand, PixelWand};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
AlphaChannelOption,
|
||||||
ColorspaceType,
|
ColorspaceType,
|
||||||
CompositeOperator,
|
CompositeOperator,
|
||||||
DitherMethod,
|
DitherMethod,
|
||||||
@ -1142,8 +1143,7 @@ impl MagickWand {
|
|||||||
MagickBrightnessContrastImage => brightness_contrast_image(brightness: f64, contrast: f64)
|
MagickBrightnessContrastImage => brightness_contrast_image(brightness: f64, contrast: f64)
|
||||||
|
|
||||||
/// Set the image alpha channel mode.
|
/// Set the image alpha channel mode.
|
||||||
MagickSetImageAlphaChannel => set_image_alpha_channel(
|
MagickSetImageAlphaChannel => set_image_alpha_channel(alpha_channel: AlphaChannelOption)
|
||||||
alpha_channel: bindings::AlphaChannelOption)
|
|
||||||
|
|
||||||
/// Discard all but one of any pixel color.
|
/// Discard all but one of any pixel color.
|
||||||
MagickUniqueImageColors => unique_image_colors()
|
MagickUniqueImageColors => unique_image_colors()
|
||||||
|
|||||||
@ -317,7 +317,7 @@ fn test_set_image_background_color() {
|
|||||||
let mut pw = PixelWand::new();
|
let mut pw = PixelWand::new();
|
||||||
pw.set_color("#0000FF").unwrap();
|
pw.set_color("#0000FF").unwrap();
|
||||||
wand.set_image_background_color(&pw).unwrap();
|
wand.set_image_background_color(&pw).unwrap();
|
||||||
wand.set_image_alpha_channel(bindings::AlphaChannelOption_RemoveAlphaChannel)
|
wand.set_image_alpha_channel(magick_rust::AlphaChannelOption::Remove)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let blob = wand.write_image_blob("rgb").unwrap();
|
let blob = wand.write_image_blob("rgb").unwrap();
|
||||||
assert_eq!(0u8, blob[0]);
|
assert_eq!(0u8, blob[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user