Browse Source

Merge pull request #676 from SixLabors/js/defect-675

Fix 1 bit bmp decoding and add extra test images.
af/merge-core
James Jackson-South 8 years ago
committed by GitHub
parent
commit
76bf1035ad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  2. 5
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  3. 20
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Bmp/pal1.bmp
  5. 3
      tests/Images/Input/Bmp/pal1p1.bmp
  6. 3
      tests/Images/Input/Bmp/pal4.bmp

4
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<byte, Bgr24>(ref colors[colorIndex]);

5
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<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit>

20
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

3
tests/Images/Input/Bmp/pal1.bmp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c631861fa4c4e959d2abc6e0db0106253989b0101223cb08020e116e19c97f77
size 1086

3
tests/Images/Input/Bmp/pal1p1.bmp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:620eb83715dd99a640b6c61f5337c2f01fd19246d4759a2bc0480b8ee960bf63
size 1082

3
tests/Images/Input/Bmp/pal4.bmp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:01f7bfaaf5110a404fb68451a860970750c155e5c46e1721fa6b9c500be0ca2c
size 4198
Loading…
Cancel
Save