1use std::ffi::CStr;
2use std::str::from_utf8_unchecked;
3
4use ffi::AVColorRange::*;
5use ffi::*;
6
7#[derive(Eq, PartialEq, Clone, Copy, Debug)]
8pub enum Range {
9 Unspecified,
10 MPEG,
11 JPEG,
12}
13
14impl Range {
15 pub fn name(&self) -> Option<&'static str> {
16 if *self == Range::Unspecified {
17 return None;
18 }
19 unsafe {
20 let ptr = av_color_range_name((*self).into());
21 ptr.as_ref()
22 .map(|ptr: *const i8| from_utf8_unchecked(CStr::from_ptr(ptr).to_bytes()))
23 }
24 }
25}
26
27impl From<AVColorRange> for Range {
28 fn from(value: AVColorRange) -> Self {
29 match value {
30 AVCOL_RANGE_UNSPECIFIED => Range::Unspecified,
31 AVCOL_RANGE_MPEG => Range::MPEG,
32 AVCOL_RANGE_JPEG => Range::JPEG,
33 AVCOL_RANGE_NB => Range::Unspecified,
34 }
35 }
36}
37
38impl From<Range> for AVColorRange {
39 fn from(value: Range) -> AVColorRange {
40 match value {
41 Range::Unspecified => AVCOL_RANGE_UNSPECIFIED,
42 Range::MPEG => AVCOL_RANGE_MPEG,
43 Range::JPEG => AVCOL_RANGE_JPEG,
44 }
45 }
46}
47