util/frame/video: refactor data() and data_mut()
This commit is contained in:
parent
e9a9ad5720
commit
8298586d9f
@ -267,33 +267,27 @@ impl Video {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data(&self) -> Vec<&[u8]> {
|
||||
let mut result = Vec::new();
|
||||
pub fn data(&self, index: usize) -> &[u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
unsafe {
|
||||
for (i, length) in (*self.as_ptr()).linesize.iter().take_while(|l| **l > 0).enumerate() {
|
||||
result.push(slice::from_raw_parts(
|
||||
(*self.as_ptr()).data[i],
|
||||
*length as usize * self.height() as usize));
|
||||
slice::from_raw_parts((*self.as_ptr()).data[index],
|
||||
(*self.as_ptr()).linesize[index] as usize * self.height() as usize)
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
pub fn data_mut(&mut self, index: usize) -> &mut [u8] {
|
||||
if index >= self.planes() {
|
||||
panic!("out of bounds");
|
||||
}
|
||||
|
||||
pub fn data_mut(&mut self) -> Vec<&mut [u8]> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
unsafe {
|
||||
for (i, length) in (*self.as_ptr()).linesize.iter().take_while(|l| **l > 0).enumerate() {
|
||||
result.push(slice::from_raw_parts_mut(
|
||||
(*self.as_mut_ptr()).data[i],
|
||||
*length as usize * self.height() as usize));
|
||||
slice::from_raw_parts_mut((*self.as_mut_ptr()).data[index],
|
||||
(*self.as_ptr()).linesize[index] as usize * self.height() as usize)
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Video {
|
||||
|
Loading…
x
Reference in New Issue
Block a user