Skip to content

Commit 13ff434

Browse files
brianpopowJimBobSquarePants
authored andcommitted
Fix Decoding interlaced grayscale (#831)
1 parent 637f767 commit 13ff434

6 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
145145
{
146146
byte scaledLuminanceTrans = (byte)(luminanceTrans.PackedValue * scaleFactor);
147147
Rgba32 rgba32 = default;
148-
for (int x = pixelOffset; x < header.Width; x += increment)
148+
for (int x = pixelOffset, o = 0; x < header.Width; x += increment, o++)
149149
{
150-
byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, x) * scaleFactor);
150+
byte luminance = (byte)(Unsafe.Add(ref scanlineSpanRef, o) * scaleFactor);
151151
rgba32.R = luminance;
152152
rgba32.G = luminance;
153153
rgba32.B = luminance;

tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ public partial class PngDecoderTests
6767
TestImages.Png.GrayTrns16BitInterlaced
6868
};
6969

70-
public static readonly string[] TestImagesGrayAlpha8Bit =
70+
public static readonly string[] TestImagesGray8BitInterlaced =
7171
{
72-
TestImages.Png.GrayAlpha8Bit,
73-
TestImages.Png.GrayAlpha8Bit2
72+
TestImages.Png.GrayAlpha1BitInterlaced,
73+
TestImages.Png.GrayAlpha2BitInterlaced,
74+
TestImages.Png.Gray4BitInterlaced,
75+
TestImages.Png.GrayAlpha8BitInterlaced
7476
};
7577

7678
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
@@ -130,8 +132,8 @@ public void Decode_64Bpp<TPixel>(TestImageProvider<TPixel> provider)
130132
}
131133

132134
[Theory]
133-
[WithFileCollection(nameof(TestImagesGrayAlpha8Bit), PixelTypes.Rgba32)]
134-
public void Decoder_Gray8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
135+
[WithFileCollection(nameof(TestImagesGray8BitInterlaced), PixelTypes.Rgba32)]
136+
public void Decoder_Gray8bitInterlaced<TPixel>(TestImageProvider<TPixel> provider)
135137
where TPixel : struct, IPixel<TPixel>
136138
{
137139
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
@@ -166,8 +168,8 @@ public void Decode_GrayAlpha16Bit<TPixel>(TestImageProvider<TPixel> provider)
166168
}
167169

168170
[Theory]
169-
[WithFile(TestImages.Png.Splash, PixelTypes)]
170-
public void Decoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
171+
[WithFile(TestImages.Png.GrayAlpha8BitInterlaced, PixelTypes)]
172+
public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
171173
where TPixel : struct, IPixel<TPixel>
172174
{
173175
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
@@ -178,8 +180,8 @@ public void Decoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel
178180
}
179181

180182
[Theory]
181-
[WithFile(TestImages.Png.GrayAlpha8Bit2, PixelTypes)]
182-
public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
183+
[WithFile(TestImages.Png.Splash, PixelTypes)]
184+
public void Decoder_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
183185
where TPixel : struct, IPixel<TPixel>
184186
{
185187
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public static class Png
2929
public const string Gray4Bpp = "Png/gray_4bpp.png";
3030
public const string Gray16Bit = "Png/gray-16.png";
3131
public const string GrayAlpha8Bit = "Png/gray-alpha-8.png";
32-
public const string GrayAlpha8Bit2 = "Png/rollsroyce.png";
32+
public const string GrayAlpha8BitInterlaced = "Png/rollsroyce.png";
33+
public const string GrayAlpha1BitInterlaced = "Png/iftbbn0g01.png";
34+
public const string GrayAlpha2BitInterlaced = "Png/iftbbn0g02.png";
35+
public const string Gray4BitInterlaced = "Png/iftbbn0g04.png";
3336
public const string GrayAlpha16Bit = "Png/gray-alpha-16.png";
3437
public const string GrayTrns16BitInterlaced = "Png/gray-16-tRNS-interlaced.png";
3538
public const string Rgb24BppTrans = "Png/rgb-8-tRNS.png";
214 Bytes
Loading
211 Bytes
Loading
489 Bytes
Loading

0 commit comments

Comments
 (0)