Skip to content

Commit

Permalink
Fix 1 bit bmp decoding and add extra test images.
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Aug 14, 2018
1 parent dcdb9db commit 18c4a7f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
Expand Up @@ -373,11 +373,9 @@ private void ReadRgbPalette<TPixel>(Buffer2D<TPixel> pixels, byte[] colors, int
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<byte, Bgr24>(ref colors[colorIndex]);
Expand Down
5 changes: 1 addition & 4 deletions tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
Expand Up @@ -17,10 +17,7 @@ public class BmpDecoderTests
{
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<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit>
Expand Down
20 changes: 19 additions & 1 deletion tests/ImageSharp.Tests/TestImages.cs
Expand Up @@ -165,12 +165,30 @@ public static class Bmp
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
Expand Down
Binary file added tests/Images/Input/Bmp/pal1.bmp
Binary file not shown.
Binary file added tests/Images/Input/Bmp/pal1p1.bmp
Binary file not shown.
Binary file added tests/Images/Input/Bmp/pal4.bmp
Binary file not shown.

0 comments on commit 18c4a7f

Please sign in to comment.