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();
}
}