util::color: implement .name() for {Primaries, Range, TransferCharacteristic}

This commit is contained in:
Zhiming Wang
2021-03-13 06:56:48 +01:00
committed by meh
parent 3c6aca0b95
commit b75f433ae5
3 changed files with 36 additions and 0 deletions
+12
View File
@@ -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<AVColorPrimaries> for Primaries {
fn from(value: AVColorPrimaries) -> Primaries {
match value {
+12
View File
@@ -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<AVColorRange> for Range {
fn from(value: AVColorRange) -> Self {
match value {
+12
View File
@@ -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<AVColorTransferCharacteristic> for TransferCharacteristic {
fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic {
match value {