Commit 2cf30129 authored by Romain Vimont's avatar Romain Vimont Committed by Thomas Daede

Do not use PlaneMutSlice from Plane::pad()

We have access to the whole underlying buffer from there.

This avoids to call methods returning multirows mutable slices from the
PlaneMutslice, so we can then remove these methods.
parent 2c0e27f5
......@@ -115,11 +115,9 @@ impl<T: Pixel> Plane<T> {
if xorigin > 0 {
for y in 0..height {
let mut ps = self
.mut_slice(&PlaneOffset { x: -(xorigin as isize), y: y as isize });
let s = ps.as_mut_slice_w_width(xorigin + 1);
let fill_val = s[xorigin];
for val in s[..xorigin].iter_mut() {
let base = (yorigin + y) * stride;
let fill_val = self.data[base + xorigin];
for val in &mut self.data[base..base + xorigin] {
*val = fill_val;
}
}
......@@ -127,35 +125,29 @@ impl<T: Pixel> Plane<T> {
if xorigin + width < stride {
for y in 0..height {
let mut ps = self
.mut_slice(&PlaneOffset { x: width as isize - 1, y: y as isize });
let s = ps.as_mut_slice_w_width(stride - xorigin - width + 1);
let fill_val = s[0];
for val in s[1..].iter_mut() {
let base = (yorigin + y) * stride + xorigin + width;
let fill_val = self.data[base - 1];
for val in &mut self.data[base..base + stride - (xorigin + width)] {
*val = fill_val;
}
}
}
if yorigin > 0 {
let mut ps = self.mut_slice(&PlaneOffset {
x: -(xorigin as isize),
y: -(yorigin as isize)
});
let (s1, s2) = ps.as_mut_slice().split_at_mut(yorigin * stride);
let (top, bottom) = self.data.split_at_mut(yorigin * stride);
let src = &bottom[..stride];
for y in 0..yorigin {
s1[y * stride..y * stride + stride].copy_from_slice(&s2[..stride]);
let dst = &mut top[y * stride..(y + 1) * stride];
dst.copy_from_slice(src);
}
}
if yorigin + height < alloc_height {
let mut ps = self.mut_slice(&PlaneOffset {
x: -(xorigin as isize),
y: height as isize - 1
});
let (s2, s1) = ps.as_mut_slice().split_at_mut(stride);
if yorigin + height < self.cfg.alloc_height {
let (top, bottom) = self.data.split_at_mut((yorigin + height) * stride);
let src = &top[(yorigin + height - 1) * stride..];
for y in 0..alloc_height - (yorigin + height) {
s1[y * stride..y * stride + stride].copy_from_slice(&s2[..stride]);
let dst = &mut bottom[y * stride..(y + 1) * stride];
dst.copy_from_slice(src);
}
}
}
......@@ -238,13 +230,16 @@ impl<T: Pixel> Plane<T> {
pub fn downsample_from(&mut self, src: &Plane<T>) {
let width = self.cfg.width;
let height = self.cfg.height;
let xorigin = self.cfg.xorigin;
let yorigin = self.cfg.yorigin;
let stride = self.cfg.stride;
assert!(width * 2 == src.cfg.width);
assert!(height * 2 == src.cfg.height);
for row in 0..height {
let mut dst_slice = self.mut_slice(&PlaneOffset{ x: 0, y: row as isize });
let dst = dst_slice.as_mut_slice();
let base = (yorigin + row) * stride + xorigin;
let dst = &mut self.data[base..base + width];
for col in 0..width {
let mut sum = 0;
......
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