@@ -180,6 +180,7 @@ void ReadImage(byte[] src, SimpleBitmap bmp) {
180180
181181 Pixel [ ] pal = localPal ?? globalPal ;
182182 int dst_index = 0 ;
183+ bool fastPath = imageX == 0 && imageY == 0 && imageW == bmp . Width && imageH == bmp . Height ;
183184
184185 // Read image data
185186 offset = AdvanceOffset ( 1 ) ;
@@ -277,18 +278,29 @@ void ReadImage(byte[] src, SimpleBitmap bmp) {
277278
278279 // "top" entry is actually last entry in chain
279280 int chain_len = dict [ code ] . len ;
280- for ( int i = chain_len - 1 ; i >= 0 ; i -- )
281- {
282- int index = dst_index + i ;
283- byte palIndex = dict [ code ] . value ;
284-
285- //int localX = index % imageW;
286- //int localY = index / imageW;
287- int globalX = imageX + ( index % imageW ) ;
288- int globalY = imageY + ( index / imageW ) ;
289- bmp . pixels [ globalY * bmp . Width + globalX ] = pal [ palIndex ] ;
290-
291- code = dict [ code ] . prev ;
281+ // If frame is same size as image, no need to convert coordinates
282+ if ( fastPath ) {
283+ for ( int i = chain_len - 1 ; i >= 0 ; i -- )
284+ {
285+ byte palIndex = dict [ code ] . value ;
286+ bmp . pixels [ dst_index + i ] = pal [ palIndex ] ;
287+
288+ code = dict [ code ] . prev ;
289+ }
290+ } else {
291+ for ( int i = chain_len - 1 ; i >= 0 ; i -- )
292+ {
293+ int index = dst_index + i ;
294+ byte palIndex = dict [ code ] . value ;
295+
296+ //int localX = index % imageW;
297+ //int localY = index / imageW;
298+ int globalX = imageX + ( index % imageW ) ;
299+ int globalY = imageY + ( index / imageW ) ;
300+ bmp . pixels [ globalY * bmp . Width + globalX ] = pal [ palIndex ] ;
301+
302+ code = dict [ code ] . prev ;
303+ }
292304 }
293305
294306 dst_index += chain_len ;
0 commit comments