util/frame: add some more accessors

This commit is contained in:
meh 2015-05-15 21:52:15 +02:00
parent 930af9d581
commit 2dd658f337
4 changed files with 73 additions and 1 deletions

View File

@ -0,0 +1,41 @@
use ffi::*;
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum Location {
Unspecified,
Left,
Center,
TopLeft,
Top,
BottomLeft,
Bottom,
}
impl From<AVChromaLocation> 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<AVChromaLocation> 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
}
}
}

2
src/util/chroma/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod location;
pub use self::location::Location;

View File

@ -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 {

View File

@ -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;