@@ -213,23 +213,7 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
213213 }
214214
215215 this . currentStream . Position += 4 ;
216- this . ReadScanlines (
217- chunk . Length - 4 ,
218- currentFrame ,
219- pngMetadata ,
220- ( ) =>
221- {
222- int length = this . ReadNextDataChunk ( ) ;
223- if ( this . ReadNextDataChunk ( ) is 0 )
224- {
225- return length ;
226- }
227-
228- this . currentStream . Position += 4 ; // Skip sequence number
229- return length - 4 ;
230- } ,
231- lastFrameControl . Value ,
232- cancellationToken ) ;
216+ this . ReadScanlines ( chunk . Length - 4 , currentFrame , pngMetadata , this . ReadNextDataChunkAndSkipSeq , lastFrameControl . Value , cancellationToken ) ;
233217 lastFrameControl = null ;
234218 break ;
235219 case PngChunkType . Data :
@@ -1576,7 +1560,7 @@ private int ReadNextDataChunk()
15761560
15771561 Span < byte > buffer = stackalloc byte [ 20 ] ;
15781562
1579- this . currentStream . Read ( buffer , 0 , 4 ) ;
1563+ _ = this . currentStream . Read ( buffer , 0 , 4 ) ;
15801564
15811565 if ( this . TryReadChunk ( buffer , out PngChunk chunk ) )
15821566 {
@@ -1592,6 +1576,22 @@ private int ReadNextDataChunk()
15921576 return 0 ;
15931577 }
15941578
1579+ /// <summary>
1580+ /// Reads the next data chunk and skip sequence number.
1581+ /// </summary>
1582+ /// <returns>Count of bytes in the next data chunk, or 0 if there are no more data chunks left.</returns>
1583+ private int ReadNextDataChunkAndSkipSeq ( )
1584+ {
1585+ int length = this . ReadNextDataChunk ( ) ;
1586+ if ( this . ReadNextDataChunk ( ) is 0 )
1587+ {
1588+ return length ;
1589+ }
1590+
1591+ this . currentStream . Position += 4 ; // Skip sequence number
1592+ return length - 4 ;
1593+ }
1594+
15951595 /// <summary>
15961596 /// Reads a chunk from the stream.
15971597 /// </summary>
0 commit comments