skia_safe/effects/
high_contrast_filter.rs

1use crate::{high_contrast_config::InvertStyle, prelude::*, scalar, ColorFilter};
2use skia_bindings::{self as sb, SkHighContrastConfig};
3
4pub mod high_contrast_config {
5    pub use skia_bindings::SkHighContrastConfig_InvertStyle as InvertStyle;
6    #[test]
7    fn invert_style_naming() {
8        let _ = InvertStyle::InvertLightness;
9    }
10}
11
12#[repr(C)]
13#[derive(Clone, PartialEq, Debug)]
14pub struct HighContrastConfig {
15    pub grayscale: bool,
16    pub invert_style: InvertStyle,
17    pub contrast: scalar,
18}
19
20native_transmutable!(
21    SkHighContrastConfig,
22    HighContrastConfig,
23    high_contrast_config
24);
25
26impl Default for HighContrastConfig {
27    fn default() -> Self {
28        Self {
29            grayscale: false,
30            invert_style: InvertStyle::NoInvert,
31            contrast: 0.0,
32        }
33    }
34}
35
36impl HighContrastConfig {
37    pub fn new(grayscale: bool, invert_style: InvertStyle, contrast: scalar) -> Self {
38        Self {
39            grayscale,
40            invert_style,
41            contrast,
42        }
43    }
44
45    pub fn is_valid(&self) -> bool {
46        self.contrast >= -1.0 && self.contrast <= 1.0
47    }
48}
49
50impl ColorFilter {
51    pub fn high_contrast(config: &HighContrastConfig) -> Option<Self> {
52        new(config)
53    }
54}
55
56pub fn new(config: &HighContrastConfig) -> Option<ColorFilter> {
57    ColorFilter::from_ptr(unsafe { sb::C_SkHighContrastFilter_Make(config.native()) })
58}