From e6af16b0815cd2098bab21f5902da8d7043324c2 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 4 Dec 2016 14:19:10 +1100 Subject: [PATCH] Much better output. Nearly there. Touch #9 Image in issue works perfectly as does rgba test image. rgb 8x8 test image shows 2 pixel error though and I don't know why. --- .../Formats/Png/Filters/AverageFilter.cs | 2 - src/ImageSharp/Formats/Png/PngDecoderCore.cs | 50 +++++++++--------- tests/ImageSharp.Tests/FileTestBase.cs | 5 +- tests/ImageSharp.Tests/TestImages.cs | 5 +- .../TestImages/Formats/Png/interlaced.png | Bin 17372 -> 17949 bytes 5 files changed, 32 insertions(+), 30 deletions(-) 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 ca39e19d8ff6765a11a9bfd1ca11b7b1b5d52d57..1bd38e06e5204748f856266758a4f194ce447a1a 100644 GIT binary patch delta 506 zcmcc9&N#P+al>RTCM&hgQ@I+MIZZ+gjjfClyZT$smjXD#FcSNMV=_F}({&2?6y3?f3>{{{N3|2;5ER i2BJ&oAq&9SjG!=hct_#8p3Ax{kf^7tpUXO@geCwT2!J;L delta 229 zcmbQ+!+58ial>RTCX1}iQ@I+MC%+aDnykTR0;co$Vkh?qs7+qa&$jtH-wdYB-ohn@ zEUff6-g siq_rN_-Fj*|9|;d`@FYDJRpjg86MtI_}*4g#SG$my85}Sb4q9e08Mdb-v9sr