diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 128ae0854..d67beb036 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -373,11 +373,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp for (int x = 0; x < arrayWidth; x++) { int colOffset = x * ppb; - - for (int shift = 0; shift < ppb && (x + shift) < width; shift++) + for (int shift = 0, newX = colOffset; shift < ppb && newX < width; shift++, newX++) { int colorIndex = ((rowSpan[offset] >> (8 - bits - (shift * bits))) & mask) * 4; - int newX = colOffset + shift; // Stored in b-> g-> r order. rgba.Bgr = Unsafe.As(ref colors[colorIndex]); diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs index 09c3d1545..5f2de9f51 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs @@ -17,10 +17,7 @@ namespace SixLabors.ImageSharp.Tests { public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector; - public static readonly string[] AllBmpFiles = - { - Car, F, NegHeight, CoreHeader, V5Header, RLE, RLEInverted, Bit8, Bit8Inverted, Bit16, Bit16Inverted - }; + public static readonly string[] AllBmpFiles = All; public static readonly TheoryData RatioFiles = new TheoryData diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 142b923ed..5eb70117e 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -165,12 +165,30 @@ namespace SixLabors.ImageSharp.Tests public const string V5Header = "Bmp/BITMAPV5HEADER.bmp"; public const string RLE = "Bmp/RunLengthEncoded.bmp"; public const string RLEInverted = "Bmp/RunLengthEncoded-inverted.bmp"; + public const string Bit1 = "Bmp/pal1.bmp"; + public const string Bit1Pal1 = "Bmp/pal1p1.bmp"; + public const string Bit4 = "Bmp/pal4.bmp"; public const string Bit8 = "Bmp/test8.bmp"; public const string Bit8Inverted = "Bmp/test8-inverted.bmp"; public const string Bit16 = "Bmp/test16.bmp"; public const string Bit16Inverted = "Bmp/test16-inverted.bmp"; - public static readonly string[] All = { Car, F, NegHeight, CoreHeader, V5Header, RLE, RLEInverted, Bit8, Bit8Inverted, Bit16, Bit16Inverted }; + public static readonly string[] All + = { + Car, + F, + NegHeight, + CoreHeader, + V5Header, RLE, + RLEInverted, + Bit1, + Bit1Pal1, + Bit4, + Bit8, + Bit8Inverted, + Bit16, + Bit16Inverted + }; } public static class Gif diff --git a/tests/Images/Input/Bmp/pal1.bmp b/tests/Images/Input/Bmp/pal1.bmp new file mode 100644 index 000000000..4776f8277 Binary files /dev/null and b/tests/Images/Input/Bmp/pal1.bmp differ diff --git a/tests/Images/Input/Bmp/pal1p1.bmp b/tests/Images/Input/Bmp/pal1p1.bmp new file mode 100644 index 000000000..b68321c4c Binary files /dev/null and b/tests/Images/Input/Bmp/pal1p1.bmp differ diff --git a/tests/Images/Input/Bmp/pal4.bmp b/tests/Images/Input/Bmp/pal4.bmp new file mode 100644 index 000000000..7fd36303c Binary files /dev/null and b/tests/Images/Input/Bmp/pal4.bmp differ