Browse Source

Fix Decoding interlaced grayscale (#831)

pull/833/head
Brian Popow 7 years ago
committed by James Jackson-South
parent
commit
13ff434b9e
  1. 4
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  2. 20
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  3. 5
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Png/iftbbn0g01.png
  5. BIN
      tests/Images/Input/Png/iftbbn0g02.png
  6. BIN
      tests/Images/Input/Png/iftbbn0g04.png

4
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;

20
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<string, int, int, PixelResolutionUnit> RatioFiles =
@ -130,8 +132,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
}
[Theory]
[WithFileCollection(nameof(TestImagesGrayAlpha8Bit), PixelTypes.Rgba32)]
public void Decoder_Gray8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(TestImagesGray8BitInterlaced), PixelTypes.Rgba32)]
public void Decoder_Gray8bitInterlaced<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider)
[WithFile(TestImages.Png.GrayAlpha8BitInterlaced, PixelTypes)]
public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider)
[WithFile(TestImages.Png.Splash, PixelTypes)]
public void Decoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))

5
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";

BIN
tests/Images/Input/Png/iftbbn0g01.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

BIN
tests/Images/Input/Png/iftbbn0g02.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

BIN
tests/Images/Input/Png/iftbbn0g04.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 B

Loading…
Cancel
Save