From c3cee74c02d1d5b579fd705452ef42e19c52a18d Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 28 Aug 2017 23:11:24 +0200 Subject: [PATCH 1/4] Minor optimization for the PaethFilter decoder. --- .../Formats/Png/Filters/PaethFilter.cs | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index ec12eca058..f0f5ae0995 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -31,22 +31,21 @@ namespace ImageSharp.Formats ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); // Paeth(x) + PaethPredictor(Raw(x-bpp), Prior(x), Prior(x-bpp)) - for (int x = 1; x < scanline.Length; x++) + int offset = bytesPerPixel + 1; + for (int x = 1; x < offset; x++) { - if (x - bytesPerPixel < 1) - { - ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); - byte above = Unsafe.Add(ref prevBaseRef, x); - scan = (byte)((scan + PaethPredicator(0, above, 0)) % 256); - } - else - { - ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); - byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); - byte above = Unsafe.Add(ref prevBaseRef, x); - byte upperLeft = Unsafe.Add(ref prevBaseRef, x - bytesPerPixel); - scan = (byte)((scan + PaethPredicator(left, above, upperLeft)) % 256); - } + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte above = Unsafe.Add(ref prevBaseRef, x); + scan = (byte)(scan + above); + } + + for (int x = offset; x < scanline.Length; x++) + { + ref byte scan = ref Unsafe.Add(ref scanBaseRef, x); + byte left = Unsafe.Add(ref scanBaseRef, x - bytesPerPixel); + byte above = Unsafe.Add(ref prevBaseRef, x); + byte upperLeft = Unsafe.Add(ref prevBaseRef, x - bytesPerPixel); + scan = (byte)(scan + PaethPredicator(left, above, upperLeft)); } } From e6239727a0f41ac988e5ada1ca3a88f33f21791e Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 28 Aug 2017 23:13:41 +0200 Subject: [PATCH 2/4] Added missing clear for the previousScanline when going to the next pass --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 633d151b6a..f58322ee5d 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -515,7 +515,7 @@ namespace ImageSharp.Formats this.currentRowBytesRead = 0; Span scanSpan = this.scanline.Slice(0, bytesPerInterlaceScanline); - Span prevSpan = this.previousScanline.Span.Slice(0, bytesPerInterlaceScanline); + Span prevSpan = this.previousScanline.Slice(0, bytesPerInterlaceScanline); var filterType = (FilterType)scanSpan[0]; switch (filterType) @@ -556,6 +556,8 @@ namespace ImageSharp.Formats } this.pass++; + this.previousScanline.Clear(); + if (this.pass < 7) { this.currentRow = Adam7FirstRow[this.pass]; From a5e525119a8ada5ff06998922a49ea0ee7c8653f Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 28 Aug 2017 23:22:07 +0200 Subject: [PATCH 3/4] Added missing reset to zero for the Adam7 pass. --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index f58322ee5d..6429b68fa3 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -564,6 +564,7 @@ namespace ImageSharp.Formats } else { + this.pass = 0; break; } } From fbc7be5e43e45acdc7f2196cdf38643d050a8d62 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Mon, 28 Aug 2017 23:38:20 +0200 Subject: [PATCH 4/4] Fiked typo --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4f87647ffc..11444a3b23 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -2,7 +2,7 @@ - [ ] I have written a descriptive pull-request title - [ ] I have verified that there are no overlapping [pull-requests](https://github.com/JimBobSquarePants/ImageSharp/pulls) open -- [ ] I have verified that I am following matches the existing coding patterns and practise as demonstrated in the repository. These follow strict Stylecop rules :cop:. +- [ ] I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:. - [ ] I have provided test coverage for my change (where applicable) ### Description