diff --git a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs index de494d42d0..d5f8107082 100644 --- a/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/AverageFilter.cs @@ -5,8 +5,6 @@ namespace ImageSharp.Formats { - using System; - /// /// The Average filter uses the average of the two neighboring pixels (left and above) to predict /// the value of a pixel. diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index dc76c27b82..587f29a6d8 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -440,28 +440,28 @@ namespace ImageSharp.Formats where TColor : struct, IPackedPixel where TPacked : struct { - for (int pass = 0; pass < 7; pass++) - { - int y = Adam7FirstRow[pass]; - int numColumns = this.ComputeColumnsAdam7(pass); - - if (numColumns == 0) - { - // This pass contains no data; skip to next pass - continue; - } + byte[] previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); + byte[] scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); - int bytesPerInterlaceScanline = this.CalculateScanlineLength(numColumns) + 1; + // Zero out the previousScanline, because the bytes that are rented from the arraypool may not be zero. + Array.Clear(previousScanline, 0, this.bytesPerScanline); - while (y < this.header.Height) + try + { + for (int pass = 0; pass < 7; pass++) { - byte[] previousScanline = ArrayPool.Shared.Rent(this.bytesPerScanline); - byte[] scanline = ArrayPool.Shared.Rent(this.bytesPerScanline); + int y = Adam7FirstRow[pass]; + int numColumns = this.ComputeColumnsAdam7(pass); - // Zero out the previousScanline, because the bytes that are rented from the arraypool may not be zero. - Array.Clear(previousScanline, 0, this.bytesPerScanline); + if (numColumns == 0) + { + // This pass contains no data; skip to next pass + continue; + } - try + int bytesPerInterlaceScanline = this.CalculateScanlineLength(numColumns) + 1; + + while (y < this.header.Height) { compressedStream.Read(scanline, 0, bytesPerInterlaceScanline); @@ -506,16 +506,17 @@ namespace ImageSharp.Formats this.ProcessInterlacedDefilteredScanline(scanline, y, pixels, Adam7FirstColumn[pass], Adam7ColumnIncrement[pass]); Swap(ref scanline, ref previousScanline); - } - finally - { - ArrayPool.Shared.Return(previousScanline); - ArrayPool.Shared.Return(scanline); - } - y += Adam7RowIncrement[pass]; + + y += Adam7RowIncrement[pass]; + } } } + finally + { + ArrayPool.Shared.Return(previousScanline); + ArrayPool.Shared.Return(scanline); + } } /// @@ -765,7 +766,6 @@ namespace ImageSharp.Formats } } - /// /// Reads a text chunk containing image properties from the data. /// diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs index e8034ebfd1..33f6307792 100644 --- a/tests/ImageSharp.Tests/FileTestBase.cs +++ b/tests/ImageSharp.Tests/FileTestBase.cs @@ -31,8 +31,9 @@ namespace ImageSharp.Tests // new TestFile(TestImages.Bmp.Neg_height), // Perf: Enable for local testing only // new TestFile(TestImages.Png.Blur), // Perf: Enable for local testing only // new TestFile(TestImages.Png.Indexed), // Perf: Enable for local testing only - //new TestFile(TestImages.Png.Splash), - new TestFile(TestImages.Png.SplashInterlace), + new TestFile(TestImages.Png.Splash), + //new TestFile(TestImages.Png.SplashInterlaced), + new TestFile(TestImages.Png.Interlaced), // new TestFile(TestImages.Png.Filter0), // Perf: Enable for local testing only // new TestFile(TestImages.Png.Filter1), // Perf: Enable for local testing only // new TestFile(TestImages.Png.Filter2), // Perf: Enable for local testing only diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index a8117df685..fcd8d27cd8 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -20,7 +20,10 @@ namespace ImageSharp.Tests public static string Indexed => folder + "indexed.png"; public static string Splash => folder + "splash.png"; - public static string SplashInterlace => folder + "splash-interlaced.png"; + public static string SplashInterlaced => folder + "splash-interlaced.png"; + + public static string Interlaced => folder + "interlaced.png"; + // filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public static string Filter0 => folder + "filter0.png"; public static string Filter1 => folder + "filter1.png"; diff --git a/tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png b/tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png index d4b75523dd..c9d76336cc 100644 --- a/tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png +++ b/tests/ImageSharp.Tests/TestImages/Formats/Png/interlaced.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7e1c92b1a57b762f736e14d480eb016b551ce0dc67aa588b246d838d00c0fc3f -size 17372 +oid sha256:21d34b50acf6bf71c68673585a298b8ddce3a908a46c38a6be9530487ebab8dc +size 17949