Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use chunks_exact_mut in iwht4x4, vpred, hpred, bdcpred #16

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ pub(crate) fn iwht4x4(block: &mut [i32]) {
block[12 + i] = d1 - c1;
}

for i in 0usize..4 {
let a1 = block[4 * i] + block[4 * i + 3];
let b1 = block[4 * i + 1] + block[4 * i + 2];
let c1 = block[4 * i + 1] - block[4 * i + 2];
let d1 = block[4 * i] - block[4 * i + 3];
for block in block.chunks_exact_mut(4) {
let a1 = block[0] + block[3];
let b1 = block[1] + block[2];
let c1 = block[1] - block[2];
let d1 = block[0] - block[3];

let a2 = a1 + b1;
let b2 = c1 + d1;
let c2 = a1 - b1;
let d2 = d1 - c1;

block[4 * i] = (a2 + 3) >> 3;
block[4 * i + 1] = (b2 + 3) >> 3;
block[4 * i + 2] = (c2 + 3) >> 3;
block[4 * i + 3] = (d2 + 3) >> 3;
block[0] = (a2 + 3) >> 3;
block[1] = (b2 + 3) >> 3;
block[2] = (c2 + 3) >> 3;
block[3] = (d2 + 3) >> 3;
}
}
31 changes: 20 additions & 11 deletions src/vp8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2306,18 +2306,22 @@ fn predict_4x4(ws: &mut [u8], stride: usize, modes: &[IntraMode], resdata: &[i32
}

fn predict_vpred(a: &mut [u8], size: usize, x0: usize, y0: usize, stride: usize) {
for y in 0usize..size {
for x in 0usize..size {
a[(x + x0) + stride * (y + y0)] = a[(x + x0) + stride * (y0 + y - 1)];
// This pass copies the top row to the rows below it.
let (above, curr) = a.split_at_mut(stride * y0);
let above_slice = &above[x0..];

for curr_chunk in curr.chunks_exact_mut(stride).take(size) {
for (curr, &above) in curr_chunk[1..].iter_mut().zip(above_slice) {
*curr = above;
}
}
}

fn predict_hpred(a: &mut [u8], size: usize, x0: usize, y0: usize, stride: usize) {
for y in 0usize..size {
for x in 0usize..size {
a[(x + x0) + stride * (y + y0)] = a[(x + x0 - 1) + stride * (y0 + y)];
}
// This pass copies the first value of a row to the values right of it.
for chunk in a.chunks_exact_mut(stride).skip(y0).take(size) {
let left = chunk[x0 - 1];
chunk[x0..].iter_mut().for_each(|a| *a = left);
}
}

Expand Down Expand Up @@ -2368,14 +2372,19 @@ fn predict_tmpred(a: &mut [u8], size: usize, x0: usize, y0: usize, stride: usize

fn predict_bdcpred(a: &mut [u8], x0: usize, y0: usize, stride: usize) {
let mut v = 4;

a[(y0 - 1) * stride + x0..][..4]
.iter()
.for_each(|&a| v += u32::from(a));

for i in 0usize..4 {
v += u32::from(a[(y0 + i) * stride + x0 - 1]) + u32::from(a[(y0 - 1) * stride + x0 + i]);
v += u32::from(a[(y0 + i) * stride + x0 - 1]);
}

v >>= 3;
for y in 0usize..4 {
for x in 0usize..4 {
a[x + x0 + stride * (y + y0)] = v as u8;
for chunk in a.chunks_exact_mut(stride).skip(y0).take(4) {
for ch in chunk[x0..][..4].iter_mut() {
*ch = v as u8;
}
}
}
Expand Down
Loading