Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ public static void ProcessInterlacedGrayscaleWithAlphaScanline<TPixel>(
else
{
Rgba32 rgba32 = default;
int offset = 0;
for (int x = pixelOffset; x < header.Width; x += increment)
{
int offset = x * bytesPerPixel;
byte luminance = Unsafe.Add(ref scanlineSpanRef, offset);
byte alpha = Unsafe.Add(ref scanlineSpanRef, offset + bytesPerSample);
rgba32.R = luminance;
Expand All @@ -252,6 +252,7 @@ public static void ProcessInterlacedGrayscaleWithAlphaScanline<TPixel>(

pixel.FromRgba32(rgba32);
Unsafe.Add(ref rowSpanRef, x) = pixel;
offset += bytesPerPixel;
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public partial class PngDecoderTests
TestImages.Png.GrayTrns16BitInterlaced
};

public static readonly string[] TestImagesGrayAlpha8Bit =
{
TestImages.Png.GrayAlpha8Bit,
TestImages.Png.GrayAlpha8Bit2
};

public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit>
{
Expand Down Expand Up @@ -123,6 +129,18 @@ public void Decode_64Bpp<TPixel>(TestImageProvider<TPixel> provider)
}
}

[Theory]
[WithFileCollection(nameof(TestImagesGrayAlpha8Bit), PixelTypes.Rgba32)]
public void Decoder_Gray8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
}

[Theory]
[WithFileCollection(nameof(TestImagesGray16Bit), PixelTypes.Rgb48)]
public void Decode_Gray16Bit<TPixel>(TestImageProvider<TPixel> provider)
Expand Down Expand Up @@ -159,6 +177,18 @@ public void Decoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel
}
}

[Theory]
[WithFile(TestImages.Png.GrayAlpha8Bit2, PixelTypes)]
public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
}

[Fact]
public void Decode_IgnoreMetadataIsFalse_TextChunckIsRead()
{
Expand Down
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static class Png
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 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";
Expand Down
Binary file added tests/Images/Input/Png/rollsroyce.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.