chromashift/
color_space.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum ColorSpace {
15 Srgb,
16 DisplayP3,
17 A98Rgb,
18 ProphotoRgb,
19 Rec2020,
20}
21
22impl PartialOrd for ColorSpace {
23 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
24 if self == other {
25 return Some(core::cmp::Ordering::Equal);
26 }
27 let self_contains_other = self.contains(*other);
28 let other_contains_self = other.contains(*self);
29 match (self_contains_other, other_contains_self) {
30 (true, false) => Some(core::cmp::Ordering::Greater),
31 (false, true) => Some(core::cmp::Ordering::Less),
32 _ => None,
33 }
34 }
35}
36
37impl ColorSpace {
38 pub fn contains(self, other: ColorSpace) -> bool {
40 if self == other {
41 return true;
42 }
43 match self {
44 ColorSpace::Srgb => false,
45 ColorSpace::DisplayP3 => other == ColorSpace::Srgb,
46 ColorSpace::A98Rgb => other == ColorSpace::Srgb,
47 ColorSpace::ProphotoRgb => other != ColorSpace::ProphotoRgb,
48 ColorSpace::Rec2020 => matches!(other, ColorSpace::Srgb | ColorSpace::DisplayP3),
49 }
50 }
51}