Skip to content

Commit b75f433

Browse files
zmwangxmeh
authored andcommitted
util::color: implement .name() for {Primaries, Range, TransferCharacteristic}
1 parent 3c6aca0 commit b75f433

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/util/color/primaries.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ pub enum Primaries {
2323
EBU3213,
2424
}
2525

26+
impl Primaries {
27+
pub fn name(&self) -> Option<&'static str> {
28+
if *self == Primaries::Unspecified {
29+
return None;
30+
}
31+
unsafe {
32+
let ptr = av_color_primaries_name((*self).into());
33+
ptr.as_ref().map(|ptr| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
34+
}
35+
}
36+
}
37+
2638
impl From<AVColorPrimaries> for Primaries {
2739
fn from(value: AVColorPrimaries) -> Primaries {
2840
match value {

src/util/color/range.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ pub enum Range {
99
JPEG,
1010
}
1111

12+
impl Range {
13+
pub fn name(&self) -> Option<&'static str> {
14+
if *self == Range::Unspecified {
15+
return None;
16+
}
17+
unsafe {
18+
let ptr = av_color_range_name((*self).into());
19+
ptr.as_ref().map(|ptr| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
20+
}
21+
}
22+
}
23+
1224
impl From<AVColorRange> for Range {
1325
fn from(value: AVColorRange) -> Self {
1426
match value {

src/util/color/transfer_characteristic.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ pub enum TransferCharacteristic {
2525
ARIB_STD_B67,
2626
}
2727

28+
impl TransferCharacteristic {
29+
pub fn name(&self) -> Option<&'static str> {
30+
if *self == TransferCharacteristic::Unspecified {
31+
return None;
32+
}
33+
unsafe {
34+
let ptr = av_color_transfer_name((*self).into());
35+
ptr.as_ref().map(|ptr| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
36+
}
37+
}
38+
}
39+
2840
impl From<AVColorTransferCharacteristic> for TransferCharacteristic {
2941
fn from(value: AVColorTransferCharacteristic) -> TransferCharacteristic {
3042
match value {

0 commit comments

Comments
 (0)