1use std::ffi::CStr;
2use std::str::from_utf8_unchecked;
3
4use ffi::AVColorTransferCharacteristic::*;
5use ffi::*;
6
7#[derive(Eq, PartialEq, Clone, Copy, Debug)]
8pub enum TransferCharacteristic {
9 Reserved0,
10 BT709,
11 Unspecified,
12 Reserved,
13 GAMMA22,
14 GAMMA28,
15 SMPTE170M,
16 SMPTE240M,
17 Linear,
18 Log,
19 LogSqrt,
20 IEC61966_2_4,
21 BT1361_ECG,
22 IEC61966_2_1,
23 BT2020_10,
24 BT2020_12,
25 SMPTE2084,
26 SMPTE428,
27 ARIB_STD_B67,
28}
29
30impl TransferCharacteristic {
31 pub fn name(&self) -> Option<&'static str> {
32 if *self == TransferCharacteristic::Unspecified {
33 return None;
34 }
35 unsafe {
36 let ptr = av_color_transfer_name((*self).into());
37 ptr.as_ref()
38 .map(|ptr: *const i8| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
39 }
40 }
41}
42
43impl From<AVColorTransferCharacteristic> for TransferCharacteristic {
44 fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic {
45 match value {
46 AVCOL_TRC_RESERVED0 => TransferCharacteristic::Reserved0,
47 AVCOL_TRC_BT709 => TransferCharacteristic::BT709,
48 AVCOL_TRC_UNSPECIFIED => TransferCharacteristic::Unspecified,
49 AVCOL_TRC_RESERVED => TransferCharacteristic::Reserved,
50 AVCOL_TRC_GAMMA22 => TransferCharacteristic::GAMMA22,
51 AVCOL_TRC_GAMMA28 => TransferCharacteristic::GAMMA28,
52 AVCOL_TRC_SMPTE170M => TransferCharacteristic::SMPTE170M,
53 AVCOL_TRC_SMPTE240M => TransferCharacteristic::SMPTE240M,
54 AVCOL_TRC_LINEAR => TransferCharacteristic::Linear,
55 AVCOL_TRC_LOG => TransferCharacteristic::Log,
56 AVCOL_TRC_LOG_SQRT => TransferCharacteristic::LogSqrt,
57 AVCOL_TRC_IEC61966_2_4 => TransferCharacteristic::IEC61966_2_4,
58 AVCOL_TRC_BT1361_ECG => TransferCharacteristic::BT1361_ECG,
59 AVCOL_TRC_IEC61966_2_1 => TransferCharacteristic::IEC61966_2_1,
60 AVCOL_TRC_BT2020_10 => TransferCharacteristic::BT2020_10,
61 AVCOL_TRC_BT2020_12 => TransferCharacteristic::BT2020_12,
62 AVCOL_TRC_NB => TransferCharacteristic::Reserved0,
63 AVCOL_TRC_SMPTE2084 => TransferCharacteristic::SMPTE2084,
64 AVCOL_TRC_SMPTE428 => TransferCharacteristic::SMPTE428,
65 AVCOL_TRC_ARIB_STD_B67 => TransferCharacteristic::ARIB_STD_B67,
66 }
67 }
68}
69
70impl From<TransferCharacteristic> for AVColorTransferCharacteristic {
71 fn from(value: TransferCharacteristic) -> AVColorTransferCharacteristic {
72 match value {
73 TransferCharacteristic::Reserved0 => AVCOL_TRC_RESERVED0,
74 TransferCharacteristic::BT709 => AVCOL_TRC_BT709,
75 TransferCharacteristic::Unspecified => AVCOL_TRC_UNSPECIFIED,
76 TransferCharacteristic::Reserved => AVCOL_TRC_RESERVED,
77 TransferCharacteristic::GAMMA22 => AVCOL_TRC_GAMMA22,
78 TransferCharacteristic::GAMMA28 => AVCOL_TRC_GAMMA28,
79 TransferCharacteristic::SMPTE170M => AVCOL_TRC_SMPTE170M,
80 TransferCharacteristic::SMPTE240M => AVCOL_TRC_SMPTE240M,
81 TransferCharacteristic::Linear => AVCOL_TRC_LINEAR,
82 TransferCharacteristic::Log => AVCOL_TRC_LOG,
83 TransferCharacteristic::LogSqrt => AVCOL_TRC_LOG_SQRT,
84 TransferCharacteristic::IEC61966_2_4 => AVCOL_TRC_IEC61966_2_4,
85 TransferCharacteristic::BT1361_ECG => AVCOL_TRC_BT1361_ECG,
86 TransferCharacteristic::IEC61966_2_1 => AVCOL_TRC_IEC61966_2_1,
87 TransferCharacteristic::BT2020_10 => AVCOL_TRC_BT2020_10,
88 TransferCharacteristic::BT2020_12 => AVCOL_TRC_BT2020_12,
89 TransferCharacteristic::SMPTE2084 => AVCOL_TRC_SMPTE2084,
90 TransferCharacteristic::SMPTE428 => AVCOL_TRC_SMPTE428,
91 TransferCharacteristic::ARIB_STD_B67 => AVCOL_TRC_ARIB_STD_B67,
92 }
93 }
94}
95