Skip to main content

fret_core/
image.rs

1/// Color space metadata for image resources.
2///
3/// This is a portable, contract-level value type used across the runtime/renderer boundary.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum ImageColorSpace {
6    Srgb,
7    Linear,
8}
9
10impl ImageColorSpace {
11    pub const fn to_color_info(self) -> ImageColorInfo {
12        match self {
13            Self::Srgb => ImageColorInfo::srgb_rgba(),
14            Self::Linear => ImageColorInfo::linear_rgba(),
15        }
16    }
17}
18
19/// Stable metadata describing how to interpret pixel bytes for streaming images (ADR 0124).
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21pub struct ImageColorInfo {
22    pub encoding: ImageEncoding,
23    pub range: ColorRange,
24    pub matrix: YuvMatrix,
25    pub primaries: ColorPrimaries,
26    pub transfer: TransferFunction,
27    pub chroma_siting: Option<ChromaSiting>,
28}
29
30impl ImageColorInfo {
31    pub const fn srgb_rgba() -> Self {
32        Self {
33            encoding: ImageEncoding::Srgb,
34            range: ColorRange::Full,
35            matrix: YuvMatrix::Bt709,
36            primaries: ColorPrimaries::Bt709,
37            transfer: TransferFunction::Srgb,
38            chroma_siting: None,
39        }
40    }
41
42    pub const fn linear_rgba() -> Self {
43        Self {
44            encoding: ImageEncoding::Linear,
45            range: ColorRange::Full,
46            matrix: YuvMatrix::Bt709,
47            primaries: ColorPrimaries::Bt709,
48            transfer: TransferFunction::Linear,
49            chroma_siting: None,
50        }
51    }
52}
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
55pub enum ImageEncoding {
56    Srgb,
57    Linear,
58}
59
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
61pub enum ColorRange {
62    Full,
63    Limited,
64}
65
66#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
67pub enum YuvMatrix {
68    Bt601,
69    Bt709,
70    Bt2020,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
74pub enum ColorPrimaries {
75    Bt709,
76    Bt2020,
77    DisplayP3,
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
81pub enum TransferFunction {
82    Linear,
83    Srgb,
84    Bt709,
85    Pq,
86    Hlg,
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
90pub enum ChromaSiting {
91    Center,
92    Left,
93    TopLeft,
94}
95
96/// Explicit alpha semantics for image updates (ADR 0124 / ADR 0040).
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
98pub enum AlphaMode {
99    Opaque,
100    Premultiplied,
101    Straight,
102}