From 2dd658f3377bf6522106b74aeff9c540b721f0aa Mon Sep 17 00:00:00 2001 From: meh Date: Fri, 15 May 2015 21:52:15 +0200 Subject: [PATCH] util/frame: add some more accessors --- src/util/chroma/location.rs | 41 +++++++++++++++++++++++++++++++++++++ src/util/chroma/mod.rs | 2 ++ src/util/frame/mod.rs | 30 ++++++++++++++++++++++++++- src/util/mod.rs | 1 + 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/util/chroma/location.rs create mode 100644 src/util/chroma/mod.rs diff --git a/src/util/chroma/location.rs b/src/util/chroma/location.rs new file mode 100644 index 0000000..d8d900d --- /dev/null +++ b/src/util/chroma/location.rs @@ -0,0 +1,41 @@ +use ffi::*; + +#[derive(Eq, PartialEq, Clone, Copy, Debug)] +pub enum Location { + Unspecified, + Left, + Center, + TopLeft, + Top, + BottomLeft, + Bottom, +} + +impl From for Location { + fn from(value: AVChromaLocation) -> Self { + match value { + AVCHROMA_LOC_UNSPECIFIED => Location::Unspecified, + AVCHROMA_LOC_LEFT => Location::Left, + AVCHROMA_LOC_CENTER => Location::Center, + AVCHROMA_LOC_TOPLEFT => Location::TopLeft, + AVCHROMA_LOC_TOP => Location::Top, + AVCHROMA_LOC_BOTTOMLEFT => Location::BottomLeft, + AVCHROMA_LOC_BOTTOM => Location::Bottom, + AVCHROMA_LOC_NB => Location::Unspecified + } + } +} + +impl Into for Location { + fn into(self) -> AVChromaLocation { + match self { + Location::Unspecified => AVCHROMA_LOC_UNSPECIFIED, + Location::Left => AVCHROMA_LOC_LEFT, + Location::Center => AVCHROMA_LOC_CENTER, + Location::TopLeft => AVCHROMA_LOC_TOPLEFT, + Location::Top => AVCHROMA_LOC_TOP, + Location::BottomLeft => AVCHROMA_LOC_BOTTOMLEFT, + Location::Bottom => AVCHROMA_LOC_BOTTOM + } + } +} diff --git a/src/util/chroma/mod.rs b/src/util/chroma/mod.rs new file mode 100644 index 0000000..8623568 --- /dev/null +++ b/src/util/chroma/mod.rs @@ -0,0 +1,2 @@ +pub mod location; +pub use self::location::Location; diff --git a/src/util/frame/mod.rs b/src/util/frame/mod.rs index b31b0a1..81feb8d 100644 --- a/src/util/frame/mod.rs +++ b/src/util/frame/mod.rs @@ -7,8 +7,9 @@ use std::mem; use std::ops::Deref; use ffi::*; -use ::{Dictionary, Rational}; +use ::{Dictionary, Rational, Picture}; use ::util::format; +use ::util::chroma; use ::picture; use ::color; @@ -257,6 +258,10 @@ impl Video { Video(Frame::new()) } + pub fn picture(&self) -> Picture { + Picture::wrap(self.ptr as *mut AVPicture, self.format(), self.width(), self.height()) + } + pub fn format(&self) -> format::Pixel { unsafe { if (*self.ptr).format == -1 { @@ -274,6 +279,24 @@ impl Video { } } + pub fn is_interlaced(&self) -> bool { + unsafe { + (*self.ptr).interlaced_frame != 0 + } + } + + pub fn is_top_first(&self) -> bool { + unsafe { + (*self.ptr).top_field_first != 0 + } + } + + pub fn has_palette_changed(&self) -> bool { + unsafe { + (*self.ptr).palette_has_changed != 0 + } + } + pub fn width(&self) -> usize { unsafe { (*self.ptr).width as usize @@ -346,6 +369,11 @@ impl Video { } } + pub fn chroma_location(&self) -> chroma::Location { + unsafe { + chroma::Location::from((*self.ptr).chroma_location) + } + } pub fn aspect_ratio(&self) -> Rational { unsafe { diff --git a/src/util/mod.rs b/src/util/mod.rs index 3a9a29b..eaddfd9 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -6,6 +6,7 @@ pub mod picture; pub mod color; pub mod format; pub mod frame; +pub mod chroma; use std::ffi::CStr; use std::str::from_utf8_unchecked;