@ -33,8 +33,6 @@
|
||||
extern crate libc;
|
||||
|
||||
use libc::size_t;
|
||||
#[cfg(not(target_os = "freebsd"))]
|
||||
use libc::ssize_t;
|
||||
|
||||
pub use conversions::ToMagick;
|
||||
pub use result::MagickError;
|
||||
|
||||
39
src/types/align_type.rs
Normal file
39
src/types/align_type.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum AlignType {
|
||||
Undefined = bindings::AlignType_UndefinedAlign,
|
||||
Left = bindings::AlignType_LeftAlign,
|
||||
Center = bindings::AlignType_CenterAlign,
|
||||
Right = bindings::AlignType_RightAlign,
|
||||
}
|
||||
|
||||
impl Default for AlignType {
|
||||
fn default() -> Self {
|
||||
return AlignType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AlignType> for bindings::AlignType {
|
||||
fn from(value: AlignType) -> Self {
|
||||
return value as bindings::AlignType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::AlignType> for AlignType {
|
||||
fn from(value: bindings::AlignType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `AlignType` has the same repr as `bindings::AlignType` - u32
|
||||
*
|
||||
* If `value` is less than Right than it is in the vaild range and can be safely
|
||||
* reinterpreted as `AlignType`
|
||||
*/
|
||||
if value <= bindings::AlignType_RightAlign {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return AlignType::default();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
22
src/types/auto_threshold_method.rs
Normal file
22
src/types/auto_threshold_method.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum AutoThresholdMethod {
|
||||
Undefined = bindings::AutoThresholdMethod_UndefinedThresholdMethod,
|
||||
Kapur = bindings::AutoThresholdMethod_KapurThresholdMethod,
|
||||
OTSU = bindings::AutoThresholdMethod_OTSUThresholdMethod,
|
||||
Triangle = bindings::AutoThresholdMethod_TriangleThresholdMethod,
|
||||
}
|
||||
|
||||
impl Default for AutoThresholdMethod {
|
||||
fn default() -> Self {
|
||||
return AutoThresholdMethod::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AutoThresholdMethod> for bindings::AutoThresholdMethod {
|
||||
fn from(value: AutoThresholdMethod) -> Self {
|
||||
return value as bindings::AutoThresholdMethod;
|
||||
}
|
||||
}
|
||||
105
src/types/channel_type.rs
Normal file
105
src/types/channel_type.rs
Normal file
@ -0,0 +1,105 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ChannelType {
|
||||
Undefined,
|
||||
RedChannel,
|
||||
GrayChannel,
|
||||
CyanChannel,
|
||||
LChannel,
|
||||
GreenChannel,
|
||||
MagentaChannel,
|
||||
aChannel,
|
||||
BlueChannel,
|
||||
bChannel,
|
||||
YellowChannel,
|
||||
BlackChannel,
|
||||
AlphaChannel,
|
||||
OpacityChannel,
|
||||
IndexChannel,
|
||||
ReadMaskChannel,
|
||||
WriteMaskChannel,
|
||||
MetaChannel,
|
||||
CompositeMaskChannel,
|
||||
CompositeChannels,
|
||||
AllChannels,
|
||||
TrueAlphaChannel,
|
||||
RGBChannels,
|
||||
GrayChannels,
|
||||
SyncChannels,
|
||||
DefaultChannels,
|
||||
}
|
||||
|
||||
impl Default for ChannelType {
|
||||
fn default() -> Self {
|
||||
return ChannelType::DefaultChannels;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ChannelType> for bindings::ChannelType {
|
||||
fn from(value: ChannelType) -> Self {
|
||||
match value {
|
||||
ChannelType::Undefined => { bindings::ChannelType_UndefinedChannel },
|
||||
ChannelType::RedChannel => { bindings::ChannelType_RedChannel },
|
||||
ChannelType::GrayChannel => { bindings::ChannelType_GrayChannel },
|
||||
ChannelType::CyanChannel => { bindings::ChannelType_CyanChannel },
|
||||
ChannelType::LChannel => { bindings::ChannelType_LChannel },
|
||||
ChannelType::GreenChannel => { bindings::ChannelType_GreenChannel },
|
||||
ChannelType::MagentaChannel => { bindings::ChannelType_MagentaChannel },
|
||||
ChannelType::aChannel => { bindings::ChannelType_aChannel },
|
||||
ChannelType::BlueChannel => { bindings::ChannelType_BlueChannel },
|
||||
ChannelType::bChannel => { bindings::ChannelType_bChannel },
|
||||
ChannelType::YellowChannel => { bindings::ChannelType_YellowChannel },
|
||||
ChannelType::BlackChannel => { bindings::ChannelType_BlackChannel },
|
||||
ChannelType::AlphaChannel => { bindings::ChannelType_AlphaChannel },
|
||||
ChannelType::OpacityChannel => { bindings::ChannelType_OpacityChannel },
|
||||
ChannelType::IndexChannel => { bindings::ChannelType_IndexChannel },
|
||||
ChannelType::ReadMaskChannel => { bindings::ChannelType_ReadMaskChannel },
|
||||
ChannelType::WriteMaskChannel => { bindings::ChannelType_WriteMaskChannel },
|
||||
ChannelType::MetaChannel => { bindings::ChannelType_MetaChannel },
|
||||
ChannelType::CompositeMaskChannel => { bindings::ChannelType_CompositeMaskChannel },
|
||||
ChannelType::CompositeChannels => { bindings::ChannelType_CompositeChannels },
|
||||
ChannelType::AllChannels => { bindings::ChannelType_AllChannels },
|
||||
ChannelType::TrueAlphaChannel => { bindings::ChannelType_TrueAlphaChannel },
|
||||
ChannelType::RGBChannels => { bindings::ChannelType_RGBChannels },
|
||||
ChannelType::GrayChannels => { bindings::ChannelType_GrayChannels },
|
||||
ChannelType::SyncChannels => { bindings::ChannelType_SyncChannels },
|
||||
ChannelType::DefaultChannels => { bindings::ChannelType_DefaultChannels },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::ChannelType> for ChannelType {
|
||||
fn from(value: bindings::ChannelType) -> Self {
|
||||
// Unreachable match arms commented out
|
||||
match value {
|
||||
bindings::ChannelType_UndefinedChannel => { ChannelType::Undefined },
|
||||
bindings::ChannelType_RedChannel => { ChannelType::RedChannel },
|
||||
// bindings::ChannelType_GrayChannel => { ChannelType::GrayChannel },
|
||||
// bindings::ChannelType_CyanChannel => { ChannelType::CyanChannel },
|
||||
// bindings::ChannelType_LChannel => { ChannelType::LChannel },
|
||||
bindings::ChannelType_GreenChannel => { ChannelType::GreenChannel },
|
||||
// bindings::ChannelType_MagentaChannel => { ChannelType::MagentaChannel },
|
||||
// bindings::ChannelType_aChannel => { ChannelType::aChannel },
|
||||
bindings::ChannelType_BlueChannel => { ChannelType::BlueChannel },
|
||||
// bindings::ChannelType_bChannel => { ChannelType::bChannel },
|
||||
// bindings::ChannelType_YellowChannel => { ChannelType::YellowChannel },
|
||||
bindings::ChannelType_BlackChannel => { ChannelType::BlackChannel },
|
||||
bindings::ChannelType_AlphaChannel => { ChannelType::AlphaChannel },
|
||||
// bindings::ChannelType_OpacityChannel => { ChannelType::OpacityChannel },
|
||||
bindings::ChannelType_IndexChannel => { ChannelType::IndexChannel },
|
||||
bindings::ChannelType_ReadMaskChannel => { ChannelType::ReadMaskChannel },
|
||||
bindings::ChannelType_WriteMaskChannel => { ChannelType::WriteMaskChannel },
|
||||
bindings::ChannelType_MetaChannel => { ChannelType::MetaChannel },
|
||||
bindings::ChannelType_CompositeMaskChannel => { ChannelType::CompositeMaskChannel },
|
||||
bindings::ChannelType_CompositeChannels => { ChannelType::CompositeChannels },
|
||||
bindings::ChannelType_AllChannels => { ChannelType::AllChannels },
|
||||
// bindings::ChannelType_TrueAlphaChannel => { ChannelType::TrueAlphaChannel },
|
||||
// bindings::ChannelType_RGBChannels => { ChannelType::RGBChannels },
|
||||
bindings::ChannelType_GrayChannels => { ChannelType::GrayChannels },
|
||||
bindings::ChannelType_SyncChannels => { ChannelType::SyncChannels },
|
||||
// bindings::ChannelType_DefaultChannels => { ChannelType::DefaultChannels },
|
||||
_ => { ChannelType::Undefined },
|
||||
}
|
||||
}
|
||||
}
|
||||
39
src/types/clip_path_units.rs
Normal file
39
src/types/clip_path_units.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum ClipPathUnits {
|
||||
Undefined = bindings::ClipPathUnits_UndefinedPathUnits,
|
||||
UserSpace = bindings::ClipPathUnits_UserSpace,
|
||||
UserSpaceOnUse = bindings::ClipPathUnits_UserSpaceOnUse,
|
||||
ObjectBoundingBox = bindings::ClipPathUnits_ObjectBoundingBox,
|
||||
}
|
||||
|
||||
impl Default for ClipPathUnits {
|
||||
fn default() -> Self {
|
||||
return ClipPathUnits::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ClipPathUnits> for bindings::ClipPathUnits {
|
||||
fn from(value: ClipPathUnits) -> Self {
|
||||
return value as bindings::ClipPathUnits;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::ClipPathUnits> for ClipPathUnits {
|
||||
fn from(value: bindings::ClipPathUnits) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `ClipPathUnits` has the same repr as `bindings::ClipPathUnits` - u32
|
||||
*
|
||||
* If `value` is less than ObjectBoundingBox than it is in the vaild range and can be safely
|
||||
* reinterpreted as `ClipPathUnits`
|
||||
*/
|
||||
if value <= bindings::ClipPathUnits_ObjectBoundingBox {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return ClipPathUnits::default();
|
||||
}
|
||||
}
|
||||
64
src/types/compression_type.rs
Normal file
64
src/types/compression_type.rs
Normal file
@ -0,0 +1,64 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum CompressionType {
|
||||
Undefined = bindings::CompressionType_UndefinedCompression,
|
||||
B44A = bindings::CompressionType_B44ACompression,
|
||||
B44 = bindings::CompressionType_B44Compression,
|
||||
BZip = bindings::CompressionType_BZipCompression,
|
||||
DXT1 = bindings::CompressionType_DXT1Compression,
|
||||
DXT3 = bindings::CompressionType_DXT3Compression,
|
||||
DXT5 = bindings::CompressionType_DXT5Compression,
|
||||
Fax = bindings::CompressionType_FaxCompression,
|
||||
Group4 = bindings::CompressionType_Group4Compression,
|
||||
JBIG1 = bindings::CompressionType_JBIG1Compression,
|
||||
JBIG2 = bindings::CompressionType_JBIG2Compression,
|
||||
JPEG2000 = bindings::CompressionType_JPEG2000Compression,
|
||||
JPEG = bindings::CompressionType_JPEGCompression,
|
||||
LosslessJPEG = bindings::CompressionType_LosslessJPEGCompression,
|
||||
LZMA = bindings::CompressionType_LZMACompression,
|
||||
LZW = bindings::CompressionType_LZWCompression,
|
||||
No = bindings::CompressionType_NoCompression,
|
||||
Piz = bindings::CompressionType_PizCompression,
|
||||
Pxr24 = bindings::CompressionType_Pxr24Compression,
|
||||
RLE = bindings::CompressionType_RLECompression,
|
||||
Zip = bindings::CompressionType_ZipCompression,
|
||||
ZipS = bindings::CompressionType_ZipSCompression,
|
||||
Zstd = bindings::CompressionType_ZstdCompression,
|
||||
WebP = bindings::CompressionType_WebPCompression,
|
||||
DWAA = bindings::CompressionType_DWAACompression,
|
||||
DWAB = bindings::CompressionType_DWABCompression,
|
||||
BC7 = bindings::CompressionType_BC7Compression,
|
||||
BC5 = bindings::CompressionType_BC5Compression,
|
||||
LERC = bindings::CompressionType_LERCCompression,
|
||||
}
|
||||
|
||||
impl Default for CompressionType {
|
||||
fn default() -> Self {
|
||||
return CompressionType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CompressionType> for bindings::CompressionType {
|
||||
fn from(value: CompressionType) -> Self {
|
||||
return value as bindings::CompressionType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::CompressionType> for CompressionType {
|
||||
fn from(value: bindings::CompressionType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `CompressionType` has the same repr as `bindings::CompressionType` - u32
|
||||
*
|
||||
* If `value` is less than LERC than it is in the vaild range and can be safely
|
||||
* reinterpreted as `CompressionType`
|
||||
*/
|
||||
if value <= bindings::CompressionType_LERCCompression {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return CompressionType::default();
|
||||
}
|
||||
}
|
||||
40
src/types/decoration_type.rs
Normal file
40
src/types/decoration_type.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum DecorationType {
|
||||
Undefined = bindings::DecorationType_UndefinedDecoration,
|
||||
No = bindings::DecorationType_NoDecoration,
|
||||
Underline = bindings::DecorationType_UnderlineDecoration,
|
||||
Overline = bindings::DecorationType_OverlineDecoration,
|
||||
LineThrough = bindings::DecorationType_LineThroughDecoration,
|
||||
}
|
||||
|
||||
impl Default for DecorationType {
|
||||
fn default() -> Self {
|
||||
return DecorationType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DecorationType> for bindings::DecorationType {
|
||||
fn from(value: DecorationType) -> Self {
|
||||
return value as bindings::DecorationType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::DecorationType> for DecorationType {
|
||||
fn from(value: bindings::DecorationType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `DecorationType` has the same repr as `bindings::DecorationType` - u32
|
||||
*
|
||||
* If `value` is less than LineThrough than it is in the vaild range and can be safely
|
||||
* reinterpreted as `DecorationType`
|
||||
*/
|
||||
if value <= bindings::DecorationType_LineThroughDecoration {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return DecorationType::default();
|
||||
}
|
||||
}
|
||||
39
src/types/direction_type.rs
Normal file
39
src/types/direction_type.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum DirectionType {
|
||||
Undefined = bindings::DirectionType_UndefinedDirection,
|
||||
RightToLeft = bindings::DirectionType_RightToLeftDirection,
|
||||
LeftToRight = bindings::DirectionType_LeftToRightDirection,
|
||||
TopToBottom = bindings::DirectionType_TopToBottomDirection,
|
||||
}
|
||||
|
||||
impl Default for DirectionType {
|
||||
fn default() -> Self {
|
||||
return DirectionType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DirectionType> for bindings::DirectionType {
|
||||
fn from(value: DirectionType) -> Self {
|
||||
return value as bindings::DirectionType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::DirectionType> for DirectionType {
|
||||
fn from(value: bindings::DirectionType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `DirectionType` has the same repr as `bindings::DirectionType` - u32
|
||||
*
|
||||
* If `value` is less than TopToBottom than it is in the vaild range and can be safely
|
||||
* reinterpreted as `DirectionType`
|
||||
*/
|
||||
if value <= bindings::DirectionType_TopToBottomDirection {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return DirectionType::default();
|
||||
}
|
||||
}
|
||||
43
src/types/dispose_type.rs
Normal file
43
src/types/dispose_type.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum DisposeType {
|
||||
/*
|
||||
* Identical to `Undefined`
|
||||
*/
|
||||
// Unrecognized = bindings::DisposeType_UnrecognizedDispose,
|
||||
Undefined = bindings::DisposeType_UndefinedDispose,
|
||||
None = bindings::DisposeType_NoneDispose,
|
||||
Background = bindings::DisposeType_BackgroundDispose,
|
||||
Previous = bindings::DisposeType_PreviousDispose,
|
||||
}
|
||||
|
||||
impl Default for DisposeType {
|
||||
fn default() -> Self {
|
||||
return DisposeType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DisposeType> for bindings::DisposeType {
|
||||
fn from(value: DisposeType) -> Self {
|
||||
return value as bindings::DisposeType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::DisposeType> for DisposeType {
|
||||
fn from(value: bindings::DisposeType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `DisposeType` has the same repr as `bindings::DisposeType` - u32
|
||||
*
|
||||
* If `value` is less than Previous than it is in the vaild range and can be safely
|
||||
* reinterpreted as `DisposeType`
|
||||
*/
|
||||
if value <= bindings::DisposeType_PreviousDispose {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return DisposeType::default();
|
||||
}
|
||||
}
|
||||
38
src/types/endian_type.rs
Normal file
38
src/types/endian_type.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum EndianType {
|
||||
Undefined = bindings::EndianType_UndefinedEndian,
|
||||
LSB = bindings::EndianType_LSBEndian,
|
||||
MSB = bindings::EndianType_MSBEndian,
|
||||
}
|
||||
|
||||
impl Default for EndianType {
|
||||
fn default() -> Self {
|
||||
return EndianType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EndianType> for bindings::EndianType {
|
||||
fn from(value: EndianType) -> Self {
|
||||
return value as bindings::EndianType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::EndianType> for EndianType {
|
||||
fn from(value: bindings::EndianType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `EndianType` has the same repr as `bindings::EndianType` - u32
|
||||
*
|
||||
* If `value` is less than MSB than it is in the vaild range and can be safely
|
||||
* reinterpreted as `EndianType`
|
||||
*/
|
||||
if value <= bindings::EndianType_MSBEndian {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return EndianType::default();
|
||||
}
|
||||
}
|
||||
38
src/types/fill_rule.rs
Normal file
38
src/types/fill_rule.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum FillRule {
|
||||
Undefined = bindings::FillRule_UndefinedRule,
|
||||
EvenOdd = bindings::FillRule_EvenOddRule,
|
||||
NonZero = bindings::FillRule_NonZeroRule,
|
||||
}
|
||||
|
||||
impl Default for FillRule {
|
||||
fn default() -> Self {
|
||||
return FillRule::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FillRule> for bindings::FillRule {
|
||||
fn from(value: FillRule) -> Self {
|
||||
return value as bindings::FillRule;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::FillRule> for FillRule {
|
||||
fn from(value: bindings::FillRule) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `FillRule` has the same repr as `bindings::FillRule` - u32
|
||||
*
|
||||
* If `value` is less than NonZero than it is in the vaild range and can be safely
|
||||
* reinterpreted as `FillRule`
|
||||
*/
|
||||
if value <= bindings::FillRule_NonZeroRule {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return FillRule::default();
|
||||
}
|
||||
}
|
||||
37
src/types/geometry_info.rs
Normal file
37
src/types/geometry_info.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use crate::bindings;
|
||||
|
||||
pub type GeometryInfo = bindings::GeometryInfo;
|
||||
|
||||
impl GeometryInfo {
|
||||
pub fn new() -> GeometryInfo {
|
||||
return GeometryInfo {
|
||||
rho: 0.0,
|
||||
sigma: 0.0,
|
||||
xi: 0.0,
|
||||
psi: 0.0,
|
||||
chi: 0.0,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn set_rho(&mut self, rho: f64) {
|
||||
self.rho = rho;
|
||||
}
|
||||
pub fn set_sigma(&mut self, sigma: f64) {
|
||||
self.sigma = sigma;
|
||||
}
|
||||
pub fn set_xi(&mut self, xi: f64) {
|
||||
self.xi = xi;
|
||||
}
|
||||
pub fn set_psi(&mut self, psi: f64) {
|
||||
self.psi = psi;
|
||||
}
|
||||
pub fn set_chi(&mut self, chi: f64) {
|
||||
self.chi = chi;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GeometryInfo {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
21
src/types/image.rs
Normal file
21
src/types/image.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::bindings;
|
||||
|
||||
pub struct Image<'a> {
|
||||
image: *mut bindings::Image,
|
||||
phantom_data: PhantomData<&'a bindings::Image>,
|
||||
}
|
||||
|
||||
impl Image<'_> {
|
||||
pub unsafe fn new(img: *mut bindings::Image) -> Self {
|
||||
Image {
|
||||
image: img,
|
||||
phantom_data: PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn get_ptr(&self) -> *mut bindings::Image {
|
||||
self.image
|
||||
}
|
||||
}
|
||||
47
src/types/image_type.rs
Normal file
47
src/types/image_type.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum ImageType {
|
||||
Undefined = bindings::ImageType_UndefinedType,
|
||||
Bilevel = bindings::ImageType_BilevelType,
|
||||
Grayscale = bindings::ImageType_GrayscaleType,
|
||||
GrayscaleAlpha = bindings::ImageType_GrayscaleAlphaType,
|
||||
Palette = bindings::ImageType_PaletteType,
|
||||
PaletteAlpha = bindings::ImageType_PaletteAlphaType,
|
||||
TrueColor = bindings::ImageType_TrueColorType,
|
||||
TrueColorAlpha = bindings::ImageType_TrueColorAlphaType,
|
||||
ColorSeparation = bindings::ImageType_ColorSeparationType,
|
||||
ColorSeparationAlpha = bindings::ImageType_ColorSeparationAlphaType,
|
||||
Optimize = bindings::ImageType_OptimizeType,
|
||||
PaletteBilevelAlpha = bindings::ImageType_PaletteBilevelAlphaType,
|
||||
}
|
||||
|
||||
impl Default for ImageType {
|
||||
fn default() -> Self {
|
||||
return ImageType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ImageType> for bindings::ImageType {
|
||||
fn from(value: ImageType) -> Self {
|
||||
return value as bindings::ImageType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::ImageType> for ImageType {
|
||||
fn from(value: bindings::ImageType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `ImageType` has the same repr as `bindings::ImageType` - u32
|
||||
*
|
||||
* If `value` is less than SouthEast than it is in the vaild range and can be safely
|
||||
* reinterpreted as `ImageType`
|
||||
*/
|
||||
if value <= bindings::ImageType_PaletteBilevelAlphaType {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return ImageType::default();
|
||||
}
|
||||
}
|
||||
43
src/types/interlace_type.rs
Normal file
43
src/types/interlace_type.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum InterlaceType {
|
||||
Undefined = bindings::InterlaceType_UndefinedInterlace,
|
||||
No = bindings::InterlaceType_NoInterlace,
|
||||
Line = bindings::InterlaceType_LineInterlace,
|
||||
Plane = bindings::InterlaceType_PlaneInterlace,
|
||||
Partition = bindings::InterlaceType_PartitionInterlace,
|
||||
GIF = bindings::InterlaceType_GIFInterlace,
|
||||
JPEG = bindings::InterlaceType_JPEGInterlace,
|
||||
PNG = bindings::InterlaceType_PNGInterlace,
|
||||
}
|
||||
|
||||
impl Default for InterlaceType {
|
||||
fn default() -> Self {
|
||||
return InterlaceType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InterlaceType> for bindings::InterlaceType {
|
||||
fn from(value: InterlaceType) -> Self {
|
||||
return value as bindings::InterlaceType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::InterlaceType> for InterlaceType {
|
||||
fn from(value: bindings::InterlaceType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `InterlaceType` has the same repr as `bindings::InterlaceType` - u32
|
||||
*
|
||||
* If `value` is less than PNG than it is in the vaild range and can be safely
|
||||
* reinterpreted as `InterlaceType`
|
||||
*/
|
||||
if value <= bindings::InterlaceType_PNGInterlace {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return InterlaceType::default();
|
||||
}
|
||||
}
|
||||
390
src/types/kernel.rs
Normal file
390
src/types/kernel.rs
Normal file
@ -0,0 +1,390 @@
|
||||
use std::ffi::CString;
|
||||
|
||||
use crate::bindings;
|
||||
use crate::{Result, MagickError};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum KernelInfoType {
|
||||
Undefined = bindings::KernelInfoType_UndefinedKernel,
|
||||
Unity = bindings::KernelInfoType_UnityKernel,
|
||||
Gaussian = bindings::KernelInfoType_GaussianKernel,
|
||||
DoG = bindings::KernelInfoType_DoGKernel,
|
||||
LoG = bindings::KernelInfoType_LoGKernel,
|
||||
Blur = bindings::KernelInfoType_BlurKernel,
|
||||
Comet = bindings::KernelInfoType_CometKernel,
|
||||
Binomial = bindings::KernelInfoType_BinomialKernel,
|
||||
Laplacian = bindings::KernelInfoType_LaplacianKernel,
|
||||
Sobel = bindings::KernelInfoType_SobelKernel,
|
||||
FreiChen = bindings::KernelInfoType_FreiChenKernel,
|
||||
Roberts = bindings::KernelInfoType_RobertsKernel,
|
||||
Prewitt = bindings::KernelInfoType_PrewittKernel,
|
||||
Compass = bindings::KernelInfoType_CompassKernel,
|
||||
Kirsch = bindings::KernelInfoType_KirschKernel,
|
||||
Diamond = bindings::KernelInfoType_DiamondKernel,
|
||||
Square = bindings::KernelInfoType_SquareKernel,
|
||||
Rectangle = bindings::KernelInfoType_RectangleKernel,
|
||||
Octagon = bindings::KernelInfoType_OctagonKernel,
|
||||
Disk = bindings::KernelInfoType_DiskKernel,
|
||||
Plus = bindings::KernelInfoType_PlusKernel,
|
||||
Cross = bindings::KernelInfoType_CrossKernel,
|
||||
Ring = bindings::KernelInfoType_RingKernel,
|
||||
Peaks = bindings::KernelInfoType_PeaksKernel,
|
||||
Edges = bindings::KernelInfoType_EdgesKernel,
|
||||
Corners = bindings::KernelInfoType_CornersKernel,
|
||||
Diagonals = bindings::KernelInfoType_DiagonalsKernel,
|
||||
LineEnds = bindings::KernelInfoType_LineEndsKernel,
|
||||
LineJunctions = bindings::KernelInfoType_LineJunctionsKernel,
|
||||
Ridges = bindings::KernelInfoType_RidgesKernel,
|
||||
ConvexHull = bindings::KernelInfoType_ConvexHullKernel,
|
||||
ThinSE = bindings::KernelInfoType_ThinSEKernel,
|
||||
Skeleton = bindings::KernelInfoType_SkeletonKernel,
|
||||
Chebyshev = bindings::KernelInfoType_ChebyshevKernel,
|
||||
Manhattan = bindings::KernelInfoType_ManhattanKernel,
|
||||
Octagonal = bindings::KernelInfoType_OctagonalKernel,
|
||||
Euclidean = bindings::KernelInfoType_EuclideanKernel,
|
||||
UserDefined = bindings::KernelInfoType_UserDefinedKernel,
|
||||
}
|
||||
|
||||
impl Default for KernelInfoType {
|
||||
fn default() -> Self {
|
||||
return KernelInfoType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KernelInfoType> for bindings::KernelInfoType {
|
||||
fn from(value: KernelInfoType) -> Self {
|
||||
return value as bindings::KernelInfoType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum MorphologyMethod {
|
||||
Undefined = bindings::MorphologyMethod_UndefinedMorphology,
|
||||
Convolve = bindings::MorphologyMethod_ConvolveMorphology,
|
||||
Correlate = bindings::MorphologyMethod_CorrelateMorphology,
|
||||
Erode = bindings::MorphologyMethod_ErodeMorphology,
|
||||
Dilate = bindings::MorphologyMethod_DilateMorphology,
|
||||
ErodeIntensity = bindings::MorphologyMethod_ErodeIntensityMorphology,
|
||||
DilateIntensity = bindings::MorphologyMethod_DilateIntensityMorphology,
|
||||
IterativeDistance = bindings::MorphologyMethod_IterativeDistanceMorphology,
|
||||
Open = bindings::MorphologyMethod_OpenMorphology,
|
||||
Close = bindings::MorphologyMethod_CloseMorphology,
|
||||
OpenIntensity = bindings::MorphologyMethod_OpenIntensityMorphology,
|
||||
CloseIntensity = bindings::MorphologyMethod_CloseIntensityMorphology,
|
||||
Smooth = bindings::MorphologyMethod_SmoothMorphology,
|
||||
EdgeIn = bindings::MorphologyMethod_EdgeInMorphology,
|
||||
EdgeOut = bindings::MorphologyMethod_EdgeOutMorphology,
|
||||
Edge = bindings::MorphologyMethod_EdgeMorphology,
|
||||
TopHat = bindings::MorphologyMethod_TopHatMorphology,
|
||||
BottomHat = bindings::MorphologyMethod_BottomHatMorphology,
|
||||
HitAndMiss = bindings::MorphologyMethod_HitAndMissMorphology,
|
||||
Thinning = bindings::MorphologyMethod_ThinningMorphology,
|
||||
Thicken = bindings::MorphologyMethod_ThickenMorphology,
|
||||
Distance = bindings::MorphologyMethod_DistanceMorphology,
|
||||
Voronoi = bindings::MorphologyMethod_VoronoiMorphology,
|
||||
}
|
||||
|
||||
impl Default for MorphologyMethod {
|
||||
fn default() -> Self {
|
||||
return MorphologyMethod::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MorphologyMethod> for bindings::KernelInfoType {
|
||||
fn from(value: MorphologyMethod) -> Self {
|
||||
return value as bindings::MorphologyMethod;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// Builder, that creates instances of [KernelInfo](self::KernelInfo)
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Here is an example of how you can use this struct to create a kernel to convolve an image:
|
||||
///
|
||||
/// ```
|
||||
/// use magick_rust::{MagickWand, PixelWand, KernelBuilder};
|
||||
///
|
||||
/// fn main() -> Result<(), magick_rust::MagickError> {
|
||||
/// let mut wand1 = MagickWand::new();
|
||||
/// wand1.new_image(4, 4, &PixelWand::new())?; // Replace with `read_image` to open your image file
|
||||
/// let wand2 = wand1.clone();
|
||||
///
|
||||
/// let kernel_info = KernelBuilder::new()
|
||||
/// .set_size((3, 3))
|
||||
/// .set_center((1, 1)) // Not really needed here - the center is in the middle of kernel
|
||||
/// // by default
|
||||
/// .set_values(&[0.111, 0.111, 0.111,
|
||||
/// 0.111, 0.111, 0.111,
|
||||
/// 0.111, 0.111, 0.111])
|
||||
/// .build()?;
|
||||
///
|
||||
/// wand1.convolve_image(&kernel_info)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Here is an example of how you can use this struct to create builtin kernel to gaussian blur an
|
||||
/// image (not the best way to do it, just an example):
|
||||
///
|
||||
/// ```
|
||||
/// use magick_rust::{MagickWand, PixelWand, KernelBuilder, KernelInfoType, GeometryInfo};
|
||||
///
|
||||
/// fn main() -> Result<(), magick_rust::MagickError> {
|
||||
/// let mut wand1 = MagickWand::new();
|
||||
/// wand1.new_image(4, 4, &PixelWand::new())?; // Replace with `read_image` to open your image file
|
||||
/// let wand2 = wand1.clone();
|
||||
///
|
||||
/// let mut geom_info = GeometryInfo::new();
|
||||
/// geom_info.set_sigma(15.0);
|
||||
/// let kernel_info = KernelBuilder::new()
|
||||
/// .set_info_type(KernelInfoType::Gaussian)
|
||||
/// .set_geom_info(geom_info)
|
||||
/// .build_builtin()?;
|
||||
///
|
||||
/// wand1.convolve_image(&kernel_info)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct KernelBuilder {
|
||||
size: Option<(usize, usize)>,
|
||||
center: Option<(usize, usize)>,
|
||||
values: Option<Vec<f64>>,
|
||||
|
||||
info_type: Option<KernelInfoType>,
|
||||
geom_info: Option<crate::GeometryInfo>,
|
||||
}
|
||||
|
||||
impl KernelBuilder {
|
||||
pub fn new() -> KernelBuilder {
|
||||
return KernelBuilder {
|
||||
size: None,
|
||||
center: None,
|
||||
values: None,
|
||||
|
||||
info_type: None,
|
||||
geom_info: None,
|
||||
};
|
||||
}
|
||||
|
||||
/// Used for user defined kernels
|
||||
pub fn set_size(mut self, size: (usize, usize)) -> KernelBuilder {
|
||||
self.size = Some(size);
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Used for user defined kernels
|
||||
pub fn set_center(mut self, center: (usize, usize)) -> KernelBuilder {
|
||||
self.center = Some(center);
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Used for user defined kernels
|
||||
pub fn set_values(mut self, values: &[f64]) -> KernelBuilder {
|
||||
self.values = Some(values.into());
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn build(&self) -> Result<KernelInfo> {
|
||||
let size = self.size.ok_or(MagickError("no kernel size given"))?;
|
||||
let values = self.values.as_ref().ok_or(MagickError("no kernel values given"))?;
|
||||
|
||||
if values.len() != size.0 * size.1 {
|
||||
return Err(MagickError("kernel size doesn't match kernel values size"));
|
||||
}
|
||||
|
||||
// Create kernel string
|
||||
let mut kernel_string = if let Some(center) = self.center {
|
||||
format!(
|
||||
"{}x{}+{}+{}:",
|
||||
size.0,
|
||||
size.1,
|
||||
center.0,
|
||||
center.1
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"{}x{}:",
|
||||
size.0,
|
||||
size.1,
|
||||
)
|
||||
};
|
||||
|
||||
// Add values
|
||||
values.iter().for_each(|x| {
|
||||
kernel_string.push_str(&format!("{x},"));
|
||||
});
|
||||
|
||||
// Remove trailing ","
|
||||
kernel_string.pop();
|
||||
|
||||
// Create null terminated string
|
||||
let c_kernel_string = CString::new(kernel_string).expect("CString::new() has failed");
|
||||
|
||||
// Create kernel info
|
||||
let kernel_info = unsafe {
|
||||
bindings::AcquireKernelInfo(
|
||||
c_kernel_string.as_ptr(),
|
||||
std::ptr::null_mut()
|
||||
)
|
||||
};
|
||||
|
||||
if kernel_info.is_null() {
|
||||
return Err(MagickError("failed to acquire kernel info"));
|
||||
}
|
||||
|
||||
Ok(KernelInfo::new(kernel_info))
|
||||
}
|
||||
|
||||
/// Used for builtin kernels
|
||||
pub fn set_info_type(mut self, info_type: KernelInfoType) -> KernelBuilder {
|
||||
self.info_type = Some(info_type);
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Used for builtin kernels
|
||||
pub fn set_geom_info(mut self, geom_info: crate::GeometryInfo) -> KernelBuilder {
|
||||
self.geom_info = Some(geom_info);
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn build_builtin(&self) -> Result<KernelInfo> {
|
||||
let info_type = self.info_type.ok_or(MagickError("no info type given"))?;
|
||||
let mut geom_info = self.geom_info.ok_or(MagickError("no geometry info given"))?;
|
||||
|
||||
// Create kernel info
|
||||
let kernel_info = unsafe {
|
||||
bindings::AcquireKernelBuiltIn(
|
||||
info_type.into(),
|
||||
&mut geom_info,
|
||||
std::ptr::null_mut()
|
||||
)
|
||||
};
|
||||
|
||||
if kernel_info.is_null() {
|
||||
return Err(MagickError("failed to acquire builtin kernel info"));
|
||||
}
|
||||
|
||||
Ok(KernelInfo::new(kernel_info))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct KernelInfo {
|
||||
kernel_info: *mut bindings::KernelInfo,
|
||||
}
|
||||
|
||||
impl KernelInfo {
|
||||
fn new(kernel_info: *mut bindings::KernelInfo) -> KernelInfo {
|
||||
return KernelInfo {
|
||||
kernel_info
|
||||
};
|
||||
}
|
||||
|
||||
/// The values within the kernel is scaled directly using given scaling factor without change.
|
||||
pub fn scale(&mut self, factor: f64) {
|
||||
unsafe {
|
||||
bindings::ScaleKernelInfo(
|
||||
self.kernel_info,
|
||||
factor,
|
||||
0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Kernel normalization is designed to ensure that any use of the kernel scaling factor with
|
||||
/// 'Convolve' or 'Correlate' morphology methods will fall into -1.0 to +1.0 range. Note that
|
||||
/// for non-HDRI versions of IM this may cause images to have any negative results clipped,
|
||||
/// unless some 'bias' is used.
|
||||
///
|
||||
/// More specifically. Kernels which only contain positive values (such as a 'Gaussian' kernel)
|
||||
/// will be scaled so that those values sum to +1.0, ensuring a 0.0 to +1.0 output range for
|
||||
/// non-HDRI images.
|
||||
///
|
||||
/// For Kernels that contain some negative values, (such as 'Sharpen' kernels) the kernel will
|
||||
/// be scaled by the absolute of the sum of kernel values, so that it will generally fall
|
||||
/// within the +/- 1.0 range.
|
||||
///
|
||||
/// For kernels whose values sum to zero, (such as 'Laplacian' kernels) kernel will be scaled
|
||||
/// by just the sum of the positive values, so that its output range will again fall into the
|
||||
/// +/- 1.0 range.
|
||||
pub fn normalize(&mut self) {
|
||||
unsafe {
|
||||
bindings::ScaleKernelInfo(
|
||||
self.kernel_info,
|
||||
1.0,
|
||||
bindings::GeometryFlags_NormalizeValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// For special kernels designed for locating shapes using 'Correlate', (often only containing
|
||||
/// +1 and -1 values, representing foreground/background matching) a special normalization
|
||||
/// method is provided to scale the positive values separately to those of the negative values,
|
||||
/// so the kernel will be forced to become a zero-sum kernel better suited to such searches.
|
||||
pub fn correlate_normalize(&mut self) {
|
||||
unsafe {
|
||||
bindings::ScaleKernelInfo(
|
||||
self.kernel_info,
|
||||
1.0,
|
||||
bindings::GeometryFlags_CorrelateNormalizeValue
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a given amount of the 'Unity' Convolution Kernel to the given pre-scaled and
|
||||
/// normalized Kernel. This in effect adds that amount of the original image into the resulting
|
||||
/// convolution kernel. This value is usually provided by the user as a percentage value in the
|
||||
/// 'convolve:scale' setting.
|
||||
///
|
||||
/// The resulting effect is to convert the defined kernels into blended soft-blurs, unsharp
|
||||
/// kernels or into sharpening kernels.
|
||||
pub fn unity_add(&mut self, scale: f64) {
|
||||
unsafe {
|
||||
bindings::UnityAddKernelInfo(
|
||||
self.kernel_info,
|
||||
scale
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn get_ptr(&self) -> *mut bindings::KernelInfo {
|
||||
return self.kernel_info;
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for KernelInfo {
|
||||
fn drop(&mut self) {
|
||||
unsafe { bindings::DestroyKernelInfo(self.kernel_info) };
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for KernelInfo {
|
||||
fn clone(&self) -> Self {
|
||||
let kernel_info = unsafe {
|
||||
bindings::CloneKernelInfo(self.kernel_info)
|
||||
};
|
||||
|
||||
if kernel_info.is_null() {
|
||||
panic!("failed to clone kernel info");
|
||||
}
|
||||
|
||||
return KernelInfo::new(kernel_info);
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for KernelInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
unsafe { write!(f, "{:?}", *self.kernel_info) }
|
||||
}
|
||||
}
|
||||
35
src/types/layer_method.rs
Normal file
35
src/types/layer_method.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum LayerMethod {
|
||||
Undefined = bindings::LayerMethod_UndefinedLayer,
|
||||
Coalesce = bindings::LayerMethod_CoalesceLayer,
|
||||
CompareAny = bindings::LayerMethod_CompareAnyLayer,
|
||||
CompareClear = bindings::LayerMethod_CompareClearLayer,
|
||||
CompareOverlay = bindings::LayerMethod_CompareOverlayLayer,
|
||||
Dispose = bindings::LayerMethod_DisposeLayer,
|
||||
Optimize = bindings::LayerMethod_OptimizeLayer,
|
||||
OptimizeImage = bindings::LayerMethod_OptimizeImageLayer,
|
||||
OptimizePlus = bindings::LayerMethod_OptimizePlusLayer,
|
||||
OptimizeTrans = bindings::LayerMethod_OptimizeTransLayer,
|
||||
RemoveDups = bindings::LayerMethod_RemoveDupsLayer,
|
||||
RemoveZero = bindings::LayerMethod_RemoveZeroLayer,
|
||||
Composite = bindings::LayerMethod_CompositeLayer,
|
||||
Merge = bindings::LayerMethod_MergeLayer,
|
||||
Flatten = bindings::LayerMethod_FlattenLayer,
|
||||
Mosaic = bindings::LayerMethod_MosaicLayer,
|
||||
TrimBounds = bindings::LayerMethod_TrimBoundsLayer,
|
||||
}
|
||||
|
||||
impl Default for LayerMethod {
|
||||
fn default() -> Self {
|
||||
return LayerMethod::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LayerMethod> for bindings::LayerMethod {
|
||||
fn from(value: LayerMethod) -> Self {
|
||||
return value as bindings::LayerMethod;
|
||||
}
|
||||
}
|
||||
39
src/types/line_cap.rs
Normal file
39
src/types/line_cap.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum LineCap {
|
||||
Undefined = bindings::LineCap_UndefinedCap,
|
||||
Butt = bindings::LineCap_ButtCap,
|
||||
Round = bindings::LineCap_RoundCap,
|
||||
Square = bindings::LineCap_SquareCap,
|
||||
}
|
||||
|
||||
impl Default for LineCap {
|
||||
fn default() -> Self {
|
||||
return LineCap::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LineCap> for bindings::LineCap {
|
||||
fn from(value: LineCap) -> Self {
|
||||
return value as bindings::LineCap;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::LineCap> for LineCap {
|
||||
fn from(value: bindings::LineCap) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `LineCap` has the same repr as `bindings::LineCap` - u32
|
||||
*
|
||||
* If `value` is less than Square than it is in the vaild range and can be safely
|
||||
* reinterpreted as `LineCap`
|
||||
*/
|
||||
if value <= bindings::LineCap_SquareCap {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return LineCap::default();
|
||||
}
|
||||
}
|
||||
39
src/types/line_join.rs
Normal file
39
src/types/line_join.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum LineJoin {
|
||||
Undefined = bindings::LineJoin_UndefinedJoin,
|
||||
Miter = bindings::LineJoin_MiterJoin,
|
||||
Round = bindings::LineJoin_RoundJoin,
|
||||
Bevel = bindings::LineJoin_BevelJoin,
|
||||
}
|
||||
|
||||
impl Default for LineJoin {
|
||||
fn default() -> Self {
|
||||
return LineJoin::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LineJoin> for bindings::LineJoin {
|
||||
fn from(value: LineJoin) -> Self {
|
||||
return value as bindings::LineJoin;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::LineJoin> for LineJoin {
|
||||
fn from(value: bindings::LineJoin) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `LineJoin` has the same repr as `bindings::LineJoin` - u32
|
||||
*
|
||||
* If `value` is less than Bevel than it is in the vaild range and can be safely
|
||||
* reinterpreted as `LineJoin`
|
||||
*/
|
||||
if value <= bindings::LineJoin_BevelJoin {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return LineJoin::default();
|
||||
}
|
||||
}
|
||||
52
src/types/magick_evaluate_operator.rs
Normal file
52
src/types/magick_evaluate_operator.rs
Normal file
@ -0,0 +1,52 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum MagickEvaluateOperator {
|
||||
Undefined = bindings::MagickEvaluateOperator_UndefinedEvaluateOperator,
|
||||
Abs = bindings::MagickEvaluateOperator_AbsEvaluateOperator,
|
||||
Add = bindings::MagickEvaluateOperator_AddEvaluateOperator,
|
||||
AddModulus = bindings::MagickEvaluateOperator_AddModulusEvaluateOperator,
|
||||
And = bindings::MagickEvaluateOperator_AndEvaluateOperator,
|
||||
Cosine = bindings::MagickEvaluateOperator_CosineEvaluateOperator,
|
||||
Divide = bindings::MagickEvaluateOperator_DivideEvaluateOperator,
|
||||
Exponential = bindings::MagickEvaluateOperator_ExponentialEvaluateOperator,
|
||||
GaussianNoise = bindings::MagickEvaluateOperator_GaussianNoiseEvaluateOperator,
|
||||
ImpulseNoise = bindings::MagickEvaluateOperator_ImpulseNoiseEvaluateOperator,
|
||||
LaplacianNoise = bindings::MagickEvaluateOperator_LaplacianNoiseEvaluateOperator,
|
||||
LeftShift = bindings::MagickEvaluateOperator_LeftShiftEvaluateOperator,
|
||||
Log = bindings::MagickEvaluateOperator_LogEvaluateOperator,
|
||||
Max = bindings::MagickEvaluateOperator_MaxEvaluateOperator,
|
||||
Mean = bindings::MagickEvaluateOperator_MeanEvaluateOperator,
|
||||
Median = bindings::MagickEvaluateOperator_MedianEvaluateOperator,
|
||||
Min = bindings::MagickEvaluateOperator_MinEvaluateOperator,
|
||||
MultiplicativeNoise = bindings::MagickEvaluateOperator_MultiplicativeNoiseEvaluateOperator,
|
||||
Multiply = bindings::MagickEvaluateOperator_MultiplyEvaluateOperator,
|
||||
Or = bindings::MagickEvaluateOperator_OrEvaluateOperator,
|
||||
PoissonNoise = bindings::MagickEvaluateOperator_PoissonNoiseEvaluateOperator,
|
||||
Pow = bindings::MagickEvaluateOperator_PowEvaluateOperator,
|
||||
RightShift = bindings::MagickEvaluateOperator_RightShiftEvaluateOperator,
|
||||
RootMeanSquare = bindings::MagickEvaluateOperator_RootMeanSquareEvaluateOperator,
|
||||
Set = bindings::MagickEvaluateOperator_SetEvaluateOperator,
|
||||
Sine = bindings::MagickEvaluateOperator_SineEvaluateOperator,
|
||||
Subtract = bindings::MagickEvaluateOperator_SubtractEvaluateOperator,
|
||||
Sum = bindings::MagickEvaluateOperator_SumEvaluateOperator,
|
||||
ThresholdBlack = bindings::MagickEvaluateOperator_ThresholdBlackEvaluateOperator,
|
||||
Threshold = bindings::MagickEvaluateOperator_ThresholdEvaluateOperator,
|
||||
ThresholdWhite = bindings::MagickEvaluateOperator_ThresholdWhiteEvaluateOperator,
|
||||
UniformNoise = bindings::MagickEvaluateOperator_UniformNoiseEvaluateOperator,
|
||||
Xor = bindings::MagickEvaluateOperator_XorEvaluateOperator,
|
||||
InverseLog = bindings::MagickEvaluateOperator_InverseLogEvaluateOperator,
|
||||
}
|
||||
|
||||
impl Default for MagickEvaluateOperator {
|
||||
fn default() -> Self {
|
||||
return MagickEvaluateOperator::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MagickEvaluateOperator> for bindings::MagickEvaluateOperator {
|
||||
fn from(value: MagickEvaluateOperator) -> Self {
|
||||
return value as bindings::MagickEvaluateOperator;
|
||||
}
|
||||
}
|
||||
23
src/types/magick_function.rs
Normal file
23
src/types/magick_function.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum MagickFunction {
|
||||
Undefined = bindings::MagickFunction_UndefinedFunction,
|
||||
Arcsin = bindings::MagickFunction_ArcsinFunction,
|
||||
Arctan = bindings::MagickFunction_ArctanFunction,
|
||||
Polynomial = bindings::MagickFunction_PolynomialFunction,
|
||||
Sinusoid = bindings::MagickFunction_SinusoidFunction,
|
||||
}
|
||||
|
||||
impl Default for MagickFunction {
|
||||
fn default() -> Self {
|
||||
return MagickFunction::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MagickFunction> for bindings::MagickFunction {
|
||||
fn from(value: MagickFunction) -> Self {
|
||||
return value as bindings::MagickFunction;
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,73 @@
|
||||
mod align_type;
|
||||
mod alpha_channel_option;
|
||||
mod auto_threshold_method;
|
||||
mod channel_type;
|
||||
mod clip_path_units;
|
||||
mod colorspace_type;
|
||||
mod composite_operator;
|
||||
mod compression_type;
|
||||
mod decoration_type;
|
||||
mod direction_type;
|
||||
mod dispose_type;
|
||||
mod dither_method;
|
||||
mod endian_type;
|
||||
mod fill_rule;
|
||||
mod filter_type;
|
||||
mod geometry_info;
|
||||
mod gravity_type;
|
||||
mod image;
|
||||
mod image_type;
|
||||
mod interlace_type;
|
||||
mod kernel;
|
||||
mod layer_method;
|
||||
mod line_cap;
|
||||
mod line_join;
|
||||
mod magick_evaluate_operator;
|
||||
mod magick_function;
|
||||
mod metric_type;
|
||||
mod orientation_type;
|
||||
mod pixel_interpolate_method;
|
||||
mod pixel_mask;
|
||||
mod rendering_intent;
|
||||
mod resolution_type;
|
||||
mod resource_type;
|
||||
mod statistic_type;
|
||||
mod stretch_type;
|
||||
mod style_type;
|
||||
|
||||
pub use self::align_type::AlignType;
|
||||
pub use self::alpha_channel_option::AlphaChannelOption;
|
||||
pub use self::auto_threshold_method::AutoThresholdMethod;
|
||||
pub use self::channel_type::ChannelType;
|
||||
pub use self::clip_path_units::ClipPathUnits;
|
||||
pub use self::colorspace_type::ColorspaceType;
|
||||
pub use self::composite_operator::CompositeOperator;
|
||||
pub use self::compression_type::CompressionType;
|
||||
pub use self::decoration_type::DecorationType;
|
||||
pub use self::direction_type::DirectionType;
|
||||
pub use self::dispose_type::DisposeType;
|
||||
pub use self::dither_method::DitherMethod;
|
||||
pub use self::endian_type::EndianType;
|
||||
pub use self::fill_rule::FillRule;
|
||||
pub use self::filter_type::FilterType;
|
||||
pub use self::geometry_info::GeometryInfo;
|
||||
pub use self::gravity_type::GravityType;
|
||||
pub use self::image::Image;
|
||||
pub use self::image_type::ImageType;
|
||||
pub use self::interlace_type::InterlaceType;
|
||||
pub use self::kernel::*;
|
||||
pub use self::layer_method::LayerMethod;
|
||||
pub use self::line_cap::LineCap;
|
||||
pub use self::line_join::LineJoin;
|
||||
pub use self::magick_evaluate_operator::MagickEvaluateOperator;
|
||||
pub use self::magick_function::MagickFunction;
|
||||
pub use self::metric_type::MetricType;
|
||||
pub use self::orientation_type::OrientationType;
|
||||
pub use self::pixel_interpolate_method::PixelInterpolateMethod;
|
||||
pub use self::pixel_mask::PixelMask;
|
||||
pub use self::rendering_intent::RenderingIntent;
|
||||
pub use self::resolution_type::ResolutionType;
|
||||
pub use self::resource_type::ResourceType;
|
||||
pub use self::statistic_type::StatisticType;
|
||||
pub use self::stretch_type::StretchType;
|
||||
pub use self::style_type::StyleType;
|
||||
|
||||
44
src/types/orientation_type.rs
Normal file
44
src/types/orientation_type.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum OrientationType {
|
||||
Undefined = bindings::OrientationType_UndefinedOrientation,
|
||||
TopLeft = bindings::OrientationType_TopLeftOrientation,
|
||||
TopRight = bindings::OrientationType_TopRightOrientation,
|
||||
BottomRight = bindings::OrientationType_BottomRightOrientation,
|
||||
BottomLeft = bindings::OrientationType_BottomLeftOrientation,
|
||||
LeftTop = bindings::OrientationType_LeftTopOrientation,
|
||||
RightTop = bindings::OrientationType_RightTopOrientation,
|
||||
RightBottom = bindings::OrientationType_RightBottomOrientation,
|
||||
LeftBottom = bindings::OrientationType_LeftBottomOrientation,
|
||||
}
|
||||
|
||||
impl Default for OrientationType {
|
||||
fn default() -> Self {
|
||||
return OrientationType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OrientationType> for bindings::OrientationType {
|
||||
fn from(value: OrientationType) -> Self {
|
||||
return value as bindings::OrientationType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::OrientationType> for OrientationType {
|
||||
fn from(value: bindings::OrientationType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `OrientationType` has the same repr as `bindings::OrientationType` - u32
|
||||
*
|
||||
* If `value` is less than LeftBottom than it is in the vaild range and can be safely
|
||||
* reinterpreted as `OrientationType`
|
||||
*/
|
||||
if value <= bindings::OrientationType_LeftBottomOrientation {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return OrientationType::default();
|
||||
}
|
||||
}
|
||||
47
src/types/pixel_interpolate_method.rs
Normal file
47
src/types/pixel_interpolate_method.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum PixelInterpolateMethod {
|
||||
Undefined = bindings::PixelInterpolateMethod_UndefinedInterpolatePixel,
|
||||
Average = bindings::PixelInterpolateMethod_AverageInterpolatePixel,
|
||||
Average9 = bindings::PixelInterpolateMethod_Average9InterpolatePixel,
|
||||
Average16 = bindings::PixelInterpolateMethod_Average16InterpolatePixel,
|
||||
Background = bindings::PixelInterpolateMethod_BackgroundInterpolatePixel,
|
||||
Bilinear = bindings::PixelInterpolateMethod_BilinearInterpolatePixel,
|
||||
Blend = bindings::PixelInterpolateMethod_BlendInterpolatePixel,
|
||||
Catrom = bindings::PixelInterpolateMethod_CatromInterpolatePixel,
|
||||
Integer = bindings::PixelInterpolateMethod_IntegerInterpolatePixel,
|
||||
Mesh = bindings::PixelInterpolateMethod_MeshInterpolatePixel,
|
||||
Nearest = bindings::PixelInterpolateMethod_NearestInterpolatePixel,
|
||||
Spline = bindings::PixelInterpolateMethod_SplineInterpolatePixel,
|
||||
}
|
||||
|
||||
impl Default for PixelInterpolateMethod {
|
||||
fn default() -> Self {
|
||||
return PixelInterpolateMethod::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PixelInterpolateMethod> for bindings::PixelInterpolateMethod {
|
||||
fn from(value: PixelInterpolateMethod) -> Self {
|
||||
return value as bindings::PixelInterpolateMethod;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::PixelInterpolateMethod> for PixelInterpolateMethod {
|
||||
fn from(value: bindings::PixelInterpolateMethod) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `PixelInterpolateMethod` has the same repr as `bindings::PixelInterpolateMethod` - u32
|
||||
*
|
||||
* If `value` is less than Spline than it is in the vaild range and can be safely
|
||||
* reinterpreted as `PixelInterpolateMethod`
|
||||
*/
|
||||
if value <= bindings::PixelInterpolateMethod_SplineInterpolatePixel {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return PixelInterpolateMethod::default();
|
||||
}
|
||||
}
|
||||
22
src/types/pixel_mask.rs
Normal file
22
src/types/pixel_mask.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum PixelMask {
|
||||
Undefined = bindings::PixelMask_UndefinedPixelMask,
|
||||
Read = bindings::PixelMask_ReadPixelMask,
|
||||
Write = bindings::PixelMask_WritePixelMask,
|
||||
Composite = bindings::PixelMask_CompositePixelMask,
|
||||
}
|
||||
|
||||
impl Default for PixelMask {
|
||||
fn default() -> Self {
|
||||
return PixelMask::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PixelMask> for bindings::PixelMask {
|
||||
fn from(value: PixelMask) -> Self {
|
||||
return value as bindings::PixelMask;
|
||||
}
|
||||
}
|
||||
40
src/types/rendering_intent.rs
Normal file
40
src/types/rendering_intent.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum RenderingIntent {
|
||||
Undefined = bindings::RenderingIntent_UndefinedIntent,
|
||||
Saturation = bindings::RenderingIntent_SaturationIntent,
|
||||
Perceptual = bindings::RenderingIntent_PerceptualIntent,
|
||||
Absolute = bindings::RenderingIntent_AbsoluteIntent,
|
||||
Relative = bindings::RenderingIntent_RelativeIntent,
|
||||
}
|
||||
|
||||
impl Default for RenderingIntent {
|
||||
fn default() -> Self {
|
||||
return RenderingIntent::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RenderingIntent> for bindings::RenderingIntent {
|
||||
fn from(value: RenderingIntent) -> Self {
|
||||
return value as bindings::RenderingIntent;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::RenderingIntent> for RenderingIntent {
|
||||
fn from(value: bindings::RenderingIntent) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `RenderingIntent` has the same repr as `bindings::RenderingIntent` - u32
|
||||
*
|
||||
* If `value` is less than Relative than it is in the vaild range and can be safely
|
||||
* reinterpreted as `RenderingIntent`
|
||||
*/
|
||||
if value <= bindings::RenderingIntent_RelativeIntent {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return RenderingIntent::default();
|
||||
}
|
||||
}
|
||||
38
src/types/resolution_type.rs
Normal file
38
src/types/resolution_type.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum ResolutionType {
|
||||
Undefined = bindings::ResolutionType_UndefinedResolution,
|
||||
PixelsPerInch = bindings::ResolutionType_PixelsPerInchResolution,
|
||||
PixelsPerCentimeter = bindings::ResolutionType_PixelsPerCentimeterResolution,
|
||||
}
|
||||
|
||||
impl Default for ResolutionType {
|
||||
fn default() -> Self {
|
||||
return ResolutionType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResolutionType> for bindings::ResolutionType {
|
||||
fn from(value: ResolutionType) -> Self {
|
||||
return value as bindings::ResolutionType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::ResolutionType> for ResolutionType {
|
||||
fn from(value: bindings::ResolutionType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `ResolutionType` has the same repr as `bindings::ResolutionType` - u32
|
||||
*
|
||||
* If `value` is less than PixelsPerCentimeter than it is in the vaild range and can be safely
|
||||
* reinterpreted as `ResolutionType`
|
||||
*/
|
||||
if value <= bindings::ResolutionType_PixelsPerCentimeterResolution {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return ResolutionType::default();
|
||||
}
|
||||
}
|
||||
46
src/types/statistic_type.rs
Normal file
46
src/types/statistic_type.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum StatisticType {
|
||||
Undefined = bindings::StatisticType_UndefinedStatistic,
|
||||
Gradient = bindings::StatisticType_GradientStatistic,
|
||||
Maximum = bindings::StatisticType_MaximumStatistic,
|
||||
Mean = bindings::StatisticType_MeanStatistic,
|
||||
Median = bindings::StatisticType_MedianStatistic,
|
||||
Minimum = bindings::StatisticType_MinimumStatistic,
|
||||
Mode = bindings::StatisticType_ModeStatistic,
|
||||
Nonpeak = bindings::StatisticType_NonpeakStatistic,
|
||||
RootMeanSquare = bindings::StatisticType_RootMeanSquareStatistic,
|
||||
StandardDeviation = bindings::StatisticType_StandardDeviationStatistic,
|
||||
Contrast = bindings::StatisticType_ContrastStatistic,
|
||||
}
|
||||
|
||||
impl Default for StatisticType {
|
||||
fn default() -> Self {
|
||||
return StatisticType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StatisticType> for bindings::StatisticType {
|
||||
fn from(value: StatisticType) -> Self {
|
||||
return value as bindings::StatisticType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::StatisticType> for StatisticType {
|
||||
fn from(value: bindings::StatisticType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `StatisticType` has the same repr as `bindings::StatisticType` - u32
|
||||
*
|
||||
* If `value` is less than Contrast than it is in the vaild range and can be safely
|
||||
* reinterpreted as `StatisticType`
|
||||
*/
|
||||
if value <= bindings::StatisticType_ContrastStatistic {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return StatisticType::default();
|
||||
}
|
||||
}
|
||||
46
src/types/stretch_type.rs
Normal file
46
src/types/stretch_type.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum StretchType {
|
||||
Undefined = bindings::StretchType_UndefinedStretch,
|
||||
Normal = bindings::StretchType_NormalStretch,
|
||||
UltraCondensed = bindings::StretchType_UltraCondensedStretch,
|
||||
ExtraCondensed = bindings::StretchType_ExtraCondensedStretch,
|
||||
Condensed = bindings::StretchType_CondensedStretch,
|
||||
SemiCondensed = bindings::StretchType_SemiCondensedStretch,
|
||||
SemiExpanded = bindings::StretchType_SemiExpandedStretch,
|
||||
Expanded = bindings::StretchType_ExpandedStretch,
|
||||
ExtraExpanded = bindings::StretchType_ExtraExpandedStretch,
|
||||
UltraExpanded = bindings::StretchType_UltraExpandedStretch,
|
||||
Any = bindings::StretchType_AnyStretch,
|
||||
}
|
||||
|
||||
impl Default for StretchType {
|
||||
fn default() -> Self {
|
||||
return StretchType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StretchType> for bindings::StretchType {
|
||||
fn from(value: StretchType) -> Self {
|
||||
return value as bindings::StretchType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::StretchType> for StretchType {
|
||||
fn from(value: bindings::StretchType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `StretchType` has the same repr as `bindings::StretchType` - u32
|
||||
*
|
||||
* If `value` is less than Any than it is in the vaild range and can be safely
|
||||
* reinterpreted as `StretchType`
|
||||
*/
|
||||
if value <= bindings::StretchType_AnyStretch {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return StretchType::default();
|
||||
}
|
||||
}
|
||||
41
src/types/style_type.rs
Normal file
41
src/types/style_type.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use crate::bindings;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum StyleType {
|
||||
Undefined = bindings::StyleType_UndefinedStyle,
|
||||
Normal = bindings::StyleType_NormalStyle,
|
||||
Italic = bindings::StyleType_ItalicStyle,
|
||||
Oblique = bindings::StyleType_ObliqueStyle,
|
||||
Any = bindings::StyleType_AnyStyle,
|
||||
Bold = bindings::StyleType_BoldStyle,
|
||||
}
|
||||
|
||||
impl Default for StyleType {
|
||||
fn default() -> Self {
|
||||
return StyleType::Undefined;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StyleType> for bindings::StyleType {
|
||||
fn from(value: StyleType) -> Self {
|
||||
return value as bindings::StyleType;
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bindings::StyleType> for StyleType {
|
||||
fn from(value: bindings::StyleType) -> Self {
|
||||
/*
|
||||
* SAFETY:
|
||||
*
|
||||
* `StyleType` has the same repr as `bindings::StyleType` - u32
|
||||
*
|
||||
* If `value` is less than Bold than it is in the vaild range and can be safely
|
||||
* reinterpreted as `StyleType`
|
||||
*/
|
||||
if value <= bindings::StyleType_BoldStyle {
|
||||
return unsafe { std::mem::transmute(value) };
|
||||
}
|
||||
return StyleType::default();
|
||||
}
|
||||
}
|
||||
@ -16,15 +16,22 @@
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
use libc::size_t;
|
||||
#[cfg(not(target_os = "freebsd"))]
|
||||
use size_t;
|
||||
|
||||
use bindings;
|
||||
|
||||
use crate::result::MagickError;
|
||||
use crate::result::Result;
|
||||
use crate::{
|
||||
AlignType,
|
||||
ClipPathUnits,
|
||||
DecorationType,
|
||||
DirectionType,
|
||||
FillRule,
|
||||
GravityType,
|
||||
LineCap,
|
||||
LineJoin,
|
||||
StretchType,
|
||||
StyleType,
|
||||
};
|
||||
|
||||
wand_common!(
|
||||
DrawingWand,
|
||||
@ -91,30 +98,30 @@ impl DrawingWand {
|
||||
);
|
||||
|
||||
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_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, bindings::FillRule
|
||||
get_clip_units, set_clip_units, DrawGetClipUnits, DrawSetClipUnits, bindings::ClipPathUnits
|
||||
get_fill_rule, set_fill_rule, DrawGetFillRule, DrawSetFillRule, bindings::FillRule
|
||||
get_clip_rule, set_clip_rule, DrawGetClipRule, DrawSetClipRule, FillRule
|
||||
get_clip_units, set_clip_units, DrawGetClipUnits, DrawSetClipUnits, ClipPathUnits
|
||||
get_fill_rule, set_fill_rule, DrawGetFillRule, DrawSetFillRule, FillRule
|
||||
get_fill_opacity, set_fill_opacity, DrawGetFillOpacity, DrawSetFillOpacity, f64
|
||||
|
||||
get_font_size, set_font_size, DrawGetFontSize, DrawSetFontSize, f64
|
||||
get_font_style, set_font_style, DrawGetFontStyle, DrawSetFontStyle, bindings::StyleType
|
||||
get_font_weight, set_font_weight, DrawGetFontWeight, DrawSetFontWeight, size_t
|
||||
get_font_stretch, set_font_stretch, DrawGetFontStretch, DrawSetFontStretch, bindings::StretchType
|
||||
get_font_style, set_font_style, DrawGetFontStyle, DrawSetFontStyle, StyleType
|
||||
get_font_weight, set_font_weight, DrawGetFontWeight, DrawSetFontWeight, usize
|
||||
get_font_stretch, set_font_stretch, DrawGetFontStretch, DrawSetFontStretch, StretchType
|
||||
|
||||
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_join, set_stroke_line_join, DrawGetStrokeLineJoin, DrawSetStrokeLineJoin, bindings::LineJoin
|
||||
get_stroke_miter_limit, set_stroke_miter_limit, DrawGetStrokeMiterLimit, DrawSetStrokeMiterLimit, size_t
|
||||
get_stroke_line_cap, set_stroke_line_cap, DrawGetStrokeLineCap, DrawSetStrokeLineCap, LineCap
|
||||
get_stroke_line_join, set_stroke_line_join, DrawGetStrokeLineJoin, DrawSetStrokeLineJoin, LineJoin
|
||||
get_stroke_miter_limit, set_stroke_miter_limit, DrawGetStrokeMiterLimit, DrawSetStrokeMiterLimit, usize
|
||||
get_stroke_opacity, set_stroke_opacity, DrawGetStrokeOpacity, DrawSetStrokeOpacity, f64
|
||||
get_stroke_width, set_stroke_width, DrawGetStrokeWidth, DrawSetStrokeWidth, f64
|
||||
get_stroke_antialias, set_stroke_antialias, DrawGetStrokeAntialias, DrawSetStrokeAntialias, bindings::MagickBooleanType
|
||||
|
||||
get_text_alignment, set_text_alignment, DrawGetTextAlignment, DrawSetTextAlignment, bindings::AlignType
|
||||
get_text_alignment, set_text_alignment, DrawGetTextAlignment, DrawSetTextAlignment, AlignType
|
||||
get_text_antialias, set_text_antialias, DrawGetTextAntialias, DrawSetTextAntialias, bindings::MagickBooleanType
|
||||
get_text_decoration, set_text_decoration, DrawGetTextDecoration, DrawSetTextDecoration, bindings::DecorationType
|
||||
get_text_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, bindings::DirectionType
|
||||
get_text_decoration, set_text_decoration, DrawGetTextDecoration, DrawSetTextDecoration, DecorationType
|
||||
get_text_direction, set_text_direction, DrawGetTextDirection, DrawSetTextDirection, DirectionType
|
||||
get_text_kerning, set_text_kerning, DrawGetTextKerning, DrawSetTextKerning, f64
|
||||
get_text_interline_spacing, set_text_interline_spacing, DrawGetTextInterlineSpacing, DrawSetTextInterlineSpacing, f64
|
||||
get_text_interword_spacing, set_text_interword_spacing, DrawGetTextInterwordSpacing, DrawSetTextInterwordSpacing, f64
|
||||
|
||||
@ -100,7 +100,7 @@ macro_rules! get {
|
||||
($($get:ident, $c_get:ident, $typ:ty )*) => {
|
||||
$(
|
||||
pub fn $get(&self) -> $typ {
|
||||
unsafe { ::bindings::$c_get(self.wand) }
|
||||
unsafe { ::bindings::$c_get(self.wand).into() }
|
||||
}
|
||||
)*
|
||||
}
|
||||
@ -110,10 +110,10 @@ macro_rules! set_get {
|
||||
($($get:ident, $set:ident, $c_get:ident, $c_set:ident, $typ:ty )*) => {
|
||||
$(
|
||||
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) -> Result<()> {
|
||||
match unsafe { ::bindings::$c_set(self.wand, v) } {
|
||||
match unsafe { ::bindings::$c_set(self.wand, v.into()) } {
|
||||
::bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||
_ => Err(MagickError(concat!(stringify!($set), " returned false")))
|
||||
}
|
||||
@ -130,10 +130,10 @@ macro_rules! set_get_unchecked {
|
||||
($($get:ident, $set:ident, $c_get:ident, $c_set:ident, $typ:ty )*) => {
|
||||
$(
|
||||
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) {
|
||||
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 {
|
||||
@ -258,7 +258,7 @@ macro_rules! mutations {
|
||||
$(
|
||||
$(#[$attr])*
|
||||
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(()),
|
||||
_ => Err(MagickError(concat!(stringify!($c_fun), " invocation failed")))
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -22,3 +22,6 @@ mod pixel;
|
||||
pub use self::drawing::DrawingWand;
|
||||
pub use self::magick::MagickWand;
|
||||
pub use self::pixel::{PixelWand, HSL};
|
||||
|
||||
use bindings::MagickBooleanType_MagickTrue as MagickTrue;
|
||||
use bindings::MagickBooleanType_MagickFalse as MagickFalse;
|
||||
|
||||
@ -16,15 +16,11 @@
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
use libc::size_t;
|
||||
#[cfg(not(target_os = "freebsd"))]
|
||||
use size_t;
|
||||
|
||||
use bindings;
|
||||
use result::MagickError;
|
||||
|
||||
use crate::result::Result;
|
||||
use super::MagickTrue;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct HSL {
|
||||
@ -48,7 +44,7 @@ wand_common!(
|
||||
impl PixelWand {
|
||||
pub fn is_similar(&self, other: &PixelWand, fuzz: f64) -> Result<()> {
|
||||
match unsafe { bindings::IsPixelWandSimilar(self.wand, other.wand, fuzz) } {
|
||||
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||
MagickTrue => Ok(()),
|
||||
_ => Err(MagickError("not similar")),
|
||||
}
|
||||
}
|
||||
@ -86,7 +82,7 @@ impl PixelWand {
|
||||
pub fn set_color(&mut self, s: &str) -> Result<()> {
|
||||
let c_string = CString::new(s).map_err(|_| "could not convert to cstring")?;
|
||||
match unsafe { bindings::PixelSetColor(self.wand, c_string.as_ptr()) } {
|
||||
bindings::MagickBooleanType_MagickTrue => Ok(()),
|
||||
MagickTrue => Ok(()),
|
||||
_ => Err(MagickError("failed to set color")),
|
||||
}
|
||||
}
|
||||
@ -98,8 +94,8 @@ impl PixelWand {
|
||||
);
|
||||
|
||||
set_get_unchecked!(
|
||||
get_color_count, set_color_count, PixelGetColorCount, PixelSetColorCount, size_t
|
||||
get_index, set_index, PixelGetIndex, PixelSetIndex, bindings::Quantum
|
||||
get_color_count, set_color_count, PixelGetColorCount, PixelSetColorCount, usize
|
||||
get_index, set_index, PixelGetIndex, PixelSetIndex, f32
|
||||
get_fuzz, set_fuzz, PixelGetFuzz, PixelSetFuzz, f64
|
||||
);
|
||||
|
||||
|
||||
12
tests/lib.rs
12
tests/lib.rs
@ -22,7 +22,7 @@ use std::io::Read;
|
||||
use std::path::Path;
|
||||
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;
|
||||
|
||||
// Used to make sure MagickWand is initialized exactly once. Note that we
|
||||
@ -54,7 +54,7 @@ fn test_resize_image() {
|
||||
1 => 1,
|
||||
height => height / 2,
|
||||
};
|
||||
wand.resize_image(halfwidth, halfheight, magick_rust::FilterType::Lanczos);
|
||||
assert!(wand.resize_image(halfwidth, halfheight, magick_rust::FilterType::Lanczos).is_ok());
|
||||
assert_eq!(256, wand.get_image_width());
|
||||
assert_eq!(192, wand.get_image_height());
|
||||
}
|
||||
@ -76,7 +76,7 @@ fn test_thumbnail_image() {
|
||||
1 => 1,
|
||||
height => height / 2,
|
||||
};
|
||||
wand.thumbnail_image(halfwidth, halfheight);
|
||||
assert!(wand.thumbnail_image(halfwidth, halfheight).is_ok());
|
||||
assert_eq!(256, wand.get_image_width());
|
||||
assert_eq!(192, wand.get_image_height());
|
||||
}
|
||||
@ -317,7 +317,7 @@ fn test_set_image_background_color() {
|
||||
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)
|
||||
wand.set_image_alpha_channel(magick_rust::AlphaChannelOption::Remove)
|
||||
.unwrap();
|
||||
let blob = wand.write_image_blob("rgb").unwrap();
|
||||
assert_eq!(0u8, blob[0]);
|
||||
@ -364,7 +364,7 @@ fn test_clut_image() {
|
||||
assert!(wand
|
||||
.clut_image(
|
||||
&gradient,
|
||||
bindings::PixelInterpolateMethod_BilinearInterpolatePixel
|
||||
magick_rust::PixelInterpolateMethod::Bilinear
|
||||
)
|
||||
.is_ok());
|
||||
}
|
||||
@ -422,7 +422,7 @@ fn test_image_compose() {
|
||||
START.call_once(|| {
|
||||
magick_wand_genesis();
|
||||
});
|
||||
let wand = MagickWand::new();
|
||||
let mut wand = MagickWand::new();
|
||||
wand.new_image(4, 4, &PixelWand::new()).unwrap();
|
||||
|
||||
let operators = [
|
||||
|
||||
Reference in New Issue
Block a user