From e73c520f2ebc5602bfcd540e0f7dad3fd14a027f Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 2 Dec 2016 15:24:53 +1100 Subject: [PATCH] Fix decoding of 4bit indexed pngs. --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 97bf00522..38042426c 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -193,8 +193,7 @@ namespace ImageSharp.Formats } /// - /// Converts a byte array to a new array where each value in the original array is represented - /// by a the specified number of bits. + /// Converts a byte array to a new array where each value in the original array is represented by the specified number of bits. /// /// The bytes to convert from. Cannot be null. /// The number of bytes per scanline @@ -216,7 +215,8 @@ namespace ImageSharp.Formats int resultOffset = 0; // ReSharper disable once ForCanBeConvertedToForeach - for (int i = 0; i < bytesPerScanline; i++) + // First byte is the marker so skip. + for (int i = 1; i < bytesPerScanline; i++) { byte b = source[i]; for (int shift = 0; shift < 8; shift += bits) @@ -418,8 +418,7 @@ namespace ImageSharp.Formats byte[] newScanline1 = ToArrayByBitsLength(defilteredScanline, this.bytesPerScanline, this.header.BitDepth); for (int x = 0; x < this.header.Width; x++) { - int offset = 1 + ((x + 1) * this.bytesPerPixel); - byte intensity = (byte)(newScanline1[offset] * factor); + byte intensity = (byte)(newScanline1[x] * factor); color.PackFromBytes(intensity, intensity, intensity, 255); pixels[x, row] = color; }