1use std::ffi::CStr;
2use std::str::from_utf8_unchecked;
3
4use ffi::AVColorSpace::*;
5use ffi::*;
6
7#[derive(Eq, PartialEq, Clone, Copy, Debug)]
8pub enum Space {
9 RGB,
10 BT709,
11 Unspecified,
12 Reserved,
13 FCC,
14 BT470BG,
15 SMPTE170M,
16 SMPTE240M,
17 YCGCO,
18 BT2020NCL,
19 BT2020CL,
20 SMPTE2085,
21
22 ChromaDerivedNCL,
23 ChromaDerivedCL,
24 ICTCP,
25}
26
27impl Space {
28 pub const YCOCG: Space = Space::YCGCO;
29
30 pub fn name(&self) -> Option<&'static str> {
31 if *self == Space::Unspecified {
32 return None;
33 }
34 unsafe {
35 let ptr = av_color_space_name((*self).into());
36 ptr.as_ref()
37 .map(|ptr: *const i8| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
38 }
39 }
40}
41
42impl From<AVColorSpace> for Space {
43 fn from(value: AVColorSpace) -> Self {
44 match value {
45 AVCOL_SPC_RGB => Space::RGB,
46 AVCOL_SPC_BT709 => Space::BT709,
47 AVCOL_SPC_UNSPECIFIED => Space::Unspecified,
48 AVCOL_SPC_RESERVED => Space::Reserved,
49 AVCOL_SPC_FCC => Space::FCC,
50 AVCOL_SPC_BT470BG => Space::BT470BG,
51 AVCOL_SPC_SMPTE170M => Space::SMPTE170M,
52 AVCOL_SPC_SMPTE240M => Space::SMPTE240M,
53 AVCOL_SPC_YCGCO => Space::YCGCO,
54 AVCOL_SPC_BT2020_NCL => Space::BT2020NCL,
55 AVCOL_SPC_BT2020_CL => Space::BT2020CL,
56 AVCOL_SPC_SMPTE2085 => Space::SMPTE2085,
57 AVCOL_SPC_NB => Space::Unspecified,
58
59 AVCOL_SPC_CHROMA_DERIVED_NCL => Space::ChromaDerivedNCL,
60 AVCOL_SPC_CHROMA_DERIVED_CL => Space::ChromaDerivedCL,
61 AVCOL_SPC_ICTCP => Space::ICTCP,
62 }
63 }
64}
65
66impl From<Space> for AVColorSpace {
67 fn from(value: Space) -> AVColorSpace {
68 match value {
69 Space::RGB => AVCOL_SPC_RGB,
70 Space::BT709 => AVCOL_SPC_BT709,
71 Space::Unspecified => AVCOL_SPC_UNSPECIFIED,
72 Space::Reserved => AVCOL_SPC_RESERVED,
73 Space::FCC => AVCOL_SPC_FCC,
74 Space::BT470BG => AVCOL_SPC_BT470BG,
75 Space::SMPTE170M => AVCOL_SPC_SMPTE170M,
76 Space::SMPTE240M => AVCOL_SPC_SMPTE240M,
77 Space::YCGCO => AVCOL_SPC_YCGCO,
78 Space::BT2020NCL => AVCOL_SPC_BT2020_NCL,
79 Space::BT2020CL => AVCOL_SPC_BT2020_CL,
80 Space::SMPTE2085 => AVCOL_SPC_SMPTE2085,
81
82 Space::ChromaDerivedNCL => AVCOL_SPC_CHROMA_DERIVED_NCL,
83 Space::ChromaDerivedCL => AVCOL_SPC_CHROMA_DERIVED_CL,
84 Space::ICTCP => AVCOL_SPC_ICTCP,
85 }
86 }
87}
88