Browse Source

Add decoder tests for 2 bit bitmap's

pull/2220/head
Brian Popow 3 years ago
parent
commit
26700fe6b0
  1. 15
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  2. 10
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
  3. 3
      tests/Images/External/ReferenceOutput/BmpDecoderTests/BmpDecoder_CanDecode_2Bit_Rgba32_pal2.png
  4. 3
      tests/Images/External/ReferenceOutput/BmpDecoderTests/BmpDecoder_CanDecode_2Bit_Rgba32_pal2Color.png

15
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -131,6 +131,21 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
}
}
[Theory]
[WithFile(Bit2, PixelTypes.Rgba32)]
[WithFile(Bit2Color, PixelTypes.Rgba32)]
public void BmpDecoder_CanDecode_2Bit<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(BmpDecoder))
{
image.DebugSave(provider);
// Reference decoder cant decode 2-bit, compare to reference output instead.
image.CompareToReferenceOutput(provider, extension: "png");
}
}
[Theory]
[WithFile(Bit4, PixelTypes.Rgba32)]
public void BmpDecoder_CanDecode_4Bit<TPixel>(TestImageProvider<TPixel> provider)

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

@ -22,6 +22,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
private static BmpDecoder BmpDecoder => new();
private static BmpEncoder BmpEncoder => new();
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
new()
{
@ -53,14 +55,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
[MemberData(nameof(RatioFiles))]
public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit)
{
var options = new BmpEncoder();
var testFile = TestFile.Create(imagePath);
using (Image<Rgba32> input = testFile.CreateRgba32Image())
{
using (var memStream = new MemoryStream())
{
input.Save(memStream, options);
input.Save(memStream, BmpEncoder);
memStream.Position = 0;
using (var output = Image.Load<Rgba32>(memStream))
@ -78,14 +78,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
[MemberData(nameof(BmpBitsPerPixelFiles))]
public void Encode_PreserveBitsPerPixel(string imagePath, BmpBitsPerPixel bmpBitsPerPixel)
{
var options = new BmpEncoder();
var testFile = TestFile.Create(imagePath);
using (Image<Rgba32> input = testFile.CreateRgba32Image())
{
using (var memStream = new MemoryStream())
{
input.Save(memStream, options);
input.Save(memStream, BmpEncoder);
memStream.Position = 0;
using (var output = Image.Load<Rgba32>(memStream))

3
tests/Images/External/ReferenceOutput/BmpDecoderTests/BmpDecoder_CanDecode_2Bit_Rgba32_pal2.png

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

3
tests/Images/External/ReferenceOutput/BmpDecoderTests/BmpDecoder_CanDecode_2Bit_Rgba32_pal2Color.png

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