@@ -91,7 +91,13 @@ impl Render {
9191 let _out_h = self . out . height ( ) as usize ;
9292 let input_img = input. get ( ) ;
9393
94+ let light_raw = mapping. light . as_raw ( ) ;
95+ let dark_raw = mapping. dark . as_raw ( ) ;
96+ let map1_raw = mapping. map1 . as_raw ( ) ;
97+ let map2_raw = mapping. map2 . as_raw ( ) ;
98+
9499 let row_stride = out_w * 4 ;
100+ let map_stride = mapping. map1 . width ( ) as usize * 4 ;
95101 let out_raw = self . out . as_mut ( ) ;
96102
97103 #[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -106,14 +112,14 @@ impl Render {
106112 }
107113
108114 for x in 0 ..out_w {
109- let xu = x as u32 ;
110- let yu = y as u32 ;
111-
112- let light_pixel = mapping. light . get_pixel ( xu, yu) ;
113- let dark_pixel = mapping. dark . get_pixel ( xu, yu) ;
115+ let idx = x * 4 ;
116+ let light_idx = y * row_stride + idx;
117+ let map_idx = map_y_base as usize * map_stride + idx;
114118
115- let map_pixel = mapping. map1 . get_pixel ( xu, map_y_base) ;
116- let sel_pixel = mapping. map2 . get_pixel ( xu, map_y_base) ;
119+ let light_pixel = & light_raw[ light_idx..light_idx + 4 ] ;
120+ let dark_pixel = & dark_raw[ light_idx..light_idx + 4 ] ;
121+ let map_pixel = & map1_raw[ map_idx..map_idx + 4 ] ;
122+ let sel_pixel = & map2_raw[ map_idx..map_idx + 4 ] ;
117123
118124 if sel_pixel[ 0 ] != input. layer {
119125 continue ;
@@ -136,12 +142,14 @@ impl Render {
136142 let mut y13 = y1;
137143
138144 if ( x as i32 ) < w - 1 && ( y as i32 ) < h - 1 {
139- let mdx = mapping. map1 . get_pixel ( ( x + 1 ) as u32 , map_y_base) ;
140- let mdy = mapping. map1 . get_pixel ( xu, map_y_base + 1 ) ;
145+ let mdx_idx = map_idx + 4 ;
146+ let mdy_idx = map_idx + map_stride;
147+ let mdx = & map1_raw[ mdx_idx..mdx_idx + 4 ] ;
148+ let mdy = & map1_raw[ mdy_idx..mdy_idx + 4 ] ;
141149
142150 if mdx[ 3 ] > 127 && mdy[ 3 ] > 127 {
143- let idx2 = mapping . map2 . get_pixel ( ( x + 1 ) as u32 , map_y_base ) ;
144- let idx3 = mapping . map2 . get_pixel ( xu , map_y_base + 1 ) ;
151+ let idx2 = & map2_raw [ mdx_idx..mdx_idx + 4 ] ;
152+ let idx3 = & map2_raw [ mdy_idx..mdy_idx + 4 ] ;
145153
146154 if idx2[ 0 ] == input. layer && idx3[ 0 ] == input. layer {
147155 let mod2 = mdx[ 2 ] as i32 ;
0 commit comments