|
|
|
@ -3,12 +3,11 @@ |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using SixLabors.ImageSharp.Formats; |
|
|
|
using SixLabors.ImageSharp.Formats.Bmp; |
|
|
|
using SixLabors.ImageSharp.Metadata; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Processing; |
|
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs; |
|
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
|
|
|
|
|
using Xunit; |
|
|
|
using Xunit.Abstractions; |
|
|
|
@ -128,11 +127,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp |
|
|
|
[Theory] |
|
|
|
// WinBmpv3 is a 24 bits per pixel image
|
|
|
|
[WithFile(WinBmpv3, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)] |
|
|
|
[WithFile(F, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)] |
|
|
|
public void Encode_24Bit_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(WinBmpv3, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)] |
|
|
|
[WithFile(F, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)] |
|
|
|
public void Encode_24Bit_WithV4Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true); |
|
|
|
|
|
|
|
@ -150,24 +151,48 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(WinBmpv5, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel8)] |
|
|
|
[WithFile(Bit8Palette4, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel8)] |
|
|
|
[WithFile(Bit8Gs, PixelTypes.Gray8, BmpBitsPerPixel.Pixel8)] |
|
|
|
public void Encode_8Bit_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(WinBmpv5, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel8)] |
|
|
|
[WithFile(Bit8Palette4, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel8)] |
|
|
|
[WithFile(Bit8Gs, PixelTypes.Gray8, BmpBitsPerPixel.Pixel8)] |
|
|
|
public void Encode_8Bit_WithV4Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(Bit8Gs, PixelTypes.Gray8, BmpBitsPerPixel.Pixel8)] |
|
|
|
public void Encode_8BitGray_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => |
|
|
|
TestBmpEncoderCore( |
|
|
|
provider, |
|
|
|
bitsPerPixel, |
|
|
|
supportTransparency: false, |
|
|
|
ImageComparer.TolerantPercentage(0.01f)); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(Bit8Gs, PixelTypes.Gray8, BmpBitsPerPixel.Pixel8)] |
|
|
|
public void Encode_8BitGray_WithV4Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => |
|
|
|
TestBmpEncoderCore( |
|
|
|
provider, |
|
|
|
bitsPerPixel, |
|
|
|
supportTransparency: true, |
|
|
|
ImageComparer.TolerantPercentage(0.01f)); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(TestImages.Png.GrayAlpha2BitInterlaced, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)] |
|
|
|
[WithFile(Bit32Rgba, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel32)] |
|
|
|
public void Encode_PreservesAlpha<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true); |
|
|
|
|
|
|
|
private static void TestBmpEncoderCore<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel, bool supportTransparency = true) |
|
|
|
private static void TestBmpEncoderCore<TPixel>( |
|
|
|
TestImageProvider<TPixel> provider, |
|
|
|
BmpBitsPerPixel bitsPerPixel, |
|
|
|
bool supportTransparency = true, |
|
|
|
ImageComparer customComparer = null) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
using (Image<TPixel> image = provider.GetImage()) |
|
|
|
@ -181,7 +206,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp |
|
|
|
var encoder = new BmpEncoder { BitsPerPixel = bitsPerPixel, SupportTransparency = supportTransparency }; |
|
|
|
|
|
|
|
// Does DebugSave & load reference CompareToReferenceInput():
|
|
|
|
image.VerifyEncoder(provider, "bmp", bitsPerPixel, encoder); |
|
|
|
image.VerifyEncoder(provider, "bmp", bitsPerPixel, encoder, customComparer); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|