@@ -13,14 +13,16 @@ use crate::types::{MacroblockType, MotionVector};
13
13
/// equivalent to, say OpenGL `GL_CLAMP_TO_EDGE` behavior.)
14
14
///
15
15
/// 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 {
17
22
let ( x, y) = pos;
18
23
19
24
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 ;
24
26
25
27
pixel_array
26
28
. get ( x + ( y * samples_per_row) )
@@ -62,16 +64,19 @@ fn gather_block(
62
64
for ( j, v) in ( y..y + block_rows) . enumerate ( ) {
63
65
for ( i, u) in ( x..x + block_cols) . enumerate ( ) {
64
66
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) ) ;
66
68
}
67
69
}
68
70
} else {
69
71
for ( j, v) in ( y..y + block_rows) . enumerate ( ) {
70
72
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 ) ) ;
75
80
76
81
if x_interp && y_interp {
77
82
// special case to only round once
0 commit comments