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

This commit is contained in:
Zhiming Wang 2018-09-14 21:06:56 -04:00
parent b387e1de48
commit bd35f013f8
No known key found for this signature in database
GPG Key ID: 5B58F95EC95965D8
3 changed files with 48 additions and 0 deletions

View File

@ -1,3 +1,6 @@
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use ffi::AVColorPrimaries::*; use ffi::AVColorPrimaries::*;
use ffi::*; use ffi::*;
@ -21,6 +24,19 @@ pub enum Primaries {
JEDEC_P22, 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<AVColorPrimaries> for Primaries { impl From<AVColorPrimaries> for Primaries {
fn from(value: AVColorPrimaries) -> Primaries { fn from(value: AVColorPrimaries) -> Primaries {
match value { match value {

View File

@ -1,3 +1,6 @@
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use ffi::AVColorRange::*; use ffi::AVColorRange::*;
use ffi::*; use ffi::*;
@ -8,6 +11,19 @@ pub enum Range {
JPEG, 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<AVColorRange> for Range { impl From<AVColorRange> for Range {
fn from(value: AVColorRange) -> Self { fn from(value: AVColorRange) -> Self {
match value { match value {

View File

@ -1,3 +1,6 @@
use std::ffi::CStr;
use std::str::from_utf8_unchecked;
use ffi::AVColorTransferCharacteristic::*; use ffi::AVColorTransferCharacteristic::*;
use ffi::*; use ffi::*;
@ -24,6 +27,19 @@ pub enum TransferCharacteristic {
ARIB_STD_B67, 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<AVColorTransferCharacteristic> for TransferCharacteristic { impl From<AVColorTransferCharacteristic> for TransferCharacteristic {
fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic { fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic {
match value { match value {