Skip to content

Commit 45e901d

Browse files
committed
h263/gather: Pass in frame (array) height to sampler function
This also doesn't change within a block, so there is no need to compute it again for every pixel - up to four times even.
1 parent 583a580 commit 45e901d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

codecs/h263/src/decoder/cpu/gather.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ use crate::types::{MacroblockType, MotionVector};
1313
/// equivalent to, say OpenGL `GL_CLAMP_TO_EDGE` behavior.)
1414
///
1515
/// Pixel array data is read as a row-major (x + y*width) array.
16-
fn read_sample(pixel_array: &[u8], samples_per_row: usize, pos: (isize, isize)) -> u8 {
16+
fn read_sample(
17+
pixel_array: &[u8],
18+
samples_per_row: usize,
19+
num_rows: usize,
20+
pos: (isize, isize),
21+
) -> u8 {
1722
let (x, y) = pos;
1823

1924
let x = x.clamp(0, samples_per_row.saturating_sub(1) as isize) as usize;
20-
21-
let height = pixel_array.len() / samples_per_row;
22-
23-
let y = y.clamp(0, height.saturating_sub(1) as isize) as usize;
25+
let y = y.clamp(0, num_rows.saturating_sub(1) as isize) as usize;
2426

2527
pixel_array
2628
.get(x + (y * samples_per_row))
@@ -62,16 +64,19 @@ fn gather_block(
6264
for (j, v) in (y..y + block_rows).enumerate() {
6365
for (i, u) in (x..x + block_cols).enumerate() {
6466
target[pos.0 + i + ((pos.1 + j) * samples_per_row)] =
65-
read_sample(pixel_array, samples_per_row, (u, v));
67+
read_sample(pixel_array, samples_per_row, array_height, (u, v));
6668
}
6769
}
6870
} else {
6971
for (j, v) in (y..y + block_rows).enumerate() {
7072
for (i, u) in (x..x + block_cols).enumerate() {
71-
let sample_0_0 = read_sample(pixel_array, samples_per_row, (u, v));
72-
let sample_1_0 = read_sample(pixel_array, samples_per_row, (u + 1, v));
73-
let sample_0_1 = read_sample(pixel_array, samples_per_row, (u, v + 1));
74-
let sample_1_1 = read_sample(pixel_array, samples_per_row, (u + 1, v + 1));
73+
let sample_0_0 = read_sample(pixel_array, samples_per_row, array_height, (u, v));
74+
let sample_1_0 =
75+
read_sample(pixel_array, samples_per_row, array_height, (u + 1, v));
76+
let sample_0_1 =
77+
read_sample(pixel_array, samples_per_row, array_height, (u, v + 1));
78+
let sample_1_1 =
79+
read_sample(pixel_array, samples_per_row, array_height, (u + 1, v + 1));
7580

7681
if x_interp && y_interp {
7782
// special case to only round once

0 commit comments

Comments
 (0)