@@ -31,23 +31,23 @@ impl Reducer {
31
31
} ;
32
32
33
33
for x in lxmin. floor ( ) as u32 ..=( lxmax. ceil ( ) as u32 ) . min ( image. width ( ) - 1 ) {
34
- if let Some ( rgb ) = image . color_at ( x , y ) {
35
- let x_area = if ( x as f32 ) < lxmin {
36
- ( 255. * ( 1. - lxmin. fract ( ) ) ) as u64
37
- } else if ( x + 1 ) as f32 > lxmax {
38
- ( 255. * lxmax. fract ( ) ) as u64
39
- } else {
40
- 255
41
- } ;
42
-
43
- let area = x_area * y_area / 255 ;
44
-
45
- let ( r , g , b ) = rgb . into_components ( ) ;
46
- r_acc += ( r as u64 * 255 ) * area ;
47
- g_acc += ( g as u64 * 255 ) * area;
48
- b_acc += ( b as u64 * 255 ) * area;
49
- cnt += area;
50
- }
34
+ // Safety: x (resp. y) are necessarily in 0..width (resp. 0..height)
35
+ let rgb = unsafe { image . color_at_unchecked ( x , y ) } ;
36
+ let x_area = if ( x as f32 ) < lxmin {
37
+ ( 255. * ( 1. - lxmin . fract ( ) ) ) as u64
38
+ } else if ( x + 1 ) as f32 > lxmax {
39
+ ( 255. * lxmax . fract ( ) ) as u64
40
+ } else {
41
+ 255
42
+ } ;
43
+
44
+ let area = x_area * y_area / 255 ;
45
+
46
+ let ( r , g , b ) = rgb . into_components ( ) ;
47
+ r_acc += ( r as u64 * 255 ) * area;
48
+ g_acc += ( g as u64 * 255 ) * area;
49
+ b_acc += ( b as u64 * 255 ) * area;
50
+ cnt += area ;
51
51
}
52
52
}
53
53
0 commit comments