From 254ea6c77191c488ae0c7940ff299df1a9384f9c Mon Sep 17 00:00:00 2001 From: 5ohue <86558263+5ohue@users.noreply.github.com> Date: Sat, 11 May 2024 14:04:11 +0300 Subject: [PATCH] Add `CompressionType` type --- src/types/compression_type.rs | 64 +++++++++++++++++++++++++++++++++++ src/types/mod.rs | 2 ++ src/wand/magick.rs | 5 +-- src/wand/pixel.rs | 2 +- 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/types/compression_type.rs diff --git a/src/types/compression_type.rs b/src/types/compression_type.rs new file mode 100644 index 0000000..3a3799d --- /dev/null +++ b/src/types/compression_type.rs @@ -0,0 +1,64 @@ +use crate::bindings; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum CompressionType { + Undefined = bindings::CompressionType_UndefinedCompression, + B44A = bindings::CompressionType_B44ACompression, + B44 = bindings::CompressionType_B44Compression, + BZip = bindings::CompressionType_BZipCompression, + DXT1 = bindings::CompressionType_DXT1Compression, + DXT3 = bindings::CompressionType_DXT3Compression, + DXT5 = bindings::CompressionType_DXT5Compression, + Fax = bindings::CompressionType_FaxCompression, + Group4 = bindings::CompressionType_Group4Compression, + JBIG1 = bindings::CompressionType_JBIG1Compression, + JBIG2 = bindings::CompressionType_JBIG2Compression, + JPEG2000 = bindings::CompressionType_JPEG2000Compression, + JPEG = bindings::CompressionType_JPEGCompression, + LosslessJPEG = bindings::CompressionType_LosslessJPEGCompression, + LZMA = bindings::CompressionType_LZMACompression, + LZW = bindings::CompressionType_LZWCompression, + No = bindings::CompressionType_NoCompression, + Piz = bindings::CompressionType_PizCompression, + Pxr24 = bindings::CompressionType_Pxr24Compression, + RLE = bindings::CompressionType_RLECompression, + Zip = bindings::CompressionType_ZipCompression, + ZipS = bindings::CompressionType_ZipSCompression, + Zstd = bindings::CompressionType_ZstdCompression, + WebP = bindings::CompressionType_WebPCompression, + DWAA = bindings::CompressionType_DWAACompression, + DWAB = bindings::CompressionType_DWABCompression, + BC7 = bindings::CompressionType_BC7Compression, + BC5 = bindings::CompressionType_BC5Compression, + LERC = bindings::CompressionType_LERCCompression, +} + +impl Default for CompressionType { + fn default() -> Self { + return CompressionType::Undefined; + } +} + +impl From 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/mod.rs b/src/types/mod.rs index 7a652b0..463620c 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,6 +1,7 @@ mod alpha_channel_option; mod colorspace_type; mod composite_operator; +mod compression_type; mod dither_method; mod filter_type; mod gravity_type; @@ -11,6 +12,7 @@ mod resource_type; pub use self::alpha_channel_option::AlphaChannelOption; pub use self::colorspace_type::ColorspaceType; pub use self::composite_operator::CompositeOperator; +pub use self::compression_type::CompressionType; pub use self::dither_method::DitherMethod; pub use self::filter_type::FilterType; pub use self::gravity_type::GravityType; diff --git a/src/wand/magick.rs b/src/wand/magick.rs index fd91938..827deaf 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -34,6 +34,7 @@ use crate::{ AlphaChannelOption, ColorspaceType, CompositeOperator, + CompressionType, DitherMethod, FilterType, GravityType, @@ -1172,11 +1173,11 @@ impl MagickWand { set_get!( get_colorspace, set_colorspace, MagickGetColorspace, MagickSetColorspace, ColorspaceType get_image_compose, set_image_compose, MagickGetImageCompose, MagickSetImageCompose, CompositeOperator - get_compression, set_compression, MagickGetCompression, MagickSetCompression, bindings::CompressionType + get_compression, set_compression, MagickGetCompression, MagickSetCompression, CompressionType get_compression_quality, set_compression_quality, MagickGetCompressionQuality, MagickSetCompressionQuality, usize get_gravity, set_gravity, MagickGetGravity, MagickSetGravity, GravityType get_image_colorspace, set_image_colorspace, MagickGetImageColorspace, MagickSetImageColorspace, ColorspaceType - get_image_compression, set_image_compression, MagickGetImageCompression, MagickSetImageCompression, bindings::CompressionType + get_image_compression, set_image_compression, MagickGetImageCompression, MagickSetImageCompression, CompressionType get_image_compression_quality, set_image_compression_quality, MagickGetImageCompressionQuality, MagickSetImageCompressionQuality, usize get_image_delay, set_image_delay, MagickGetImageDelay, MagickSetImageDelay, usize get_image_depth, set_image_depth, MagickGetImageDepth, MagickSetImageDepth, usize diff --git a/src/wand/pixel.rs b/src/wand/pixel.rs index d10ff0a..d51f1d8 100644 --- a/src/wand/pixel.rs +++ b/src/wand/pixel.rs @@ -100,7 +100,7 @@ impl PixelWand { set_get_unchecked!( get_color_count, set_color_count, PixelGetColorCount, PixelSetColorCount, size_t - get_index, set_index, PixelGetIndex, PixelSetIndex, bindings::Quantum + get_index, set_index, PixelGetIndex, PixelSetIndex, f32 get_fuzz, set_fuzz, PixelGetFuzz, PixelSetFuzz, f64 );