Add artifact related functions

This makes it possible to blend images with user configurable percent
(see `set_image_artifact` documentation)
This commit is contained in:
5ohue
2024-05-11 21:29:36 +03:00
parent 1a66649c47
commit b8147a2b06
3 changed files with 251 additions and 4 deletions

View File

@ -15,6 +15,7 @@ mod pixel_interpolate_method;
mod rendering_intent;
mod resolution_type;
mod resource_type;
mod statistic_type;
pub use self::alpha_channel_option::AlphaChannelOption;
pub use self::colorspace_type::ColorspaceType;
@ -33,3 +34,4 @@ pub use self::pixel_interpolate_method::PixelInterpolateMethod;
pub use self::rendering_intent::RenderingIntent;
pub use self::resolution_type::ResolutionType;
pub use self::resource_type::ResourceType;
pub use self::statistic_type::StatisticType;

View File

@ -0,0 +1,46 @@
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<StatisticType> for bindings::StatisticType {
fn from(value: StatisticType) -> Self {
return value as bindings::StatisticType;
}
}
impl From<bindings::StatisticType> 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();
}
}