From f0b11a960ac7a14448e6ba85c28081ee99871439 Mon Sep 17 00:00:00 2001 From: meh Date: Mon, 18 May 2015 23:32:11 +0200 Subject: [PATCH] codec/picture: change width and height to u32 --- src/codec/picture.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/codec/picture.rs b/src/codec/picture.rs index 7e5b232..1a77c17 100644 --- a/src/codec/picture.rs +++ b/src/codec/picture.rs @@ -10,16 +10,16 @@ use ::Error; pub struct Picture<'a> { pub ptr: *mut AVPicture, - pub format: format::Pixel, - pub width: usize, - pub height: usize, + format: format::Pixel, + width: u32, + height: u32, _own: bool, _marker: PhantomData<&'a ()>, } impl<'a> Picture<'a> { - pub fn size(format: format::Pixel, width: usize, height: usize) -> Result { + pub fn size(format: format::Pixel, width: u32, height: u32) -> Result { unsafe { match avpicture_get_size(format.into(), width as c_int, height as c_int) { v if v >= 0 => Ok(v as usize), @@ -28,7 +28,7 @@ impl<'a> Picture<'a> { } } - pub fn new(format: format::Pixel, width: usize, height: usize) -> Result { + pub fn new(format: format::Pixel, width: u32, height: u32) -> Result { unsafe { let ptr = av_malloc(mem::size_of::() as size_t) as *mut AVPicture; @@ -39,7 +39,7 @@ impl<'a> Picture<'a> { format: format, width: width, height: height, - + _own: true, _marker: PhantomData }), @@ -49,19 +49,31 @@ impl<'a> Picture<'a> { } } - pub fn wrap(ptr: *mut AVPicture, format: format::Pixel, width: usize, height: usize) -> Self { + pub fn wrap(ptr: *mut AVPicture, format: format::Pixel, width: u32, height: u32) -> Self { Picture { ptr: ptr, format: format, width: width, height: height, - + _own: false, _marker: PhantomData } } + pub fn format(&self) -> format::Pixel { + self.format + } + + pub fn width(&self) -> u32 { + self.width + } + + pub fn height(&self) -> u32 { + self.height + } + pub fn layout(&self, out: &mut [u8]) -> Result { unsafe { match avpicture_layout(self.ptr, self.format.into(), self.width as c_int, self.height as c_int, out.as_mut_ptr(), out.len() as c_int) { @@ -71,7 +83,7 @@ impl<'a> Picture<'a> { } } - pub fn layout_as(&self, format: format::Pixel, width: usize, height: usize, out: &mut [u8]) -> Result { + pub fn layout_as(&self, format: format::Pixel, width: u32, height: u32, out: &mut [u8]) -> Result { unsafe { match avpicture_layout(self.ptr, format.into(), width as c_int, height as c_int, out.as_mut_ptr(), out.len() as c_int) { s if s >= 0 => Ok(s as usize), @@ -80,7 +92,7 @@ impl<'a> Picture<'a> { } } - pub fn crop(&mut self, source: &Picture, top: usize, left: usize) -> Result<(), Error> { + pub fn crop(&mut self, source: &Picture, top: u32, left: u32) -> Result<(), Error> { if self.format != source.format { return Err(Error::new(AVERROR_BUG)); }