Commit a5e6ca99 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato

Use a Box<[T]> as storage for Plane

parent 6a266ee8
......@@ -2138,7 +2138,7 @@ pub fn encode_frame<T: Pixel>(fi: &mut FrameInvariants<T>, fs: &mut FrameState<T
write_obus(&mut packet, fi, fs).unwrap();
if let Some(ref rec) = fi.rec_buffer.frames[fi.frame_to_show_map_idx as usize] {
for p in 0..3 {
fs.rec.planes[p].data.copy_from_slice(rec.frame.planes[p].data.as_slice());
fs.rec.planes[p].data.copy_from_slice(&rec.frame.planes[p].data);
}
}
} else {
......
......@@ -40,7 +40,7 @@ pub struct PlaneOffset {
#[derive(Clone, PartialEq, Eq)]
pub struct Plane<T: Pixel> {
pub data: Vec<T>,
pub data: Box<[T]>,
pub cfg: PlaneConfig
}
......@@ -90,7 +90,7 @@ impl<T: Pixel> Plane<T> {
}
assert!(is_aligned(data.as_ptr(), Self::DATA_ALIGNMENT_LOG2));
Plane {
data,
data: data.into_boxed_slice(),
cfg: PlaneConfig {
stride,
alloc_height,
......@@ -108,9 +108,10 @@ impl<T: Pixel> Plane<T> {
pub fn wrap(data: Vec<T>, stride: usize) -> Self {
let len = data.len();
assert!(len % stride == 0);
Self {
data,
data: data.into_boxed_slice(),
cfg: PlaneConfig {
stride,
alloc_height: len / stride,
......@@ -607,7 +608,7 @@ pub mod test {
0, 0, 2, 3, 4, 5, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
],
].into_boxed_slice(),
cfg: PlaneConfig {
stride: 8,
alloc_height: 9,
......@@ -623,8 +624,8 @@ pub mod test {
};
plane.pad(4, 4);
assert_eq!(
vec![
1, 1, 1, 2, 3, 4, 4, 4,
&[
1u8, 1, 1, 2, 3, 4, 4, 4,
1, 1, 1, 2, 3, 4, 4, 4,
1, 1, 1, 2, 3, 4, 4, 4,
1, 1, 1, 2, 3, 4, 4, 4,
......@@ -633,8 +634,8 @@ pub mod test {
2, 2, 2, 3, 4, 5, 5, 5,
2, 2, 2, 3, 4, 5, 5, 5,
2, 2, 2, 3, 4, 5, 5, 5,
],
plane.data
][..],
&plane.data[..]
);
}
}
......@@ -907,50 +907,50 @@ mod test {
let mut output = Plane::wrap(vec![0u8; 4 * 4], 4);
Block4x4::pred_dc(&mut output.as_mut_slice(), above, left);
assert_eq!(output.data, [32u8; 16]);
assert_eq!(&output.data[..], [32u8; 16]);
Block4x4::pred_dc_top(&mut output.as_mut_slice(), above, left);
assert_eq!(output.data, [35u8; 16]);
assert_eq!(&output.data[..], [35u8; 16]);
Block4x4::pred_dc_left(&mut output.as_mut_slice(), above, left);
assert_eq!(output.data, [30u8; 16]);
assert_eq!(&output.data[..], [30u8; 16]);
Block4x4::pred_dc_128(&mut output.as_mut_slice(), 8);
assert_eq!(output.data, [128u8; 16]);
assert_eq!(&output.data[..], [128u8; 16]);
Block4x4::pred_v(&mut output.as_mut_slice(), above);
assert_eq!(
output.data,
&output.data[..],
[33, 34, 35, 36, 33, 34, 35, 36, 33, 34, 35, 36, 33, 34, 35, 36]
);
Block4x4::pred_h(&mut output.as_mut_slice(), left);
assert_eq!(
output.data,
&output.data[..],
[31, 31, 31, 31, 30, 30, 30, 30, 29, 29, 29, 29, 28, 28, 28, 28]
);
Block4x4::pred_paeth(&mut output.as_mut_slice(), above, left, top_left);
assert_eq!(
output.data,
&output.data[..],
[32, 34, 35, 36, 30, 32, 32, 36, 29, 32, 32, 32, 28, 28, 32, 32]
);
Block4x4::pred_smooth(&mut output.as_mut_slice(), above, left);
assert_eq!(
output.data,
&output.data[..],
[32, 34, 35, 35, 30, 32, 33, 34, 29, 31, 32, 32, 29, 30, 32, 32]
);
Block4x4::pred_smooth_h(&mut output.as_mut_slice(), above, left);
assert_eq!(
output.data,
&output.data[..],
[31, 33, 34, 35, 30, 33, 34, 35, 29, 32, 34, 34, 28, 31, 33, 34]
);
Block4x4::pred_smooth_v(&mut output.as_mut_slice(), above, left);
assert_eq!(
output.data,
&output.data[..],
[33, 34, 35, 36, 31, 31, 32, 33, 30, 30, 30, 31, 29, 30, 30, 30]
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment