#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ColorSpace {
Srgb,
DisplayP3,
A98Rgb,
ProphotoRgb,
Rec2020,
}
impl PartialOrd for ColorSpace {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
if self == other {
return Some(core::cmp::Ordering::Equal);
}
let self_contains_other = self.contains(*other);
let other_contains_self = other.contains(*self);
match (self_contains_other, other_contains_self) {
(true, false) => Some(core::cmp::Ordering::Greater),
(false, true) => Some(core::cmp::Ordering::Less),
_ => None,
}
}
}
impl ColorSpace {
pub fn contains(self, other: ColorSpace) -> bool {
if self == other {
return true;
}
match self {
ColorSpace::Srgb => false,
ColorSpace::DisplayP3 => other == ColorSpace::Srgb,
ColorSpace::A98Rgb => other == ColorSpace::Srgb,
ColorSpace::ProphotoRgb => other != ColorSpace::ProphotoRgb,
ColorSpace::Rec2020 => matches!(other, ColorSpace::Srgb | ColorSpace::DisplayP3),
}
}
}