Skip to content

Commit 583a580

Browse files
committed
h263/gather: Use built-in clamp() instead of explicit conditionals
There might be intrinsics for this on some target architectures, is also shorter, and it is supposed to give the same result.
1 parent 63b6765 commit 583a580

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,11 @@ use crate::types::{MacroblockType, MotionVector};
1616
fn read_sample(pixel_array: &[u8], samples_per_row: usize, pos: (isize, isize)) -> u8 {
1717
let (x, y) = pos;
1818

19-
let x = if x < 0 {
20-
0
21-
} else if x >= samples_per_row as isize {
22-
samples_per_row.saturating_sub(1)
23-
} else {
24-
x as usize
25-
};
19+
let x = x.clamp(0, samples_per_row.saturating_sub(1) as isize) as usize;
2620

2721
let height = pixel_array.len() / samples_per_row;
2822

29-
let y = if y < 0 {
30-
0
31-
} else if y >= height as isize {
32-
height.saturating_sub(1)
33-
} else {
34-
y as usize
35-
};
23+
let y = y.clamp(0, height.saturating_sub(1) as isize) as usize;
3624

3725
pixel_array
3826
.get(x + (y * samples_per_row))

0 commit comments

Comments
 (0)