diff --git a/src/util/color/primaries.rs b/src/util/color/primaries.rs index a9d2655..b827125 100644 --- a/src/util/color/primaries.rs +++ b/src/util/color/primaries.rs @@ -1,3 +1,6 @@ +use std::ffi::CStr; +use std::str::from_utf8_unchecked; + use ffi::AVColorPrimaries::*; use ffi::*; @@ -21,6 +24,19 @@ pub enum Primaries { JEDEC_P22, } +impl Primaries { + pub fn name(&self) -> Option<&'static str> { + unsafe { + let ptr = av_color_primaries_name((*self).into()); + if ptr.is_null() { + None + } else { + Some(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 6fc8aa9..a440844 100644 --- a/src/util/color/range.rs +++ b/src/util/color/range.rs @@ -1,3 +1,6 @@ +use std::ffi::CStr; +use std::str::from_utf8_unchecked; + use ffi::AVColorRange::*; use ffi::*; @@ -8,6 +11,19 @@ pub enum Range { JPEG, } +impl Range { + pub fn name(&self) -> Option<&'static str> { + unsafe { + let ptr = av_color_range_name((*self).into()); + if ptr.is_null() { + None + } else { + Some(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 094a48b..b6c3fa9 100644 --- a/src/util/color/transfer_characteristic.rs +++ b/src/util/color/transfer_characteristic.rs @@ -1,3 +1,6 @@ +use std::ffi::CStr; +use std::str::from_utf8_unchecked; + use ffi::AVColorTransferCharacteristic::*; use ffi::*; @@ -24,6 +27,19 @@ pub enum TransferCharacteristic { ARIB_STD_B67, } +impl TransferCharacteristic { + pub fn name(&self) -> Option<&'static str> { + unsafe { + let ptr = av_color_transfer_name((*self).into()); + if ptr.is_null() { + None + } else { + Some(from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes())) + } + } + } +} + impl From for TransferCharacteristic { fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic { match value {