diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index a53844b4a7..a426208944 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -213,23 +213,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals } this.currentStream.Position += 4; - this.ReadScanlines( - chunk.Length - 4, - currentFrame, - pngMetadata, - () => - { - int length = this.ReadNextDataChunk(); - if (this.ReadNextDataChunk() is 0) - { - return length; - } - - this.currentStream.Position += 4; // Skip sequence number - return length - 4; - }, - lastFrameControl.Value, - cancellationToken); + this.ReadScanlines(chunk.Length - 4, currentFrame, pngMetadata, this.ReadNextDataChunkAndSkipSeq, lastFrameControl.Value, cancellationToken); lastFrameControl = null; break; case PngChunkType.Data: @@ -1576,7 +1560,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals Span buffer = stackalloc byte[20]; - this.currentStream.Read(buffer, 0, 4); + _ = this.currentStream.Read(buffer, 0, 4); if (this.TryReadChunk(buffer, out PngChunk chunk)) { @@ -1592,6 +1576,22 @@ internal sealed class PngDecoderCore : IImageDecoderInternals return 0; } + /// + /// Reads the next data chunk and skip sequence number. + /// + /// Count of bytes in the next data chunk, or 0 if there are no more data chunks left. + private int ReadNextDataChunkAndSkipSeq() + { + int length = this.ReadNextDataChunk(); + if (this.ReadNextDataChunk() is 0) + { + return length; + } + + this.currentStream.Position += 4; // Skip sequence number + return length - 4; + } + /// /// Reads a chunk from the stream. /// diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 1e7426226a..17fb40446d 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -240,7 +240,6 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable } }); } - } ///