1use pixman_sys as ffi;
2use thiserror::Error;
3
4#[derive(Debug, Clone, Copy)]
6pub enum Dither {
7 None,
9 Fast,
11 Good,
13 Best,
15 OrderedBayer8,
17 OrderedBlueNoise64,
19}
20
21#[derive(Debug, Error)]
23#[error("Unknown dither {0}")]
24pub struct UnknownDither(ffi::pixman_dither_t);
25
26impl TryFrom<ffi::pixman_dither_t> for Dither {
27 type Error = UnknownDither;
28
29 fn try_from(value: ffi::pixman_dither_t) -> Result<Self, Self::Error> {
30 let repeat = match value {
31 ffi::pixman_dither_t_PIXMAN_DITHER_NONE => Dither::None,
32 ffi::pixman_dither_t_PIXMAN_DITHER_FAST => Dither::Fast,
33 ffi::pixman_dither_t_PIXMAN_DITHER_GOOD => Dither::Good,
34 ffi::pixman_dither_t_PIXMAN_DITHER_BEST => Dither::Best,
35 ffi::pixman_dither_t_PIXMAN_DITHER_ORDERED_BAYER_8 => Dither::OrderedBayer8,
36 ffi::pixman_dither_t_PIXMAN_DITHER_ORDERED_BLUE_NOISE_64 => Dither::OrderedBlueNoise64,
37 _ => return Err(UnknownDither(value)),
38 };
39 Ok(repeat)
40 }
41}
42
43impl From<Dither> for ffi::pixman_dither_t {
44 fn from(value: Dither) -> Self {
45 match value {
46 Dither::None => ffi::pixman_dither_t_PIXMAN_DITHER_NONE,
47 Dither::Fast => ffi::pixman_dither_t_PIXMAN_DITHER_FAST,
48 Dither::Good => ffi::pixman_dither_t_PIXMAN_DITHER_GOOD,
49 Dither::Best => ffi::pixman_dither_t_PIXMAN_DITHER_BEST,
50 Dither::OrderedBayer8 => ffi::pixman_dither_t_PIXMAN_DITHER_ORDERED_BAYER_8,
51 Dither::OrderedBlueNoise64 => ffi::pixman_dither_t_PIXMAN_DITHER_ORDERED_BLUE_NOISE_64,
52 }
53 }
54}