use crate::image::white_level_from_bit_depth;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum ColorSpace {
Srgb,
#[default]
LinearSrgb,
DisplayP3,
Rec2020,
AdobeRgb,
ProPhotoRgb,
Unknown,
}
impl ColorSpace {
pub fn name(self) -> &'static str {
match self {
ColorSpace::Srgb => "sRGB",
ColorSpace::LinearSrgb => "Linear sRGB",
ColorSpace::DisplayP3 => "Display P3",
ColorSpace::Rec2020 => "Rec. 2020",
ColorSpace::AdobeRgb => "Adobe RGB",
ColorSpace::ProPhotoRgb => "ProPhoto RGB",
ColorSpace::Unknown => "Unknown",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum BitDepth {
Eight,
#[default]
Sixteen,
}
impl BitDepth {
pub fn bits(self) -> u8 {
match self {
BitDepth::Eight => 8,
BitDepth::Sixteen => 16,
}
}
pub fn max_value(self) -> u16 {
white_level_from_bit_depth(self.bits())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bit_depth_bits_and_max() {
assert_eq!(BitDepth::Eight.bits(), 8);
assert_eq!(BitDepth::Sixteen.bits(), 16);
assert_eq!(BitDepth::Eight.max_value(), 255);
assert_eq!(BitDepth::Sixteen.max_value(), u16::MAX);
assert_eq!(BitDepth::default(), BitDepth::Sixteen);
}
#[test]
fn color_space_defaults_and_names() {
assert_eq!(ColorSpace::default(), ColorSpace::LinearSrgb);
assert_eq!(ColorSpace::Srgb.name(), "sRGB");
assert_eq!(ColorSpace::Unknown.name(), "Unknown");
}
}