From 7494c1d17478dca041e04f72b887a9287d5f8511 Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 24 Jul 2024 19:32:32 +0800 Subject: [PATCH 1/6] Redesign types module Now we are using more functionality given to us by rust-bindgen instead of maintaining enum mappings ourselves: * Rustified enums can be generated automatically by using the EnumVariation::Rust style in rust-bindgen * Redundant suffixes can be removed through implementing ParseCallbacks::enum_variant_name * The redundant FromRust trait was removed and replaced with the standard From and Into traits --- build.rs | 106 ++++++++++++++++++++- src/conversions.rs | 31 +++--- src/lib.rs | 11 +-- src/types/align_type.rs | 54 ----------- src/types/alpha_channel_option.rs | 67 ------------- src/types/auto_threshold_method.rs | 37 -------- src/types/channel_type.rs | 120 ----------------------- src/types/clip_path_units.rs | 54 ----------- src/types/colorspace_type.rs | 90 ------------------ src/types/composite_operator.rs | 132 -------------------------- src/types/compression_type.rs | 79 --------------- src/types/decoration_type.rs | 55 ----------- src/types/direction_type.rs | 54 ----------- src/types/dispose_type.rs | 58 ----------- src/types/dither_method.rs | 37 -------- src/types/endian_type.rs | 53 ----------- src/types/fill_rule.rs | 53 ----------- src/types/filter_type.rs | 60 ------------ src/types/gravity_type.rs | 64 ------------- src/types/image_type.rs | 62 ------------ src/types/interlace_type.rs | 58 ----------- src/types/kernel.rs | 105 +------------------- src/types/layer_method.rs | 50 ---------- src/types/line_cap.rs | 54 ----------- src/types/line_join.rs | 54 ----------- src/types/magick_evaluate_operator.rs | 67 ------------- src/types/magick_function.rs | 38 -------- src/types/metric_type.rs | 45 --------- src/types/mod.rs | 104 ++++++++------------ src/types/orientation_type.rs | 59 ------------ src/types/pixel_interpolate_method.rs | 62 ------------ src/types/pixel_mask.rs | 37 -------- src/types/rendering_intent.rs | 55 ----------- src/types/resolution_type.rs | 53 ----------- src/types/resource_type.rs | 39 -------- src/types/statistic_type.rs | 61 ------------ src/types/stretch_type.rs | 61 ------------ src/types/style_type.rs | 56 ----------- src/wand/macros.rs | 12 +-- src/wand/magick.rs | 23 +++-- src/wand/mod.rs | 4 +- 41 files changed, 182 insertions(+), 2192 deletions(-) delete mode 100644 src/types/align_type.rs delete mode 100644 src/types/alpha_channel_option.rs delete mode 100644 src/types/auto_threshold_method.rs delete mode 100644 src/types/channel_type.rs delete mode 100644 src/types/clip_path_units.rs delete mode 100644 src/types/colorspace_type.rs delete mode 100644 src/types/composite_operator.rs delete mode 100644 src/types/compression_type.rs delete mode 100644 src/types/decoration_type.rs delete mode 100644 src/types/direction_type.rs delete mode 100644 src/types/dispose_type.rs delete mode 100644 src/types/dither_method.rs delete mode 100644 src/types/endian_type.rs delete mode 100644 src/types/fill_rule.rs delete mode 100644 src/types/filter_type.rs delete mode 100644 src/types/gravity_type.rs delete mode 100644 src/types/image_type.rs delete mode 100644 src/types/interlace_type.rs delete mode 100644 src/types/layer_method.rs delete mode 100644 src/types/line_cap.rs delete mode 100644 src/types/line_join.rs delete mode 100644 src/types/magick_evaluate_operator.rs delete mode 100644 src/types/magick_function.rs delete mode 100644 src/types/metric_type.rs delete mode 100644 src/types/orientation_type.rs delete mode 100644 src/types/pixel_interpolate_method.rs delete mode 100644 src/types/pixel_mask.rs delete mode 100644 src/types/rendering_intent.rs delete mode 100644 src/types/resolution_type.rs delete mode 100644 src/types/resource_type.rs delete mode 100644 src/types/statistic_type.rs delete mode 100644 src/types/stretch_type.rs delete mode 100644 src/types/style_type.rs diff --git a/build.rs b/build.rs index e89ce67f..7c650928 100644 --- a/build.rs +++ b/build.rs @@ -125,6 +125,31 @@ fn main() { } } + #[derive(Debug)] + struct RemoveEnumVariantSuffix { + enum_name: String, + variant_suffix: String + } + + impl RemoveEnumVariantSuffix { + fn new(enum_name: impl Into, variant_suffix: impl Into) -> Self { + Self { + enum_name: enum_name.into(), + variant_suffix: variant_suffix.into() + } + } + } + + impl bindgen::callbacks::ParseCallbacks for RemoveEnumVariantSuffix { + fn enum_variant_name(&self, enum_name: Option<&str>, original_variant_name: &str, _variant_value: bindgen::callbacks::EnumVariantValue) -> Option { + if enum_name != Some(&self.enum_name) { + return None; + } + + Some(original_variant_name.trim_end_matches(&self.variant_suffix).to_string()) + } + } + let ignored_macros = IgnoreMacros( vec![ "FP_INFINITE".into(), @@ -143,6 +168,79 @@ fn main() { .collect(), ); + let enum_suffixes = vec![ + ("ClassType", "Class"), + ("CompositeOperator", "CompositeOp"), + ("GravityType", "Gravity"), + ("ImageType", "Type"), + ("InterlaceType", "Interlace"), + ("OrientationType", "Orientation"), + ("ResolutionType", "Resolution"), + ("TransmitType", "TransmitType"), + ("MapMode", "Mode"), + ("ColorspaceType", "Colorspace"), + ("ChannelType", "Channel"), + ("PixelChannel", "PixelChannel"), + ("PixelIntensityMethod", "PixelIntensityMethod"), + ("PixelInterpolateMethod", "InterpolatePixel"), + ("PixelMask", "PixelMask"), + ("PixelTrait", "PixelTrait"), + ("VirtualPixelMethod", "VirtualPixelMethod"), + ("ComplianceType", "Compliance"), + ("IlluminantType", "Illuminant"), + ("CompressionType", "Compression"), + ("KernelInfoType", "Kernel"), + ("MorphologyMethod", "Morphology"), + ("PreviewType", "Preview"), + ("DisposeType", "Dispose"), + ("LayerMethod", "Layer"), + ("RenderingIntent", "Intent"), + ("EndianType", "Endian"), + ("QuantumAlphaType", "QuantumAlpha"), + ("QuantumFormat", "QuantumFormat"), + ("QuantumType", "Quantum"), + ("FilterType", "Filter"), + ("TimerState", "TimerState"), + ("StretchType", "Stretch"), + ("StyleType", "Style"), + ("AlignType", "Align"), + ("DecorationType", "Decoration"), + ("DirectionType", "Direction"), + ("FillRule", "Rule"), + ("GradientType", "Gradient"), + ("LineCap", "Cap"), + ("LineJoin", "Join"), + ("PaintMethod", "Method"), + ("PrimitiveType", "Primitive"), + ("ReferenceType", "Reference"), + ("SpreadMethod", "Spread"), + ("WordBreakType", "WordBreakType"), + ("CacheType", "Cache"), + ("AlphaChannelOption", "AlphaChannel"), + ("MetricType", "ErrorMetric"), + ("MagickFormatType", "FormatType"), + ("MagickInfoFlag", "Flag"), + ("DistortMethod", "Distortion"), + ("SparseColorMethod", "ColorInterpolate"), + ("ComplexOperator", "ComplexOperator"), + ("MontageMode", "Mode"), + ("MagickCLDeviceType", "DeviceType"), + ("CommandOption", "Options"), // debatable + ("ValidateType", "Validate"), + ("CommandOptionFLags", "OptionFlag"), + ("PolicyDomain", "PolicyDomain"), + ("PolicyRights", "PolicyRights"), + ("DitherMethod", "DitherMethod"), + ("RegistryType", "RegistryType"), + ("ResourceType", "Resource"), + ("MagickEvaluateOperator", "EvaluateOperator"), + ("MagickFunction", "Function"), + ("StatisticType", "Statistic"), + ("AutoThresholdMethod", "ThresholdMethod"), + ("PathType", "Path"), + ("NoiseType", "Noise") + ]; + if !Path::new(&bindings_path_str).exists() { // Create the header file that rust-bindgen needs as input. let gen_h_path = out_dir.join("gen.h"); @@ -160,12 +258,18 @@ fn main() { .size_t_is_usize(true) .parse_callbacks(Box::new(ignored_macros)) .blocklist_type("timex") - .blocklist_function("clock_adjtime"); + .blocklist_function("clock_adjtime") + .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: false }); for d in include_dirs { builder = builder.clang_arg(format!("-I{}", d.to_string_lossy())); } + for (enum_name, suffix) in enum_suffixes { + let remove_suffix = RemoveEnumVariantSuffix::new(enum_name, suffix); + builder = builder.parse_callbacks(Box::new(remove_suffix)); + } + let bindings = if cfg!(all(windows, target_pointer_width = "64")) { match builder.clone().generate() { Ok(bindings) => bindings, diff --git a/src/conversions.rs b/src/conversions.rs index e888e9ff..71b61171 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -15,29 +15,20 @@ */ use super::bindings; -pub trait FromRust { - fn from_rust(t: T) -> Self; -} - -impl FromRust for bindings::MagickBooleanType { - fn from_rust(b: bool) -> Self { - if b { - bindings::MagickBooleanType_MagickTrue - } else { - bindings::MagickBooleanType_MagickFalse +impl From for bool { + fn from(value: bindings::MagickBooleanType) -> Self { + match value { + bindings::MagickBooleanType::MagickFalse => false, + bindings::MagickBooleanType::MagickTrue => true } } } -pub trait ToMagick { - fn to_magick(self) -> T; -} - -impl ToMagick for E -where - T: FromRust, -{ - fn to_magick(self) -> T { - >::from_rust(self) +impl From for bindings::MagickBooleanType { + fn from(value: bool) -> Self { + match value { + true => bindings::MagickBooleanType::MagickTrue, + false => bindings::MagickBooleanType::MagickFalse + } } } diff --git a/src/lib.rs b/src/lib.rs index 8c67357c..92050e94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,7 +34,6 @@ extern crate libc; use libc::size_t; -pub use conversions::ToMagick; pub use result::MagickError; use result::Result; pub use types::*; @@ -51,7 +50,7 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); pub fn magick_wand_genesis() { unsafe { match bindings::IsMagickWandInstantiated() { - bindings::MagickBooleanType_MagickTrue => (), + bindings::MagickBooleanType::MagickTrue => (), _ => bindings::MagickWandGenesis(), } } @@ -61,7 +60,7 @@ pub fn magick_wand_genesis() { /// This function is safe to be called repeatedly. pub fn magick_wand_terminus() { unsafe { - if let bindings::MagickBooleanType_MagickTrue = bindings::IsMagickWandInstantiated() { + if let bindings::MagickBooleanType::MagickTrue = bindings::IsMagickWandInstantiated() { bindings::MagickWandTerminus(); } } @@ -69,7 +68,7 @@ pub fn magick_wand_terminus() { pub fn magick_query_fonts(pattern: &str) -> Result> { let mut number_fonts: size_t = 0; - let c_string = ::std::ffi::CString::new(pattern).map_err(|_| "could not convert to cstring")?; + let c_string = std::ffi::CString::new(pattern).map_err(|_| "could not convert to cstring")?; let ptr = unsafe { bindings::MagickQueryFonts(c_string.as_ptr(), &mut number_fonts as *mut size_t) }; if ptr.is_null() { @@ -78,9 +77,9 @@ pub fn magick_query_fonts(pattern: &str) -> Result> { )) } else { let mut v = Vec::new(); - let c_str_ptr_slice = unsafe { ::std::slice::from_raw_parts(ptr, number_fonts as usize) }; + let c_str_ptr_slice = unsafe { std::slice::from_raw_parts(ptr, number_fonts as usize) }; for c_str_ptr in c_str_ptr_slice { - let c_str = unsafe { ::std::ffi::CStr::from_ptr(*c_str_ptr) }; + let c_str = unsafe { std::ffi::CStr::from_ptr(*c_str_ptr) }; v.push(c_str.to_string_lossy().into_owned()) } Ok(v) diff --git a/src/types/align_type.rs b/src/types/align_type.rs deleted file mode 100644 index fa416b77..00000000 --- a/src/types/align_type.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::AlignType { - fn from(value: AlignType) -> Self { - return value as bindings::AlignType; - } -} - -impl From 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(); - } -} diff --git a/src/types/alpha_channel_option.rs b/src/types/alpha_channel_option.rs deleted file mode 100644 index 534f6b88..00000000 --- a/src/types/alpha_channel_option.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::AlphaChannelOption { - fn from(value: AlphaChannelOption) -> Self { - return value as bindings::AlphaChannelOption; - } -} - -impl From 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(); - } -} diff --git a/src/types/auto_threshold_method.rs b/src/types/auto_threshold_method.rs deleted file mode 100644 index 7bc1b6f0..00000000 --- a/src/types/auto_threshold_method.rs +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::AutoThresholdMethod { - fn from(value: AutoThresholdMethod) -> Self { - return value as bindings::AutoThresholdMethod; - } -} diff --git a/src/types/channel_type.rs b/src/types/channel_type.rs deleted file mode 100644 index 90947fc2..00000000 --- a/src/types/channel_type.rs +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 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 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, - } - } -} diff --git a/src/types/clip_path_units.rs b/src/types/clip_path_units.rs deleted file mode 100644 index 61d3abb0..00000000 --- a/src/types/clip_path_units.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::ClipPathUnits { - fn from(value: ClipPathUnits) -> Self { - return value as bindings::ClipPathUnits; - } -} - -impl From 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(); - } -} diff --git a/src/types/colorspace_type.rs b/src/types/colorspace_type.rs deleted file mode 100644 index 982f281d..00000000 --- a/src/types/colorspace_type.rs +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u32)] -pub enum ColorspaceType { - Undefined = bindings::ColorspaceType_UndefinedColorspace, - CMY = bindings::ColorspaceType_CMYColorspace, - CMYK = bindings::ColorspaceType_CMYKColorspace, - GRAY = bindings::ColorspaceType_GRAYColorspace, - HCL = bindings::ColorspaceType_HCLColorspace, - HCLp = bindings::ColorspaceType_HCLpColorspace, - HSB = bindings::ColorspaceType_HSBColorspace, - HSI = bindings::ColorspaceType_HSIColorspace, - HSL = bindings::ColorspaceType_HSLColorspace, - HSV = bindings::ColorspaceType_HSVColorspace, - HWB = bindings::ColorspaceType_HWBColorspace, - Lab = bindings::ColorspaceType_LabColorspace, - LCH = bindings::ColorspaceType_LCHColorspace, - LCHab = bindings::ColorspaceType_LCHabColorspace, - LCHuv = bindings::ColorspaceType_LCHuvColorspace, - Log = bindings::ColorspaceType_LogColorspace, - LMS = bindings::ColorspaceType_LMSColorspace, - Luv = bindings::ColorspaceType_LuvColorspace, - OHTA = bindings::ColorspaceType_OHTAColorspace, - Rec601YCbCr = bindings::ColorspaceType_Rec601YCbCrColorspace, - Rec709YCbCr = bindings::ColorspaceType_Rec709YCbCrColorspace, - RGB = bindings::ColorspaceType_RGBColorspace, - scRGB = bindings::ColorspaceType_scRGBColorspace, - sRGB = bindings::ColorspaceType_sRGBColorspace, - Transparent = bindings::ColorspaceType_TransparentColorspace, - xyY = bindings::ColorspaceType_xyYColorspace, - XYZ = bindings::ColorspaceType_XYZColorspace, - YCbCr = bindings::ColorspaceType_YCbCrColorspace, - YCC = bindings::ColorspaceType_YCCColorspace, - YDbDr = bindings::ColorspaceType_YDbDrColorspace, - YIQ = bindings::ColorspaceType_YIQColorspace, - YPbPr = bindings::ColorspaceType_YPbPrColorspace, - YUV = bindings::ColorspaceType_YUVColorspace, - LinearGRAY = bindings::ColorspaceType_LinearGRAYColorspace, - Jzazbz = bindings::ColorspaceType_JzazbzColorspace, - DisplayP3 = bindings::ColorspaceType_DisplayP3Colorspace, - Adobe98 = bindings::ColorspaceType_Adobe98Colorspace, - ProPhoto = bindings::ColorspaceType_ProPhotoColorspace, - Oklab = bindings::ColorspaceType_OklabColorspace, - Oklch = bindings::ColorspaceType_OklchColorspace, -} - -impl Default for ColorspaceType { - fn default() -> Self { - return ColorspaceType::RGB; - } -} - -impl From for bindings::ColorspaceType { - fn from(value: ColorspaceType) -> Self { - return value as bindings::ColorspaceType; - } -} - -impl From for ColorspaceType { - fn from(value: bindings::ColorspaceType) -> Self { - /* - * SAFETY: - * - * `ColorspaceType` has the same repr as `bindings::ColorspaceType` - u32 - * - * If `value` is less than Oklch than it is in the vaild range and can be safely - * reinterpreted as `ColorspaceType` - */ - if value <= bindings::ColorspaceType_OklchColorspace { - return unsafe { std::mem::transmute(value) }; - } - return ColorspaceType::default(); - } -} diff --git a/src/types/composite_operator.rs b/src/types/composite_operator.rs deleted file mode 100644 index cfaf9b84..00000000 --- a/src/types/composite_operator.rs +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u32)] -pub enum CompositeOperator { - Undefined = bindings::CompositeOperator_UndefinedCompositeOp, - Alpha = bindings::CompositeOperator_AlphaCompositeOp, - Atop = bindings::CompositeOperator_AtopCompositeOp, - Blend = bindings::CompositeOperator_BlendCompositeOp, - Blur = bindings::CompositeOperator_BlurCompositeOp, - Bumpmap = bindings::CompositeOperator_BumpmapCompositeOp, - ChangeMask = bindings::CompositeOperator_ChangeMaskCompositeOp, - Clear = bindings::CompositeOperator_ClearCompositeOp, - ColorBurn = bindings::CompositeOperator_ColorBurnCompositeOp, - ColorDodge = bindings::CompositeOperator_ColorDodgeCompositeOp, - Colorize = bindings::CompositeOperator_ColorizeCompositeOp, - CopyBlack = bindings::CompositeOperator_CopyBlackCompositeOp, - CopyBlue = bindings::CompositeOperator_CopyBlueCompositeOp, - Copy = bindings::CompositeOperator_CopyCompositeOp, - CopyCyan = bindings::CompositeOperator_CopyCyanCompositeOp, - CopyGreen = bindings::CompositeOperator_CopyGreenCompositeOp, - CopyMagenta = bindings::CompositeOperator_CopyMagentaCompositeOp, - CopyAlpha = bindings::CompositeOperator_CopyAlphaCompositeOp, - CopyRed = bindings::CompositeOperator_CopyRedCompositeOp, - CopyYellow = bindings::CompositeOperator_CopyYellowCompositeOp, - Darken = bindings::CompositeOperator_DarkenCompositeOp, - DarkenIntensity = bindings::CompositeOperator_DarkenIntensityCompositeOp, - Difference = bindings::CompositeOperator_DifferenceCompositeOp, - Displace = bindings::CompositeOperator_DisplaceCompositeOp, - Dissolve = bindings::CompositeOperator_DissolveCompositeOp, - Distort = bindings::CompositeOperator_DistortCompositeOp, - DivideDst = bindings::CompositeOperator_DivideDstCompositeOp, - DivideSrc = bindings::CompositeOperator_DivideSrcCompositeOp, - DstAtop = bindings::CompositeOperator_DstAtopCompositeOp, - Dst = bindings::CompositeOperator_DstCompositeOp, - DstIn = bindings::CompositeOperator_DstInCompositeOp, - DstOut = bindings::CompositeOperator_DstOutCompositeOp, - DstOver = bindings::CompositeOperator_DstOverCompositeOp, - Exclusion = bindings::CompositeOperator_ExclusionCompositeOp, - HardLight = bindings::CompositeOperator_HardLightCompositeOp, - HardMix = bindings::CompositeOperator_HardMixCompositeOp, - Hue = bindings::CompositeOperator_HueCompositeOp, - In = bindings::CompositeOperator_InCompositeOp, - Intensity = bindings::CompositeOperator_IntensityCompositeOp, - Lighten = bindings::CompositeOperator_LightenCompositeOp, - LightenIntensity = bindings::CompositeOperator_LightenIntensityCompositeOp, - LinearBurn = bindings::CompositeOperator_LinearBurnCompositeOp, - LinearDodge = bindings::CompositeOperator_LinearDodgeCompositeOp, - LinearLight = bindings::CompositeOperator_LinearLightCompositeOp, - Luminize = bindings::CompositeOperator_LuminizeCompositeOp, - Mathematics = bindings::CompositeOperator_MathematicsCompositeOp, - MinusDst = bindings::CompositeOperator_MinusDstCompositeOp, - MinusSrc = bindings::CompositeOperator_MinusSrcCompositeOp, - Modulate = bindings::CompositeOperator_ModulateCompositeOp, - ModulusAdd = bindings::CompositeOperator_ModulusAddCompositeOp, - ModulusSubtract = bindings::CompositeOperator_ModulusSubtractCompositeOp, - Multiply = bindings::CompositeOperator_MultiplyCompositeOp, - No = bindings::CompositeOperator_NoCompositeOp, - Out = bindings::CompositeOperator_OutCompositeOp, - Over = bindings::CompositeOperator_OverCompositeOp, - Overlay = bindings::CompositeOperator_OverlayCompositeOp, - PegtopLight = bindings::CompositeOperator_PegtopLightCompositeOp, - PinLight = bindings::CompositeOperator_PinLightCompositeOp, - Plus = bindings::CompositeOperator_PlusCompositeOp, - Replace = bindings::CompositeOperator_ReplaceCompositeOp, - Saturate = bindings::CompositeOperator_SaturateCompositeOp, - Screen = bindings::CompositeOperator_ScreenCompositeOp, - SoftLight = bindings::CompositeOperator_SoftLightCompositeOp, - SrcAtop = bindings::CompositeOperator_SrcAtopCompositeOp, - Src = bindings::CompositeOperator_SrcCompositeOp, - SrcIn = bindings::CompositeOperator_SrcInCompositeOp, - SrcOut = bindings::CompositeOperator_SrcOutCompositeOp, - SrcOver = bindings::CompositeOperator_SrcOverCompositeOp, - Threshold = bindings::CompositeOperator_ThresholdCompositeOp, - VividLight = bindings::CompositeOperator_VividLightCompositeOp, - Xor = bindings::CompositeOperator_XorCompositeOp, - Stereo = bindings::CompositeOperator_StereoCompositeOp, - Freeze = bindings::CompositeOperator_FreezeCompositeOp, - Interpolate = bindings::CompositeOperator_InterpolateCompositeOp, - Negate = bindings::CompositeOperator_NegateCompositeOp, - Reflect = bindings::CompositeOperator_ReflectCompositeOp, - SoftBurn = bindings::CompositeOperator_SoftBurnCompositeOp, - SoftDodge = bindings::CompositeOperator_SoftDodgeCompositeOp, - Stamp = bindings::CompositeOperator_StampCompositeOp, - RMSE = bindings::CompositeOperator_RMSECompositeOp, - SaliencyBlend = bindings::CompositeOperator_SaliencyBlendCompositeOp, - SeamlessBlend = bindings::CompositeOperator_SeamlessBlendCompositeOp, -} - -impl Default for CompositeOperator { - fn default() -> Self { - return CompositeOperator::Over; - } -} - -impl From for bindings::CompositeOperator { - fn from(value: CompositeOperator) -> Self { - return value as bindings::CompositeOperator; - } -} - -impl From for CompositeOperator { - fn from(value: bindings::CompositeOperator) -> Self { - /* - * SAFETY: - * - * `CompositeOperator` has the same repr as `bindings::CompositeOperator` - u32 - * - * If `value` is less than SeamlessBlend than it is in the vaild range and can be safely - * reinterpreted as `CompositeOperator` - */ - if value <= bindings::CompositeOperator_SeamlessBlendCompositeOp { - return unsafe { std::mem::transmute(value) }; - } - return CompositeOperator::default(); - } -} diff --git a/src/types/compression_type.rs b/src/types/compression_type.rs deleted file mode 100644 index 8522691f..00000000 --- a/src/types/compression_type.rs +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::CompressionType { - fn from(value: CompressionType) -> Self { - return value as bindings::CompressionType; - } -} - -impl From 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(); - } -} diff --git a/src/types/decoration_type.rs b/src/types/decoration_type.rs deleted file mode 100644 index b868f1e0..00000000 --- a/src/types/decoration_type.rs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::DecorationType { - fn from(value: DecorationType) -> Self { - return value as bindings::DecorationType; - } -} - -impl From 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(); - } -} diff --git a/src/types/direction_type.rs b/src/types/direction_type.rs deleted file mode 100644 index 750b6e4a..00000000 --- a/src/types/direction_type.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::DirectionType { - fn from(value: DirectionType) -> Self { - return value as bindings::DirectionType; - } -} - -impl From 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(); - } -} diff --git a/src/types/dispose_type.rs b/src/types/dispose_type.rs deleted file mode 100644 index 9e3f57d2..00000000 --- a/src/types/dispose_type.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::DisposeType { - fn from(value: DisposeType) -> Self { - return value as bindings::DisposeType; - } -} - -impl From 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(); - } -} diff --git a/src/types/dither_method.rs b/src/types/dither_method.rs deleted file mode 100644 index 3c73050d..00000000 --- a/src/types/dither_method.rs +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u32)] -pub enum DitherMethod { - Undefined = bindings::DitherMethod_UndefinedDitherMethod, - No = bindings::DitherMethod_NoDitherMethod, - Riemersma = bindings::DitherMethod_RiemersmaDitherMethod, - FloydSteinberg = bindings::DitherMethod_FloydSteinbergDitherMethod, -} - -impl Default for DitherMethod { - fn default() -> Self { - return DitherMethod::No; - } -} - -impl From for bindings::DitherMethod { - fn from(value: DitherMethod) -> Self { - return value as bindings::DitherMethod; - } -} diff --git a/src/types/endian_type.rs b/src/types/endian_type.rs deleted file mode 100644 index 8f53cedf..00000000 --- a/src/types/endian_type.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::EndianType { - fn from(value: EndianType) -> Self { - return value as bindings::EndianType; - } -} - -impl From 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(); - } -} diff --git a/src/types/fill_rule.rs b/src/types/fill_rule.rs deleted file mode 100644 index 639c71c6..00000000 --- a/src/types/fill_rule.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::FillRule { - fn from(value: FillRule) -> Self { - return value as bindings::FillRule; - } -} - -impl From 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(); - } -} diff --git a/src/types/filter_type.rs b/src/types/filter_type.rs deleted file mode 100644 index 58a70223..00000000 --- a/src/types/filter_type.rs +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u32)] -pub enum FilterType { - Undefined = bindings::FilterType_UndefinedFilter, - Point = bindings::FilterType_PointFilter, - Box = bindings::FilterType_BoxFilter, - Triangle = bindings::FilterType_TriangleFilter, - Hermite = bindings::FilterType_HermiteFilter, - Hann = bindings::FilterType_HannFilter, - Hamming = bindings::FilterType_HammingFilter, - Blackman = bindings::FilterType_BlackmanFilter, - Gaussian = bindings::FilterType_GaussianFilter, - Quadratic = bindings::FilterType_QuadraticFilter, - Cubic = bindings::FilterType_CubicFilter, - Catrom = bindings::FilterType_CatromFilter, - Mitchell = bindings::FilterType_MitchellFilter, - Jinc = bindings::FilterType_JincFilter, - Sinc = bindings::FilterType_SincFilter, - SincFast = bindings::FilterType_SincFastFilter, - Kaiser = bindings::FilterType_KaiserFilter, - Welch = bindings::FilterType_WelchFilter, - Parzen = bindings::FilterType_ParzenFilter, - Bohman = bindings::FilterType_BohmanFilter, - Bartlett = bindings::FilterType_BartlettFilter, - Lagrange = bindings::FilterType_LagrangeFilter, - Lanczos = bindings::FilterType_LanczosFilter, - LanczosSharp = bindings::FilterType_LanczosSharpFilter, - Lanczos2 = bindings::FilterType_Lanczos2Filter, - Lanczos2Sharp = bindings::FilterType_Lanczos2SharpFilter, - Robidoux = bindings::FilterType_RobidouxFilter, - RobidouxSharp = bindings::FilterType_RobidouxSharpFilter, - Cosine = bindings::FilterType_CosineFilter, - Spline = bindings::FilterType_SplineFilter, - LanczosRadius = bindings::FilterType_LanczosRadiusFilter, - CubicSpline = bindings::FilterType_CubicSplineFilter, - Sentinel = bindings::FilterType_SentinelFilter, -} - -impl From for bindings::FilterType { - fn from(value: FilterType) -> Self { - return value as bindings::FilterType; - } -} diff --git a/src/types/gravity_type.rs b/src/types/gravity_type.rs deleted file mode 100644 index c07330f9..00000000 --- a/src/types/gravity_type.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(u32)] -pub enum GravityType { - Undefined = bindings::GravityType_UndefinedGravity, - /* - * Identical to `Undefined` - */ - // Forget = bindings::GravityType_ForgetGravity, - NorthWest = bindings::GravityType_NorthWestGravity, - North = bindings::GravityType_NorthGravity, - NorthEast = bindings::GravityType_NorthEastGravity, - West = bindings::GravityType_WestGravity, - Center = bindings::GravityType_CenterGravity, - East = bindings::GravityType_EastGravity, - SouthWest = bindings::GravityType_SouthWestGravity, - South = bindings::GravityType_SouthGravity, - SouthEast = bindings::GravityType_SouthEastGravity, -} - -impl Default for GravityType { - fn default() -> Self { - return GravityType::Undefined; - } -} - -impl From for bindings::GravityType { - fn from(value: GravityType) -> Self { - return value as bindings::GravityType; - } -} - -impl From for GravityType { - fn from(value: bindings::GravityType) -> Self { - /* - * SAFETY: - * - * `GravityType` has the same repr as `bindings::GravityType` - u32 - * - * If `value` is less than SouthEast than it is in the vaild range and can be safely - * reinterpreted as `GravityType` - */ - if value <= bindings::GravityType_SouthEastGravity { - return unsafe { std::mem::transmute(value) }; - } - return GravityType::default(); - } -} diff --git a/src/types/image_type.rs b/src/types/image_type.rs deleted file mode 100644 index 33565e1e..00000000 --- a/src/types/image_type.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::ImageType { - fn from(value: ImageType) -> Self { - return value as bindings::ImageType; - } -} - -impl From 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(); - } -} diff --git a/src/types/interlace_type.rs b/src/types/interlace_type.rs deleted file mode 100644 index ade13e49..00000000 --- a/src/types/interlace_type.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::InterlaceType { - fn from(value: InterlaceType) -> Self { - return value as bindings::InterlaceType; - } -} - -impl From 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(); - } -} diff --git a/src/types/kernel.rs b/src/types/kernel.rs index 5ba64306..ee9258c8 100644 --- a/src/types/kernel.rs +++ b/src/types/kernel.rs @@ -18,101 +18,6 @@ use std::ffi::CString; use crate::bindings; use crate::{MagickError, Result}; -#[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 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 for bindings::KernelInfoType { - fn from(value: MorphologyMethod) -> Self { - return value as bindings::MorphologyMethod; - } -} - /// Builder, that creates instances of [KernelInfo](self::KernelInfo) /// /// # Examples @@ -171,7 +76,7 @@ pub struct KernelBuilder { center: Option<(usize, usize)>, values: Option>, - info_type: Option, + info_type: Option, geom_info: Option, } @@ -250,7 +155,7 @@ impl KernelBuilder { } /// Used for builtin kernels - pub fn set_info_type(mut self, info_type: KernelInfoType) -> KernelBuilder { + pub fn set_info_type(mut self, info_type: crate::KernelInfoType) -> KernelBuilder { self.info_type = Some(info_type); return self; } @@ -295,7 +200,7 @@ impl KernelInfo { /// 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) } + unsafe { bindings::ScaleKernelInfo(self.kernel_info, factor, bindings::GeometryFlags::NoValue) } } /// Kernel normalization is designed to ensure that any use of the kernel scaling factor with @@ -319,7 +224,7 @@ impl KernelInfo { bindings::ScaleKernelInfo( self.kernel_info, 1.0, - bindings::GeometryFlags_NormalizeValue, + bindings::GeometryFlags::NormalizeValue, ) } } @@ -333,7 +238,7 @@ impl KernelInfo { bindings::ScaleKernelInfo( self.kernel_info, 1.0, - bindings::GeometryFlags_CorrelateNormalizeValue, + bindings::GeometryFlags::CorrelateNormalizeValue, ) } } diff --git a/src/types/layer_method.rs b/src/types/layer_method.rs deleted file mode 100644 index 056d0238..00000000 --- a/src/types/layer_method.rs +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::LayerMethod { - fn from(value: LayerMethod) -> Self { - return value as bindings::LayerMethod; - } -} diff --git a/src/types/line_cap.rs b/src/types/line_cap.rs deleted file mode 100644 index a11c87fc..00000000 --- a/src/types/line_cap.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::LineCap { - fn from(value: LineCap) -> Self { - return value as bindings::LineCap; - } -} - -impl From 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(); - } -} diff --git a/src/types/line_join.rs b/src/types/line_join.rs deleted file mode 100644 index 2cb43fe0..00000000 --- a/src/types/line_join.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::LineJoin { - fn from(value: LineJoin) -> Self { - return value as bindings::LineJoin; - } -} - -impl From 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(); - } -} diff --git a/src/types/magick_evaluate_operator.rs b/src/types/magick_evaluate_operator.rs deleted file mode 100644 index deace9f0..00000000 --- a/src/types/magick_evaluate_operator.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::MagickEvaluateOperator { - fn from(value: MagickEvaluateOperator) -> Self { - return value as bindings::MagickEvaluateOperator; - } -} diff --git a/src/types/magick_function.rs b/src/types/magick_function.rs deleted file mode 100644 index 561345c4..00000000 --- a/src/types/magick_function.rs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::MagickFunction { - fn from(value: MagickFunction) -> Self { - return value as bindings::MagickFunction; - } -} diff --git a/src/types/metric_type.rs b/src/types/metric_type.rs deleted file mode 100644 index 796c6288..00000000 --- a/src/types/metric_type.rs +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -pub enum MetricType { - Undefined = bindings::MetricType_UndefinedErrorMetric as isize, - Absolute = bindings::MetricType_AbsoluteErrorMetric as isize, - Fuzz = bindings::MetricType_FuzzErrorMetric as isize, - MeanAbsolute = bindings::MetricType_MeanAbsoluteErrorMetric as isize, - MeanErrorPerPixel = bindings::MetricType_MeanErrorPerPixelErrorMetric as isize, - MeanSquared = bindings::MetricType_MeanSquaredErrorMetric as isize, - NormalizedCrossCorrelation = - bindings::MetricType_NormalizedCrossCorrelationErrorMetric as isize, - PeakAbsolute = bindings::MetricType_PeakAbsoluteErrorMetric as isize, - PeakSignalToNoiseRatio = bindings::MetricType_PeakSignalToNoiseRatioErrorMetric as isize, - PerceptualHash = bindings::MetricType_PerceptualHashErrorMetric as isize, - RootMeanSquared = bindings::MetricType_RootMeanSquaredErrorMetric as isize, - StructuralSimilarity = bindings::MetricType_StructuralSimilarityErrorMetric as isize, - StructuralDissimilarity = bindings::MetricType_StructuralDissimilarityErrorMetric as isize, -} - -impl Default for MetricType { - fn default() -> Self { - return MetricType::Absolute; - } -} - -impl From for bindings::MetricType { - fn from(value: MetricType) -> Self { - return value as bindings::MetricType; - } -} diff --git a/src/types/mod.rs b/src/types/mod.rs index 33ac992a..d04f791f 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -13,76 +13,46 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -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 bindings::AlignType; +pub use bindings::AlphaChannelOption; +pub use bindings::AutoThresholdMethod; +pub use bindings::ChannelType; +pub use bindings::ClipPathUnits; +pub use bindings::CompositeOperator; +pub use bindings::ColorspaceType; +pub use bindings::CompressionType; +pub use bindings::DecorationType; +pub use bindings::DirectionType; +pub use bindings::DisposeType; +pub use bindings::DitherMethod; +pub use bindings::EndianType; +pub use bindings::FillRule; +pub use bindings::FilterType; pub use self::geometry_info::GeometryInfo; -pub use self::gravity_type::GravityType; +pub use bindings::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; +pub use bindings::ImageType; +pub use bindings::InterlaceType; +pub use bindings::KernelInfoType; +pub use self::kernel::{KernelBuilder, KernelInfo}; +pub use bindings::LayerMethod; +pub use bindings::LineCap; +pub use bindings::LineJoin; +pub use bindings::MagickEvaluateOperator; +pub use bindings::MagickFunction; +pub use bindings::MetricType; +pub use bindings::MorphologyMethod; +pub use bindings::OrientationType; +pub use bindings::PixelInterpolateMethod; +pub use bindings::PixelMask; +pub use bindings::RenderingIntent; +pub use bindings::ResolutionType; +pub use bindings::ResourceType; +pub use bindings::StatisticType; +pub use bindings::StretchType; +pub use bindings::StyleType; diff --git a/src/types/orientation_type.rs b/src/types/orientation_type.rs deleted file mode 100644 index 73ee1ab8..00000000 --- a/src/types/orientation_type.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::OrientationType { - fn from(value: OrientationType) -> Self { - return value as bindings::OrientationType; - } -} - -impl From 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(); - } -} diff --git a/src/types/pixel_interpolate_method.rs b/src/types/pixel_interpolate_method.rs deleted file mode 100644 index d2eab9a7..00000000 --- a/src/types/pixel_interpolate_method.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::PixelInterpolateMethod { - fn from(value: PixelInterpolateMethod) -> Self { - return value as bindings::PixelInterpolateMethod; - } -} - -impl From 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(); - } -} diff --git a/src/types/pixel_mask.rs b/src/types/pixel_mask.rs deleted file mode 100644 index 8ea388ca..00000000 --- a/src/types/pixel_mask.rs +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::PixelMask { - fn from(value: PixelMask) -> Self { - return value as bindings::PixelMask; - } -} diff --git a/src/types/rendering_intent.rs b/src/types/rendering_intent.rs deleted file mode 100644 index 680f9135..00000000 --- a/src/types/rendering_intent.rs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::RenderingIntent { - fn from(value: RenderingIntent) -> Self { - return value as bindings::RenderingIntent; - } -} - -impl From 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(); - } -} diff --git a/src/types/resolution_type.rs b/src/types/resolution_type.rs deleted file mode 100644 index e4cf1f74..00000000 --- a/src/types/resolution_type.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::ResolutionType { - fn from(value: ResolutionType) -> Self { - return value as bindings::ResolutionType; - } -} - -impl From 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(); - } -} diff --git a/src/types/resource_type.rs b/src/types/resource_type.rs deleted file mode 100644 index 0e2543c2..00000000 --- a/src/types/resource_type.rs +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -use crate::bindings; - -/// Resource type to use with [set_resource_limit](crate::MagickWand::set_resource_limit) -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ResourceType { - Undefined = bindings::ResourceType_UndefinedResource as isize, - Area = bindings::ResourceType_AreaResource as isize, - Disk = bindings::ResourceType_DiskResource as isize, - File = bindings::ResourceType_FileResource as isize, - Height = bindings::ResourceType_HeightResource as isize, - Map = bindings::ResourceType_MapResource as isize, - Memory = bindings::ResourceType_MemoryResource as isize, - Thread = bindings::ResourceType_ThreadResource as isize, - Throttle = bindings::ResourceType_ThrottleResource as isize, - Time = bindings::ResourceType_TimeResource as isize, - Width = bindings::ResourceType_WidthResource as isize, - ListLength = bindings::ResourceType_ListLengthResource as isize, -} - -impl From for bindings::ResourceType { - fn from(value: ResourceType) -> Self { - return value as bindings::ResourceType; - } -} diff --git a/src/types/statistic_type.rs b/src/types/statistic_type.rs deleted file mode 100644 index 8e55e763..00000000 --- a/src/types/statistic_type.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::StatisticType { - fn from(value: StatisticType) -> Self { - return value as bindings::StatisticType; - } -} - -impl From 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(); - } -} diff --git a/src/types/stretch_type.rs b/src/types/stretch_type.rs deleted file mode 100644 index 83f1efbd..00000000 --- a/src/types/stretch_type.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::StretchType { - fn from(value: StretchType) -> Self { - return value as bindings::StretchType; - } -} - -impl From 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(); - } -} diff --git a/src/types/style_type.rs b/src/types/style_type.rs deleted file mode 100644 index f35eb560..00000000 --- a/src/types/style_type.rs +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2024 5ohue - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -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 for bindings::StyleType { - fn from(value: StyleType) -> Self { - return value as bindings::StyleType; - } -} - -impl From 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(); - } -} diff --git a/src/wand/macros.rs b/src/wand/macros.rs index 56754fa6..6f9d1b5f 100644 --- a/src/wand/macros.rs +++ b/src/wand/macros.rs @@ -39,7 +39,7 @@ macro_rules! wand_common { pub fn clear_exception(&mut self) -> Result<()> { match unsafe { ::bindings::$clear_exc(self.wand) } { - ::bindings::MagickBooleanType_MagickTrue => Ok(()), + ::bindings::MagickBooleanType::MagickTrue => Ok(()), _ => Err(MagickError( concat!("failed to clear", stringify!($wand), "exception").to_string(), )), @@ -52,7 +52,7 @@ macro_rules! wand_common { pub fn get_exception(&self) -> Result<(String, ::bindings::ExceptionType)> { let mut severity: ::bindings::ExceptionType = - ::bindings::ExceptionType_UndefinedException; + ::bindings::ExceptionType::UndefinedException; let ptr = unsafe { ::bindings::$get_exc(self.wand, &mut severity as *mut _) }; if ptr.is_null() { @@ -70,7 +70,7 @@ macro_rules! wand_common { pub fn is_wand(&self) -> Result<()> { match unsafe { ::bindings::$is_wand(self.wand) } { - ::bindings::MagickBooleanType_MagickTrue => Ok(()), + ::bindings::MagickBooleanType::MagickTrue => Ok(()), _ => Err(MagickError( concat!(stringify!($wand), " not a wand").to_string(), )), @@ -122,7 +122,7 @@ macro_rules! set_get { } pub fn $set(&mut self, v: $typ) -> Result<()> { match unsafe { ::bindings::$c_set(self.wand, v.into()) } { - ::bindings::MagickBooleanType_MagickTrue => Ok(()), + ::bindings::MagickBooleanType::MagickTrue => Ok(()), _ => Err(MagickError(concat!(stringify!($set), " returned false").to_string())) } } @@ -176,7 +176,7 @@ macro_rules! string_set_get { pub fn $set(&mut self, s: &str) -> Result<()> { let c_string = std::ffi::CString::new(s).map_err(|_| "could not convert to cstring")?; match unsafe { ::bindings::$c_set(self.wand, c_string.as_ptr()) } { - ::bindings::MagickBooleanType_MagickTrue => Ok(()), + ::bindings::MagickBooleanType::MagickTrue => Ok(()), _ => Err(MagickError(concat!(stringify!($set), " returned false").to_string())) } } @@ -266,7 +266,7 @@ macro_rules! mutations { $(#[$attr])* pub fn $fun(&self $(, $arg: $ty)*) -> Result<()> { 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").to_string())) } } diff --git a/src/wand/magick.rs b/src/wand/magick.rs index 956437e0..cd4da6ce 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -21,7 +21,6 @@ use libc::c_void; use libc::size_t; use bindings; -use conversions::*; use result::MagickError; #[cfg(not(target_os = "freebsd"))] use size_t; @@ -140,7 +139,7 @@ impl MagickWand { pub fn append_all(&mut self, stack: bool) -> Result { unsafe { bindings::MagickResetIterator(self.wand) }; - let result = unsafe { bindings::MagickAppendImages(self.wand, stack.to_magick()) }; + let result = unsafe { bindings::MagickAppendImages(self.wand, stack.into()) }; if result.is_null() { return Err(MagickError("failed to append image".to_string())); @@ -160,7 +159,7 @@ impl MagickWand { pub fn write_images(&self, path: &str, adjoin: bool) -> Result<()> { let c_name = CString::new(path).map_err(|_| "path string contains null byte")?; let result = - unsafe { bindings::MagickWriteImages(self.wand, c_name.as_ptr(), adjoin.to_magick()) }; + unsafe { bindings::MagickWriteImages(self.wand, c_name.as_ptr(), adjoin.into()) }; match result { MagickTrue => Ok(()), _ => Err(MagickError(self.get_exception()?.0)), @@ -478,7 +477,7 @@ impl MagickWand { let result = unsafe { bindings::MagickSigmoidalContrastImage( self.wand, - sharpen.to_magick(), + sharpen.into(), strength, midpoint * quantum_range, ) @@ -961,7 +960,7 @@ impl MagickWand { width, height, c_map.as_ptr(), - bindings::StorageType_CharPixel, + bindings::StorageType::CharPixel, pixels.as_mut_ptr() as *mut c_void, ) == MagickTrue { @@ -993,7 +992,7 @@ impl MagickWand { width, height, c_map.as_ptr(), - bindings::StorageType_DoublePixel, + bindings::StorageType::DoublePixel, pixels.as_mut_ptr() as *mut c_void, ) == MagickTrue { @@ -1138,7 +1137,7 @@ impl MagickWand { self.wand, new_width.into(), new_height.into(), - bindings::FilterType_LanczosFilter, + FilterType::Lanczos, ); } } @@ -1314,7 +1313,7 @@ impl MagickWand { columns, rows, pixel_map.as_ptr(), - bindings::StorageType_CharPixel, + bindings::StorageType::CharPixel, pixels.as_ptr() as *const libc::c_void, ) } { @@ -1341,8 +1340,8 @@ impl MagickWand { columns, rows, pixel_map.as_ptr(), - bindings::StorageType_DoublePixel, - pixels.as_ptr() as *const libc::c_void, + bindings::StorageType::DoublePixel, + pixels.as_ptr() as *const c_void, ) } { MagickTrue => Ok(()), @@ -1401,7 +1400,7 @@ impl MagickWand { colorspace.into(), tree_depth.into(), dither_method.into(), - measure_error.to_magick(), + measure_error.into(), ) } { MagickTrue => Ok(()), @@ -1425,7 +1424,7 @@ impl MagickWand { colorspace.into(), tree_depth.into(), dither_method.into(), - measure_error.to_magick(), + measure_error.into(), ) } { MagickTrue => Ok(()), diff --git a/src/wand/mod.rs b/src/wand/mod.rs index 12002457..8ce0e2c4 100644 --- a/src/wand/mod.rs +++ b/src/wand/mod.rs @@ -23,5 +23,5 @@ pub use self::drawing::DrawingWand; pub use self::magick::MagickWand; pub use self::pixel::{PixelWand, HSL}; -use bindings::MagickBooleanType_MagickFalse as MagickFalse; -use bindings::MagickBooleanType_MagickTrue as MagickTrue; +use bindings::MagickBooleanType::MagickFalse as MagickFalse; +use bindings::MagickBooleanType::MagickTrue as MagickTrue; From e7e7f5eb8750d15e5f42506ba0267b8d4e6f1984 Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 24 Jul 2024 21:20:55 +0800 Subject: [PATCH 2/6] Fix linking errors by including MagickCore as well --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 7c650928..a3e3cafa 100644 --- a/build.rs +++ b/build.rs @@ -94,7 +94,7 @@ fn main() { Ok(ref v) => v.split(PATH_SEPARATOR).map(|x| x.to_owned()).collect(), Err(_) => { if target.contains("windows") { - vec!["CORE_RL_MagickWand_".to_string()] + vec!["CORE_RL_MagickWand_".to_string(), "CORE_RL_MagickCore_".to_string()] } else if target.contains("freebsd") { vec!["MagickWand-7".to_string()] } else { From 3b1b7a502e7d29ab391ca264771511e2e355c31b Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 24 Jul 2024 21:45:40 +0800 Subject: [PATCH 3/6] Added Eq to enums --- build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index a3e3cafa..0436576c 100644 --- a/build.rs +++ b/build.rs @@ -259,7 +259,8 @@ fn main() { .parse_callbacks(Box::new(ignored_macros)) .blocklist_type("timex") .blocklist_function("clock_adjtime") - .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: false }); + .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: false }) + .derive_eq(true); for d in include_dirs { builder = builder.clang_arg(format!("-I{}", d.to_string_lossy())); From 6a84932ffe6b19c63e0f219469e9f2fd02542b43 Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 24 Jul 2024 21:46:17 +0800 Subject: [PATCH 4/6] Rewrite of bindgen ParseCallbacks --- build.rs | 149 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 65 deletions(-) diff --git a/build.rs b/build.rs index 0436576c..c14ac6fd 100644 --- a/build.rs +++ b/build.rs @@ -16,7 +16,7 @@ extern crate bindgen; extern crate pkg_config; -use std::collections::HashSet; +use std::collections::{HashMap, HashSet}; use std::env; use std::fs::File; use std::io::prelude::*; @@ -47,6 +47,71 @@ pub const PATH_SEPARATOR: &str = match cfg!(target_os = "windows") { _ => ":", }; +#[derive(Debug)] +struct IgnoreMacros { + macros_to_ignore: HashSet +} + +impl IgnoreMacros { + fn from_iter(macro_names: I) -> Self + where + S: Into, + I: IntoIterator + { + let mut macros_to_ignore = HashSet::new(); + for macro_name in macro_names { + macros_to_ignore.insert(macro_name.into()); + } + Self { + macros_to_ignore + } + } +} + +impl bindgen::callbacks::ParseCallbacks for IgnoreMacros { + fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior { + if self.macros_to_ignore.contains(name) { + bindgen::callbacks::MacroParsingBehavior::Ignore + } else { + bindgen::callbacks::MacroParsingBehavior::Default + } + } +} + +#[derive(Debug)] +struct RemoveEnumVariantSuffixes { + names_to_suffix: HashMap +} + +impl RemoveEnumVariantSuffixes { + fn from_iter(enum_suffix_pairs: I) -> Self + where + S: Into, + I: IntoIterator, + { + let mut names_to_suffix = HashMap::new(); + for (enum_name, variant_suffix) in enum_suffix_pairs { + names_to_suffix.insert(enum_name.into(), variant_suffix.into()); + } + + Self { + names_to_suffix + } + } +} + +impl bindgen::callbacks::ParseCallbacks for RemoveEnumVariantSuffixes { + fn enum_variant_name( + &self, + enum_name: Option<&str>, + original_variant_name: &str, + _variant_value: bindgen::callbacks::EnumVariantValue + ) -> Option { + let suffix = self.names_to_suffix.get(enum_name?)?; + Some(original_variant_name.trim_end_matches(suffix).to_string()) + } +} + fn main() { let check_cppflags = if cfg!(target_os = "windows") { // Resolve bash from directories listed in the PATH environment variable in the @@ -112,63 +177,21 @@ fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let bindings_path_str = out_dir.join("bindings.rs"); - #[derive(Debug)] - struct IgnoreMacros(HashSet); - - impl bindgen::callbacks::ParseCallbacks for IgnoreMacros { - fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior { - if self.0.contains(name) { - bindgen::callbacks::MacroParsingBehavior::Ignore - } else { - bindgen::callbacks::MacroParsingBehavior::Default - } - } - } - - #[derive(Debug)] - struct RemoveEnumVariantSuffix { - enum_name: String, - variant_suffix: String - } - - impl RemoveEnumVariantSuffix { - fn new(enum_name: impl Into, variant_suffix: impl Into) -> Self { - Self { - enum_name: enum_name.into(), - variant_suffix: variant_suffix.into() - } - } - } - - impl bindgen::callbacks::ParseCallbacks for RemoveEnumVariantSuffix { - fn enum_variant_name(&self, enum_name: Option<&str>, original_variant_name: &str, _variant_value: bindgen::callbacks::EnumVariantValue) -> Option { - if enum_name != Some(&self.enum_name) { - return None; - } - - Some(original_variant_name.trim_end_matches(&self.variant_suffix).to_string()) - } - } - - let ignored_macros = IgnoreMacros( - vec![ - "FP_INFINITE".into(), - "FP_NAN".into(), - "FP_NORMAL".into(), - "FP_SUBNORMAL".into(), - "FP_ZERO".into(), - "IPPORT_RESERVED".into(), - "FP_INT_UPWARD".into(), - "FP_INT_DOWNWARD".into(), - "FP_INT_TOWARDZERO".into(), - "FP_INT_TONEARESTFROMZERO".into(), - "FP_INT_TONEAREST".into(), - ] - .into_iter() - .collect(), - ); - - let enum_suffixes = vec![ + let ignored_macros = IgnoreMacros::from_iter([ + "FP_INFINITE", + "FP_NAN", + "FP_NORMAL", + "FP_SUBNORMAL", + "FP_ZERO", + "IPPORT_RESERVED", + "FP_INT_UPWARD", + "FP_INT_DOWNWARD", + "FP_INT_TOWARDZERO", + "FP_INT_TONEARESTFROMZERO", + "FP_INT_TONEAREST", + ]); + + let remove_enum_suffixes = RemoveEnumVariantSuffixes::from_iter([ ("ClassType", "Class"), ("CompositeOperator", "CompositeOp"), ("GravityType", "Gravity"), @@ -225,7 +248,7 @@ fn main() { ("ComplexOperator", "ComplexOperator"), ("MontageMode", "Mode"), ("MagickCLDeviceType", "DeviceType"), - ("CommandOption", "Options"), // debatable + ("CommandOption", "Options"), ("ValidateType", "Validate"), ("CommandOptionFLags", "OptionFlag"), ("PolicyDomain", "PolicyDomain"), @@ -239,7 +262,7 @@ fn main() { ("AutoThresholdMethod", "ThresholdMethod"), ("PathType", "Path"), ("NoiseType", "Noise") - ]; + ]); if !Path::new(&bindings_path_str).exists() { // Create the header file that rust-bindgen needs as input. @@ -257,6 +280,7 @@ fn main() { .header(gen_h_path.to_str().unwrap()) .size_t_is_usize(true) .parse_callbacks(Box::new(ignored_macros)) + .parse_callbacks(Box::new(remove_enum_suffixes)) .blocklist_type("timex") .blocklist_function("clock_adjtime") .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: false }) @@ -266,11 +290,6 @@ fn main() { builder = builder.clang_arg(format!("-I{}", d.to_string_lossy())); } - for (enum_name, suffix) in enum_suffixes { - let remove_suffix = RemoveEnumVariantSuffix::new(enum_name, suffix); - builder = builder.parse_callbacks(Box::new(remove_suffix)); - } - let bindings = if cfg!(all(windows, target_pointer_width = "64")) { match builder.clone().generate() { Ok(bindings) => bindings, From 2377d7b872ad6a51ae15e47f38c16d2ad0ac7174 Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 24 Jul 2024 22:34:38 +0800 Subject: [PATCH 5/6] Prevent using the `bash` command when using MSVC This is to prevent a nasty issue where on fresh installations of Windows, the `bash` command returns with success and prints a prompt to install WSL, which gets mistaken for MagickCore-config output. --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index c14ac6fd..48138666 100644 --- a/build.rs +++ b/build.rs @@ -113,7 +113,7 @@ impl bindgen::callbacks::ParseCallbacks for RemoveEnumVariantSuffixes { } fn main() { - let check_cppflags = if cfg!(target_os = "windows") { + let check_cppflags = if cfg!(all(target_os = "windows", not(target_env = "msvc"))) { // Resolve bash from directories listed in the PATH environment variable in the // order they appear. Command::new("cmd") From e399e0de40b1046b974d8a8ff2ea26e4ec7f10a4 Mon Sep 17 00:00:00 2001 From: Thomas Bell Date: Wed, 24 Jul 2024 23:40:06 +0800 Subject: [PATCH 6/6] Windows installation documentation --- INSTALL.md | 61 ++++++++++++++++++++++++++++++------------------------ README.md | 12 ++--------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index cda36839..79fda240 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -45,38 +45,45 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ## Installing on Windows -So far nothing works. There are several problems that must be overcome: - -* Get an appropriate version of LLVM/Clang for your architecture (32 or 64 bit). -* Get an appropriate version of ImageMagick. -* Get the generated bindings to compile without error. - -[MSYS2](https://www.msys2.org/) looks neat and might work, but the compiled binary will only run with MSYS2. - -For LLVM/Clang, I found more success with the _windows_ file on the project [releases page](https://github.com/llvm/llvm-project/releases); it is a `.tar.xz` file that might be tricky to extract, but at least it seems to work. Other versions would fail during build time due to an error in the `LoadLibraryExW` function. - -The remaining problem, I believe, is getting an appropriate version of ImageMagick. I tried the _dll_ installers both with and without HDRI, but both resulted in build failures. The other _static_ files do not have any `.dll` files so they are not useful for building magick-rust. - -My conclusion is that building magick-rust on Windows is not possible. If you do find a way to build a portable binary that does not require a separate subsystem, such as MSYS2, please share extremely detailed and repeatable instructions. Thank you. - -### Nathan's notes - -This section will be replaced by working instructions, if any can ever be found. +Currently, the only way to build on Windows is from source, as the `.lib` files have been removed from the binary releases (see [ImageMagick#7272](https://github.com/ImageMagick/ImageMagick/issues/7272)). You will need to follow the below steps carefully. +1. Ensure you have installed Git and LLVM. The easiest way to do this on Windows is by using `winget`: +```powershell +winget install Git.Git +winget install LLVM.LLVM ``` -$Env:IMAGE_MAGICK_DIR = 'C:\bin\ImageMagick-7.1.1-Q16' -$Env:LIBCLANG_PATH = 'C:\bin\clang+llvm-18.1.7-x86_64-pc-windows-msvc\bin' +2. Ensure you have installed Visual Studio 2022, with the "C++ MFC for latest build tools (x86 & x64)". +3. Clone the [ImageMagick-Windows](https://github.com/ImageMagick/ImageMagick-Windows) repository to a well known place. The following instructions assume `C:\IM7`, but the choice does not matter: +```powershell +git clone https://github.com/ImageMagick/ImageMagick-Windows C:\IM7 ``` - -The weird build error: - +4. Run the `CloneRepositories.IM7.cmd` batch file from the source directory, but take care to include the SHA hash of the latest [ImageMagick](https://github.com/ImageMagick/ImageMagick) release (e.g. d775d2a for [7.1.1-35](https://github.com/ImageMagick/ImageMagick/releases/tag/7.1.1-35)): +```powershell +cd C:\IM7 +.\CloneRepositories.IM7.cmd d775d2a +``` +5. With Visual Studio 2022, open the `C:\IM7\Configure\Configure.sln` solution. +6. Build and run this application. You can use Ctrl+F5 as a shortcut. +7. Using the wizard, configure for "Dynamic Multi-Threaded DLL Runtimes". You can leave everything else as defaults. +8. Open the generated `C:\IM7\IM7.Dynamic.x64.sln` solution. +9. Change the run configuration from Debug to Release mode. +10. Build the solution using "Build Solution" under the "Build" menu, or press Ctrl+Shift+B. +12. Get a cup of coffee, because this will take a while to finish compiling. +13. Search for "Edit the system environment variables" in the Start menu and click on "Environment Variables..." +14. Add the following as system or user environment variables (replacing `C:\IM7` as appropriate): +```ini +IMAGE_MAGICK_DIR=C:\IM7\Output +IMAGE_MAGICK_INCLUDE_DIRS=C:\IM7\ImageMagick ``` -error[E0308]: mismatched types - --> src\types\style_type.rs:26:12 - | -26 | Bold = bindings::StyleType_BoldStyle, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `i32` +15. Add the following directory to your `PATH` variable: ``` +C:\IM7\Output\bin +``` +16. Once you have restarted your IDE or terminal to pick up on the changes, you may run `cargo build` in your project that includes `magick_rust` to confirm that ImageMagick is linked successfully. + +__NOTE:__ Keep in mind that these instructions will *dynamically* link your Rust application with the ImageMagick DLLs. Thus, when distributing your application, you will either need to provide these DLLs (found as `C:\IM7\Output\bin\*_RL_*_.dll`) in the same directory as your executable, or get your users to install the ImageMagick binary distribution. + +A set of instructions to enable static linkage of ImageMagick on Windows has yet to be found. ## Creating an Example diff --git a/README.md b/README.md index 13751015..7bf213b9 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Because this crate is generating bindings for a C/C++ library, there are several - [FreeBSD](https://www.freebsd.org): `sudo pkg install ImageMagick7` - [Homebrew](http://brew.sh): `brew install imagemagick` - Linux may require building ImageMagick from source, see the [INSTALL.md](./INSTALL.md) guide - - Windows: download `*-dll` [installer](https://www.imagemagick.org/script/download.php#windows). When installing, check the *Install development headers and libraries for C and C++* checkbox. + - Windows currently requires building from source, see [INSTALL.md](./INSTALL.md#installing-on-windows) * [Clang](https://clang.llvm.org) (version 5.0 or higher, as dictated by [rust-bindgen](https://github.com/rust-lang/rust-bindgen)) * Windows requires MSVC toolchain - Download the [Microsoft C++ Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) and select the `MSVC ... build tools` (latest version with appropriate architecture) and `Windows 11 SDK` (or `10` if using Windows 10). @@ -38,15 +38,7 @@ If `pkg-config` is not available, or you wish to override its behavior, you can ### Build on Windows -When building on Windows, you will need to set the `IMAGE_MAGICK_DIR` environment variable to point to the ImageMagick installation path. Maybe this is possible with the `set` command, but it may be necessary to set the variable in the system preferences. Without setting `IMAGE_MAGICK_DIR`, the `build.rs` script will try to run `pkg-config` which is a tool generally found on Unix-based systems. - -```shell -$Env:IMAGE_MAGICK_DIR = '' -cargo build -cargo test -``` - -If you are having trouble building on Windows, you are not alone. See the [INSTALL.md](./INSTALL.md) guide for the current state of affairs. +At the moment, building on Windows requires building from source. See [INSTALL.md](./INSTALL.md#installing-on-windows) for guidance. ## Documentation