Skip to content

Commit

Permalink
Do not expose multirows slices in PlaneMutSlice
Browse files Browse the repository at this point in the history
Remove as_mut_slice() and similar methods from PlaneMutSlice which
expose slices spanning multiple rows.
  • Loading branch information
rom1v authored and tdaede committed Feb 28, 2019
1 parent 2cf3012 commit 7ccee27
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions src/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,41 +533,6 @@ impl<'a, T: Pixel> PlaneMutSlice<'a, T> {
}
}

pub fn as_mut_slice(&mut self) -> &mut [T] {
let stride = self.plane.cfg.stride;
let base = (self.y + self.plane.cfg.yorigin as isize) as usize * stride
+ (self.x + self.plane.cfg.xorigin as isize) as usize;
&mut self.plane.data[base..]
}

pub fn as_mut_slice_w_width(&mut self, width: usize) -> &mut [T] {
let stride = self.plane.cfg.stride;
let y = self.y + self.plane.cfg.yorigin as isize;
let x = self.x + self.plane.cfg.xorigin as isize;
assert!(y >= 0);
assert!(x >= 0);
let base = y as usize * stride + x as usize;
&mut self.plane.data[base..base + width]
}

pub fn offset(&self, add_x: usize, add_y: usize) -> &[T] {
let new_y =
(self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
let new_x =
(self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
&self.plane.data[new_y * self.plane.cfg.stride + new_x..]
}

pub fn offset_as_mutable(
&mut self, add_x: usize, add_y: usize
) -> &mut [T] {
let new_y =
(self.y + add_y as isize + self.plane.cfg.yorigin as isize) as usize;
let new_x =
(self.x + add_x as isize + self.plane.cfg.xorigin as isize) as usize;
&mut self.plane.data[new_y * self.plane.cfg.stride + new_x..]
}

// FIXME: code duplication with PlaneSlice

/// A slice starting i pixels above the current one.
Expand Down

0 comments on commit 7ccee27

Please sign in to comment.