1 | use std::ffi::CStr; |
2 | use std::str::from_utf8_unchecked; |
3 | |
4 | use ffi::AVColorPrimaries::*; |
5 | use ffi::*; |
6 | |
7 | #[derive (Eq, PartialEq, Clone, Copy, Debug)] |
8 | pub enum Primaries { |
9 | Reserved0, |
10 | BT709, |
11 | Unspecified, |
12 | Reserved, |
13 | BT470M, |
14 | |
15 | BT470BG, |
16 | SMPTE170M, |
17 | SMPTE240M, |
18 | Film, |
19 | BT2020, |
20 | |
21 | SMPTE428, |
22 | SMPTE431, |
23 | SMPTE432, |
24 | #[cfg (not(feature = "ffmpeg_4_3" ))] |
25 | JEDEC_P22, |
26 | #[cfg (feature = "ffmpeg_4_3" )] |
27 | EBU3213, |
28 | } |
29 | |
30 | impl Primaries { |
31 | #[cfg (feature = "ffmpeg_4_3" )] |
32 | pub const JEDEC_P22: Primaries = Primaries::EBU3213; |
33 | |
34 | pub fn name(&self) -> Option<&'static str> { |
35 | if *self == Primaries::Unspecified { |
36 | return None; |
37 | } |
38 | unsafe { |
39 | let ptr = av_color_primaries_name((*self).into()); |
40 | ptr.as_ref() |
41 | .map(|ptr: *const i8| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) |
42 | } |
43 | } |
44 | } |
45 | |
46 | impl From<AVColorPrimaries> for Primaries { |
47 | fn from(value: AVColorPrimaries) -> Primaries { |
48 | match value { |
49 | AVCOL_PRI_RESERVED0 => Primaries::Reserved0, |
50 | AVCOL_PRI_BT709 => Primaries::BT709, |
51 | AVCOL_PRI_UNSPECIFIED => Primaries::Unspecified, |
52 | AVCOL_PRI_RESERVED => Primaries::Reserved, |
53 | AVCOL_PRI_BT470M => Primaries::BT470M, |
54 | |
55 | AVCOL_PRI_BT470BG => Primaries::BT470BG, |
56 | AVCOL_PRI_SMPTE170M => Primaries::SMPTE170M, |
57 | AVCOL_PRI_SMPTE240M => Primaries::SMPTE240M, |
58 | AVCOL_PRI_FILM => Primaries::Film, |
59 | AVCOL_PRI_BT2020 => Primaries::BT2020, |
60 | AVCOL_PRI_NB => Primaries::Reserved0, |
61 | |
62 | AVCOL_PRI_SMPTE428 => Primaries::SMPTE428, |
63 | AVCOL_PRI_SMPTE431 => Primaries::SMPTE431, |
64 | AVCOL_PRI_SMPTE432 => Primaries::SMPTE432, |
65 | #[cfg (not(feature = "ffmpeg_4_3" ))] |
66 | AVCOL_PRI_JEDEC_P22 => Primaries::JEDEC_P22, |
67 | #[cfg (feature = "ffmpeg_4_3" )] |
68 | AVCOL_PRI_EBU3213 => Primaries::EBU3213, |
69 | } |
70 | } |
71 | } |
72 | |
73 | impl From<Primaries> for AVColorPrimaries { |
74 | fn from(value: Primaries) -> AVColorPrimaries { |
75 | match value { |
76 | Primaries::Reserved0 => AVCOL_PRI_RESERVED0, |
77 | Primaries::BT709 => AVCOL_PRI_BT709, |
78 | Primaries::Unspecified => AVCOL_PRI_UNSPECIFIED, |
79 | Primaries::Reserved => AVCOL_PRI_RESERVED, |
80 | Primaries::BT470M => AVCOL_PRI_BT470M, |
81 | |
82 | Primaries::BT470BG => AVCOL_PRI_BT470BG, |
83 | Primaries::SMPTE170M => AVCOL_PRI_SMPTE170M, |
84 | Primaries::SMPTE240M => AVCOL_PRI_SMPTE240M, |
85 | Primaries::Film => AVCOL_PRI_FILM, |
86 | Primaries::BT2020 => AVCOL_PRI_BT2020, |
87 | |
88 | Primaries::SMPTE428 => AVCOL_PRI_SMPTE428, |
89 | Primaries::SMPTE431 => AVCOL_PRI_SMPTE431, |
90 | Primaries::SMPTE432 => AVCOL_PRI_SMPTE432, |
91 | #[cfg (not(feature = "ffmpeg_4_3" ))] |
92 | Primaries::JEDEC_P22 => AVCOL_PRI_JEDEC_P22, |
93 | #[cfg (feature = "ffmpeg_4_3" )] |
94 | Primaries::EBU3213 => AVCOL_PRI_EBU3213, |
95 | } |
96 | } |
97 | } |
98 | |