Skip to content

Commit

Permalink
Make convert_slice_2d() use raw pointers
Browse files Browse the repository at this point in the history
The util function convert_slice_2d() operates on a slice with stride
information. It will become incompatible with PlaneSlice which will not
expose a multi-rows slice anymore (see
<xiph#631 (comment)>).

To keep it generic enough, we don't want to use a PlaneSlice wrapper for
every call, so make the function use raw pointers (and unsafe).

Note: this commit changes indentation for unsafe blocks, so the diff is
more understable with "git show -b".
  • Loading branch information
rom1v authored and lu-zero committed Feb 27, 2019
1 parent d137353 commit d8298fd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,19 @@ pub fn round_shift(value: i32, bit: usize) -> i32 {
(value + (1 << bit >> 1)) >> bit
}

pub fn convert_slice_2d<NEW, OLD>(
dst: &mut [NEW], dst_stride: usize, src: &[OLD], src_stride: usize,
pub unsafe fn convert_slice_2d<NEW, OLD>(
dst: *mut NEW, dst_stride: usize, src: *const OLD, src_stride: usize,
width: usize, height: usize
)
where
NEW: CastFromPrimitive<OLD> + Copy + 'static,
OLD: Copy + 'static,
{
for r in 0..height {
for (a, b) in dst[r * dst_stride..r * dst_stride + width]
.iter_mut()
.zip(src[r * src_stride..r * src_stride + width].iter())
{
*a = NEW::cast_from(*b);
for y in 0..height {
for x in 0..width {
let p_dst = dst.add(y * dst_stride + x);
let p_src = src.add(y * src_stride + x);
*p_dst = NEW::cast_from(*p_src);
}
}
}

0 comments on commit d8298fd

Please sign in to comment.