ezk_image/color/
mod.rs

1pub(crate) mod primaries;
2pub(crate) mod space;
3pub(crate) mod transfer;
4
5pub use primaries::ColorPrimaries;
6pub use space::ColorSpace;
7pub use transfer::ColorTransfer;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub struct RgbColorInfo {
11    pub transfer: ColorTransfer,
12    pub primaries: ColorPrimaries,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct YuvColorInfo {
17    pub transfer: ColorTransfer,
18    pub primaries: ColorPrimaries,
19    pub space: ColorSpace,
20    /// If the image uses either full or standard range
21    ///
22    /// - full range (0 - 255)
23    /// - standard range Y (16 - 235), U & V (16 - 240)
24    pub full_range: bool,
25}
26
27/// Color space of an image
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum ColorInfo {
30    RGB(RgbColorInfo),
31    YUV(YuvColorInfo),
32}
33
34impl ColorInfo {
35    pub fn primaries(&self) -> ColorPrimaries {
36        match self {
37            ColorInfo::RGB(rgb) => rgb.primaries,
38            ColorInfo::YUV(yuv) => yuv.primaries,
39        }
40    }
41
42    pub fn transfer(&self) -> ColorTransfer {
43        match self {
44            ColorInfo::RGB(rgb) => rgb.transfer,
45            ColorInfo::YUV(yuv) => yuv.transfer,
46        }
47    }
48}
49
50impl From<RgbColorInfo> for ColorInfo {
51    fn from(value: RgbColorInfo) -> Self {
52        ColorInfo::RGB(value)
53    }
54}
55
56impl From<YuvColorInfo> for ColorInfo {
57    fn from(value: YuvColorInfo) -> Self {
58        ColorInfo::YUV(value)
59    }
60}
61
62pub(crate) mod mat_idxs {
63    pub(crate) const Y: usize = 0;
64    pub(crate) const U: usize = 1;
65    pub(crate) const V: usize = 2;
66
67    pub(crate) const R: usize = 0;
68    pub(crate) const G: usize = 1;
69    pub(crate) const B: usize = 2;
70}