From 128c0b86989e5053aed3a671d12a373d1b0e3b9d Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 5 Jun 2020 17:16:48 +0100 Subject: [PATCH 1/2] Swap buffers. Fix #1211 --- src/ImageSharp/Formats/Png/PngEncoderCore.cs | 4 ++ .../Formats/Png/PngEncoderTests.cs | 47 +++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index a25f51fe1..5f7dd212f 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -1081,6 +1081,10 @@ namespace SixLabors.ImageSharp.Formats.Png // encode data IManagedByteBuffer r = this.EncodeAdam7IndexedPixelRow(destSpan); deflateStream.Write(r.Array, 0, resultLength); + + IManagedByteBuffer temp = this.currentScanline; + this.currentScanline = this.previousScanline; + this.previousScanline = temp; } } } diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 4f2490f9a..04f2ba7e0 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -199,17 +199,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png return; } - foreach (PngInterlaceMode interlaceMode in InterlaceMode) + foreach (var filterMethod in PngFilterMethods) { - TestPngEncoderCore( - provider, - pngColorType, - PngFilterMethod.Adaptive, - pngBitDepth, - interlaceMode, - appendPngColorType: true, - appendPixelType: true, - appendPngBitDepth: true); + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( + provider, + pngColorType, + (PngFilterMethod)filterMethod[0], + pngBitDepth, + interlaceMode, + appendPngColorType: true, + appendPixelType: true, + appendPngBitDepth: true); + } } } @@ -232,18 +235,22 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png public void WorksWithAllBitDepthsAndExcludeAllFilter(TestImageProvider provider, PngColorType pngColorType, PngBitDepth pngBitDepth) where TPixel : unmanaged, IPixel { - foreach (PngInterlaceMode interlaceMode in InterlaceMode) + foreach (var filterMethod in PngFilterMethods) { - TestPngEncoderCore( - provider, pngColorType, - PngFilterMethod.Adaptive, - pngBitDepth, - interlaceMode, - appendPngColorType: true, - appendPixelType: true, - appendPngBitDepth: true, - optimizeMethod: PngChunkFilter.ExcludeAll); + foreach (PngInterlaceMode interlaceMode in InterlaceMode) + { + TestPngEncoderCore( + provider, + pngColorType, + (PngFilterMethod)filterMethod[0], + pngBitDepth, + interlaceMode, + appendPngColorType: true, + appendPixelType: true, + appendPngBitDepth: true, + optimizeMethod: PngChunkFilter.ExcludeAll); + } } } From 75be04657a71b26a2f4ea2471bcc1687d7451776 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 5 Jun 2020 17:17:29 +0100 Subject: [PATCH 2/2] Update PngEncoderTests.cs --- tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs index 04f2ba7e0..93ea73eb4 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs @@ -237,7 +237,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png { foreach (var filterMethod in PngFilterMethods) { - pngColorType, foreach (PngInterlaceMode interlaceMode in InterlaceMode) { TestPngEncoderCore(