Skip to content

Commit

Permalink
fn invert: constify (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen authored Sep 19, 2023
2 parents 59dc7e4 + 6d5d46a commit 9be35a3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/wedge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,18 @@ const fn hflip(src: &[u8; 64 * 64]) -> [u8; 64 * 64] {
dst
}

fn invert(dst: &mut [u8], src: &[u8], w: usize, h: usize) {
for y in 0..h {
const fn invert<const N: usize>(src: &[u8; N], w: usize, h: usize) -> [u8; N] {
assert!(w * h == N);
let mut dst = [0; N];

const_for!(y in 0..h => {
let y_off = y * w;
for x in 0..w {
const_for!(x in 0..w => {
dst[y_off + x] = 64 - src[y_off + x];
}
}
});
});

dst
}

unsafe fn copy2d(
Expand Down Expand Up @@ -282,8 +287,7 @@ unsafe fn fill2d_16x2<const LEN_444: usize, const LEN_422: usize, const LEN_420:
);
}
for n in 0..16 {
let [dst_0, dst_1] = dst;
invert(&mut dst_1[n], &dst_0[n], w, h);
dst[1][n] = invert(&dst[0][n], w, h);
}

for n in 0..16 {
Expand Down

0 comments on commit 9be35a3

Please sign in to comment.