@@ -174,7 +174,7 @@ impl<LS: LuminanceSource> HybridBinarizer<LS> {
174174 sub_height : u32 ,
175175 width : u32 ,
176176 height : u32 ,
177- black_points : & [ Vec < u32 > ] ,
177+ black_points : & [ u32 ] ,
178178 matrix : & mut BitMatrix ,
179179 ) {
180180 let maxYOffset = height - BLOCK_SIZE as u32 ;
@@ -192,7 +192,7 @@ impl<LS: LuminanceSource> HybridBinarizer<LS> {
192192 let mut sum = 0 ;
193193 for z in -2 ..=2 {
194194 // for (int z = -2; z <= 2; z++) {
195- let blackRow = & black_points[ ( top as i32 + z) as usize ] ;
195+ let blackRow = & black_points[ ( ( top as i32 + z) as u32 * sub_width ) as usize .. ] ;
196196 sum += blackRow[ ( left - 2 ) as usize ]
197197 + blackRow[ ( left - 1 ) as usize ]
198198 + blackRow[ left as usize ]
@@ -241,10 +241,10 @@ impl<LS: LuminanceSource> HybridBinarizer<LS> {
241241 subHeight : u32 ,
242242 width : u32 ,
243243 height : u32 ,
244- ) -> Vec < Vec < u32 > > {
244+ ) -> Vec < u32 > {
245245 let maxYOffset = height as usize - BLOCK_SIZE ;
246246 let maxXOffset = width as usize - BLOCK_SIZE ;
247- let mut blackPoints = vec ! [ vec! [ 0 ; subWidth as usize ] ; subHeight as usize ] ;
247+ let mut blackPoints = vec ! [ 0 ; ( subHeight * subWidth ) as usize ] ;
248248 for y in 0 ..subHeight {
249249 // for (int y = 0; y < subHeight; y++) {
250250 let yoffset = u32:: min ( y << BLOCK_SIZE_POWER , maxYOffset as u32 ) ;
@@ -304,17 +304,17 @@ impl<LS: LuminanceSource> HybridBinarizer<LS> {
304304 // the boundaries is used for the interior.
305305
306306 // The (min < bp) is arbitrary but works better than other heuristics that were tried.
307- let average_neighbor_black_point: u32 = ( blackPoints[ y as usize - 1 ]
308- [ x as usize ]
309- + ( 2 * blackPoints[ y as usize ] [ x as usize - 1 ] )
310- + blackPoints[ y as usize - 1 ] [ x as usize - 1 ] )
307+ let average_neighbor_black_point: u32 = ( blackPoints
308+ [ ( y as usize - 1 ) * subWidth as usize + x as usize ]
309+ + ( 2 * blackPoints[ y as usize * subWidth as usize + x as usize - 1 ] )
310+ + blackPoints[ ( y as usize - 1 ) * subWidth as usize + x as usize - 1 ] )
311311 / 4 ;
312312 if ( min as u32 ) < average_neighbor_black_point {
313313 average = average_neighbor_black_point;
314314 }
315315 }
316316 }
317- blackPoints[ y as usize ] [ x as usize ] = average;
317+ blackPoints[ ( y * subWidth + x ) as usize ] = average;
318318 }
319319 }
320320 blackPoints
0 commit comments