Add InterlaceType type

This commit is contained in:
5ohue
2024-05-11 14:12:31 +03:00
parent 8870068f27
commit 5a3cb8a04d
3 changed files with 49 additions and 3 deletions

View File

@ -0,0 +1,43 @@
use crate::bindings;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum InterlaceType {
Undefined = bindings::InterlaceType_UndefinedInterlace,
No = bindings::InterlaceType_NoInterlace,
Line = bindings::InterlaceType_LineInterlace,
Plane = bindings::InterlaceType_PlaneInterlace,
Partition = bindings::InterlaceType_PartitionInterlace,
GIF = bindings::InterlaceType_GIFInterlace,
JPEG = bindings::InterlaceType_JPEGInterlace,
PNG = bindings::InterlaceType_PNGInterlace,
}
impl Default for InterlaceType {
fn default() -> Self {
return InterlaceType::Undefined;
}
}
impl From<InterlaceType> for bindings::InterlaceType {
fn from(value: InterlaceType) -> Self {
return value as bindings::InterlaceType;
}
}
impl From<bindings::InterlaceType> for InterlaceType {
fn from(value: bindings::InterlaceType) -> Self {
/*
* SAFETY:
*
* `InterlaceType` has the same repr as `bindings::InterlaceType` - u32
*
* If `value` is less than PNG than it is in the vaild range and can be safely
* reinterpreted as `InterlaceType`
*/
if value <= bindings::InterlaceType_PNGInterlace {
return unsafe { std::mem::transmute(value) };
}
return InterlaceType::default();
}
}

View File

@ -6,6 +6,7 @@ mod dispose_type;
mod dither_method;
mod filter_type;
mod gravity_type;
mod interlace_type;
mod pixel_interpolate_method;
mod metric_type;
mod resource_type;
@ -18,6 +19,7 @@ pub use self::dispose_type::DisposeType;
pub use self::dither_method::DitherMethod;
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::resource_type::ResourceType;