Add OrientationType type

This commit is contained in:
5ohue
2024-05-11 14:22:49 +03:00
parent 0c987e7860
commit db0044fa07
4 changed files with 54 additions and 15 deletions

View File

@ -8,8 +8,9 @@ mod endian_type;
mod filter_type;
mod gravity_type;
mod interlace_type;
mod pixel_interpolate_method;
mod metric_type;
mod orientation_type;
mod pixel_interpolate_method;
mod resource_type;
pub use self::alpha_channel_option::AlphaChannelOption;
@ -22,6 +23,7 @@ pub use self::endian_type::EndianType;
pub use self::filter_type::FilterType;
pub use self::gravity_type::GravityType;
pub use self::interlace_type::InterlaceType;
pub use self::pixel_interpolate_method::PixelInterpolateMethod;
pub use self::metric_type::MetricType;
pub use self::orientation_type::OrientationType;
pub use self::pixel_interpolate_method::PixelInterpolateMethod;
pub use self::resource_type::ResourceType;

View File

@ -0,0 +1,44 @@
use crate::bindings;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum OrientationType {
Undefined = bindings::OrientationType_UndefinedOrientation,
TopLeft = bindings::OrientationType_TopLeftOrientation,
TopRight = bindings::OrientationType_TopRightOrientation,
BottomRight = bindings::OrientationType_BottomRightOrientation,
BottomLeft = bindings::OrientationType_BottomLeftOrientation,
LeftTop = bindings::OrientationType_LeftTopOrientation,
RightTop = bindings::OrientationType_RightTopOrientation,
RightBottom = bindings::OrientationType_RightBottomOrientation,
LeftBottom = bindings::OrientationType_LeftBottomOrientation,
}
impl Default for OrientationType {
fn default() -> Self {
return OrientationType::Undefined;
}
}
impl From<OrientationType> for bindings::OrientationType {
fn from(value: OrientationType) -> Self {
return value as bindings::OrientationType;
}
}
impl From<bindings::OrientationType> for OrientationType {
fn from(value: bindings::OrientationType) -> Self {
/*
* SAFETY:
*
* `OrientationType` has the same repr as `bindings::OrientationType` - u32
*
* If `value` is less than LeftBottom than it is in the vaild range and can be safely
* reinterpreted as `OrientationType`
*/
if value <= bindings::OrientationType_LeftBottomOrientation {
return unsafe { std::mem::transmute(value) };
}
return OrientationType::default();
}
}

View File

@ -41,8 +41,9 @@ use crate::{
FilterType,
GravityType,
InterlaceType,
PixelInterpolateMethod,
MetricType,
OrientationType,
PixelInterpolateMethod,
ResourceType
};
@ -884,10 +885,7 @@ impl MagickWand {
/// Detect if the loaded image is not in top-left orientation, and
/// hence should be "auto" oriented so it is suitable for viewing.
pub fn requires_orientation(&self) -> bool {
unsafe {
bindings::MagickGetImageOrientation(self.wand)
!= bindings::OrientationType_TopLeftOrientation
}
return self.get_image_orientation() != OrientationType::TopLeft;
}
/// Automatically adjusts the loaded image so that its orientation is
@ -1192,7 +1190,7 @@ impl MagickWand {
get_image_interlace_scheme, set_image_interlace_scheme, MagickGetImageInterlaceScheme, MagickSetImageInterlaceScheme, InterlaceType
get_image_interpolate_method, set_image_interpolate_method, MagickGetImageInterpolateMethod, MagickSetImageInterpolateMethod, PixelInterpolateMethod
get_image_iterations, set_image_iterations, MagickGetImageIterations, MagickSetImageIterations, usize
get_image_orientation, set_image_orientation, MagickGetImageOrientation, MagickSetImageOrientation, bindings::OrientationType
get_image_orientation, set_image_orientation, MagickGetImageOrientation, MagickSetImageOrientation, OrientationType
get_image_rendering_intent, set_image_rendering_intent, MagickGetImageRenderingIntent, MagickSetImageRenderingIntent, bindings::RenderingIntent
get_image_scene, set_image_scene, MagickGetImageScene, MagickSetImageScene, usize
get_image_type, set_image_type, MagickGetImageType, MagickSetImageType, bindings::ImageType
@ -1200,7 +1198,7 @@ impl MagickWand {
get_interlace_scheme, set_interlace_scheme, MagickGetInterlaceScheme, MagickSetInterlaceScheme, InterlaceType
get_interpolate_method, set_interpolate_method, MagickGetInterpolateMethod, MagickSetInterpolateMethod, PixelInterpolateMethod
get_iterator_index, set_iterator_index, MagickGetIteratorIndex, MagickSetIteratorIndex, isize
get_orientation, set_orientation, MagickGetOrientation, MagickSetOrientation, bindings::OrientationType
get_orientation, set_orientation, MagickGetOrientation, MagickSetOrientation, OrientationType
get_pointsize, set_pointsize, MagickGetPointsize, MagickSetPointsize, f64
get_type, set_type, MagickGetType, MagickSetType, bindings::ImageType
);

View File

@ -16,11 +16,6 @@
use std::ffi::{CStr, CString};
use std::fmt;
#[cfg(target_os = "freebsd")]
use libc::size_t;
#[cfg(not(target_os = "freebsd"))]
use size_t;
use bindings;
use result::MagickError;
@ -99,7 +94,7 @@ impl PixelWand {
);
set_get_unchecked!(
get_color_count, set_color_count, PixelGetColorCount, PixelSetColorCount, size_t
get_color_count, set_color_count, PixelGetColorCount, PixelSetColorCount, usize
get_index, set_index, PixelGetIndex, PixelSetIndex, f32
get_fuzz, set_fuzz, PixelGetFuzz, PixelSetFuzz, f64
);