Browse Source

Make sure bitmap encoder preserves 4 bits per pixel, when the input is 4 bit

pull/1622/head
Brian Popow 5 years ago
parent
commit
04e6b4135a
  1. 5
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

5
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -1304,8 +1304,9 @@ namespace SixLabors.ImageSharp.Formats.Bmp
this.bmpMetadata = this.metadata.GetBmpMetadata();
this.bmpMetadata.InfoHeaderType = infoHeaderType;
// We can only encode at these bit rates so far (1 bit and 4 bit are still missing).
if (bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel8)
// We can only encode at these bit rates so far (1 bit per pixel is still missing).
if (bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel4)
|| bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel8)
|| bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel16)
|| bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel24)
|| bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel32))

2
tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

@ -40,6 +40,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
public static readonly TheoryData<string, BmpBitsPerPixel> BmpBitsPerPixelFiles =
new TheoryData<string, BmpBitsPerPixel>
{
{ Bit4, BmpBitsPerPixel.Pixel4 },
{ Bit8, BmpBitsPerPixel.Pixel8 },
{ Rgb16, BmpBitsPerPixel.Pixel16 },
{ Car, BmpBitsPerPixel.Pixel24 },
{ Bit32Rgb, BmpBitsPerPixel.Pixel32 }

Loading…
Cancel
Save