From 22ccc04f2d3dc37f1e058eb3fbd8b3753d04e18b Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Fri, 14 Sep 2018 21:06:56 -0400 Subject: [PATCH] util::color: implement .name() for {Primaries, Range, TransferCharacteristic} --- src/util/color/primaries.rs | 12 ++++++++++++ src/util/color/range.rs | 12 ++++++++++++ src/util/color/transfer_characteristic.rs | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/util/color/primaries.rs b/src/util/color/primaries.rs index 3b69b75b..e94fa5f8 100644 --- a/src/util/color/primaries.rs +++ b/src/util/color/primaries.rs @@ -23,6 +23,18 @@ pub enum Primaries { EBU3213, } +impl Primaries { + pub fn name(&self) -> Option<&'static str> { + if *self == Primaries::Unspecified { + return None; + } + unsafe { + let ptr = av_color_primaries_name((*self).into()); + ptr.as_ref().map(|ptr| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) + } + } +} + impl From for Primaries { fn from(value: AVColorPrimaries) -> Primaries { match value { diff --git a/src/util/color/range.rs b/src/util/color/range.rs index 2b978074..936fa26c 100644 --- a/src/util/color/range.rs +++ b/src/util/color/range.rs @@ -9,6 +9,18 @@ pub enum Range { JPEG, } +impl Range { + pub fn name(&self) -> Option<&'static str> { + if *self == Range::Unspecified { + return None; + } + unsafe { + let ptr = av_color_range_name((*self).into()); + ptr.as_ref().map(|ptr| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) + } + } +} + impl From for Range { fn from(value: AVColorRange) -> Self { match value { diff --git a/src/util/color/transfer_characteristic.rs b/src/util/color/transfer_characteristic.rs index ec485032..f736478d 100644 --- a/src/util/color/transfer_characteristic.rs +++ b/src/util/color/transfer_characteristic.rs @@ -25,6 +25,18 @@ pub enum TransferCharacteristic { ARIB_STD_B67, } +impl TransferCharacteristic { + pub fn name(&self) -> Option<&'static str> { + if *self == TransferCharacteristic::Unspecified { + return None; + } + unsafe { + let ptr = av_color_transfer_name((*self).into()); + ptr.as_ref().map(|ptr| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) + } + } +} + impl From for TransferCharacteristic { fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic { match value {