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!(SkHighContrastConfig, HighContrastConfig);
21
22impl Default for HighContrastConfig {
23    fn default() -> Self {
24        Self {
25            grayscale: false,
26            invert_style: InvertStyle::NoInvert,
27            contrast: 0.0,
28        }
29    }
30}
31
32impl HighContrastConfig {
33    pub fn new(grayscale: bool, invert_style: InvertStyle, contrast: scalar) -> Self {
34        Self {
35            grayscale,
36            invert_style,
37            contrast,
38        }
39    }
40
41    pub fn is_valid(&self) -> bool {
42        self.contrast >= -1.0 && self.contrast <= 1.0
43    }
44}
45
46impl ColorFilter {
47    pub fn high_contrast(config: &HighContrastConfig) -> Option<Self> {
48        new(config)
49    }
50}
51
52pub fn new(config: &HighContrastConfig) -> Option<ColorFilter> {
53    ColorFilter::from_ptr(unsafe { sb::C_SkHighContrastFilter_Make(config.native()) })
54}