From 13ff434b9e1114a956d9b7807c2a771df653f0da Mon Sep 17 00:00:00 2001 From: Brian Popow <38701097+brianpopow@users.noreply.github.com> Date: Thu, 7 Feb 2019 00:57:43 +0100 Subject: [PATCH] Fix Decoding interlaced grayscale (#831) --- .../Formats/Png/PngScanlineProcessor.cs | 4 ++-- .../Formats/Png/PngDecoderTests.cs | 20 ++++++++++-------- tests/ImageSharp.Tests/TestImages.cs | 5 ++++- tests/Images/Input/Png/iftbbn0g01.png | Bin 0 -> 214 bytes tests/Images/Input/Png/iftbbn0g02.png | Bin 0 -> 211 bytes tests/Images/Input/Png/iftbbn0g04.png | Bin 0 -> 489 bytes 6 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 tests/Images/Input/Png/iftbbn0g01.png create mode 100644 tests/Images/Input/Png/iftbbn0g02.png create mode 100644 tests/Images/Input/Png/iftbbn0g04.png diff --git a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs index 40c2841176..c23694951d 100644 --- a/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs +++ b/src/ImageSharp/Formats/Png/PngScanlineProcessor.cs @@ -145,9 +145,9 @@ namespace SixLabors.ImageSharp.Formats.Png { byte scaledLuminanceTrans = (byte)(luminanceTrans.PackedValue * scaleFactor); Rgba32 rgba32 = default; - for (int x = pixelOffset; x < header.Width; x += increment) + for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++) { - byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, x) * scaleFactor); + byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, o) * scaleFactor); rgba32.R = luminance; rgba32.G = luminance; rgba32.B = luminance; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 1452f233b6..eca7a2543a 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -67,10 +67,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png TestImages.Png.GrayTrns16BitInterlaced }; - public static readonly string[] TestImagesGrayAlpha8Bit = + public static readonly string[] TestImagesGray8BitInterlaced = { - TestImages.Png.GrayAlpha8Bit, - TestImages.Png.GrayAlpha8Bit2 + TestImages.Png.GrayAlpha1BitInterlaced, + TestImages.Png.GrayAlpha2BitInterlaced, + TestImages.Png.Gray4BitInterlaced, + TestImages.Png.GrayAlpha8BitInterlaced }; public static readonly TheoryData RatioFiles = @@ -130,8 +132,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png } [Theory] - [WithFileCollection(nameof(TestImagesGrayAlpha8Bit), PixelTypes.Rgba32)] - public void Decoder_Gray8bitWithAlpha(TestImageProvider provider) + [WithFileCollection(nameof(TestImagesGray8BitInterlaced), PixelTypes.Rgba32)] + public void Decoder_Gray8bitInterlaced(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage(new PngDecoder())) @@ -166,8 +168,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png } [Theory] - [WithFile(TestImages.Png.Splash, PixelTypes)] - public void Decoder_IsNotBoundToSinglePixelType(TestImageProvider provider) + [WithFile(TestImages.Png.GrayAlpha8BitInterlaced, PixelTypes)] + public void Decoder_CanDecodeGrey8bitWithAlpha(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage(new PngDecoder())) @@ -178,8 +180,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png } [Theory] - [WithFile(TestImages.Png.GrayAlpha8Bit2, PixelTypes)] - public void Decoder_CanDecodeGrey8bitWithAlpha(TestImageProvider provider) + [WithFile(TestImages.Png.Splash, PixelTypes)] + public void Decoder_IsNotBoundToSinglePixelType(TestImageProvider provider) where TPixel : struct, IPixel { using (Image image = provider.GetImage(new PngDecoder())) diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index b4b75bfd8a..51e2d084c6 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -29,7 +29,10 @@ namespace SixLabors.ImageSharp.Tests public const string Gray4Bpp = "Png/gray_4bpp.png"; public const string Gray16Bit = "Png/gray-16.png"; public const string GrayAlpha8Bit = "Png/gray-alpha-8.png"; - public const string GrayAlpha8Bit2 = "Png/rollsroyce.png"; + public const string GrayAlpha8BitInterlaced = "Png/rollsroyce.png"; + public const string GrayAlpha1BitInterlaced = "Png/iftbbn0g01.png"; + public const string GrayAlpha2BitInterlaced = "Png/iftbbn0g02.png"; + public const string Gray4BitInterlaced = "Png/iftbbn0g04.png"; public const string GrayAlpha16Bit = "Png/gray-alpha-16.png"; public const string GrayTrns16BitInterlaced = "Png/gray-16-tRNS-interlaced.png"; public const string Rgb24BppTrans = "Png/rgb-8-tRNS.png"; diff --git a/tests/Images/Input/Png/iftbbn0g01.png b/tests/Images/Input/Png/iftbbn0g01.png new file mode 100644 index 0000000000000000000000000000000000000000..6eb27d10e8d587875d1abf309b32591d573b7ea0 GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0vp^3Lwk~Bp7wr%FhF7rjj7PUvHOsv8mycFdT%?VwTS?8OI)lN`3ceUp%TVw%dl6lUjrI}dZ;WI290Fis=;*St8< zcEdA2&o2}xQqNf*wpHxg%7n}A0<)ygNO@lVqqDNOhvVa?ztx`@lQdM8DRV!O1Uiku M)78&qol`;+0Qf*sZU6uP literal 0 HcmV?d00001 diff --git a/tests/Images/Input/Png/iftbbn0g02.png b/tests/Images/Input/Png/iftbbn0g02.png new file mode 100644 index 0000000000000000000000000000000000000000..46ba4977792db7242ca14bd6b484424bd133284e GIT binary patch literal 211 zcmeAS@N?(olHy`uVBq!ia0vp^3Lwk`Bp9=o@yY{frjj7PU0gxFlL!dbcw$T{zIjBs)WP z{>HX0@k_>q?fVNd4~VM8l(NdkN663XEIFvVY7gtm6|BD9hhnzgmdK II;Vst00?1CAOHXW literal 0 HcmV?d00001 diff --git a/tests/Images/Input/Png/iftbbn0g04.png b/tests/Images/Input/Png/iftbbn0g04.png new file mode 100644 index 0000000000000000000000000000000000000000..e9db0ad50d0b43fece4191d0cee877d179727461 GIT binary patch literal 489 zcmVD%0+%?m8{ukIf_cfIf76xL6xMlh8HQXmr+U zgHu`IDZOwFPOi$inM8OmiUyAd5k7MDe1U}Iu)(d(&>%vO8rB9Gb=|oYUkFP$XI4Do zX6~_Ke8jVOD<*u?tE>+_?9bDmOZF~l?DS9Q-I+;sMk8Z$C!TQ23#yh*E-ghTInPVs z*|xdA%+#v;V}>n6)vXhXb|8g!X74vFQKbno5O|crC(GG9EgGq@;NrY{=@*NYxi0E! zB%%y^wk*YUUDRfRM9F$Wg&JvHlu0O}w0@G_FsAR9i4ti2M*m>CU04jY``*&DX{P^i fh!0!%U-(c literal 0 HcmV?d00001