|
|
|
@ -2,10 +2,12 @@ |
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using SixLabors.ImageSharp.Formats.Bmp; |
|
|
|
using SixLabors.ImageSharp.Metadata; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
using SixLabors.ImageSharp.Processing; |
|
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
|
|
|
|
|
using Xunit; |
|
|
|
using Xunit.Abstractions; |
|
|
|
@ -110,11 +112,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp |
|
|
|
[WithFile(Bit32Rgba, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|
|
|
[WithFile(WinBmpv4, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|
|
|
[WithFile(WinBmpv5, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|
|
|
// WinBmpv3 is a 24 bits per pixel image
|
|
|
|
[WithFile(WinBmpv3, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)] |
|
|
|
[WithFile(Rgb16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)] |
|
|
|
[WithFile(Bit16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)] |
|
|
|
public void Encode_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
public void Encode_32Bit_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
// if supportTransparency is false, a v3 bitmap header will be written
|
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false); |
|
|
|
|
|
|
|
@ -123,24 +121,84 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp |
|
|
|
[WithFile(Bit32Rgba, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|
|
|
[WithFile(WinBmpv4, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|
|
|
[WithFile(WinBmpv5, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)] |
|
|
|
public void Encode_32Bit_WithV4Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true); |
|
|
|
|
|
|
|
[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); |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(Rgb16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)] |
|
|
|
[WithFile(Bit16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)] |
|
|
|
public void Encode_16Bit_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(Rgb16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)] |
|
|
|
[WithFile(Bit16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)] |
|
|
|
public void Encode_WithV4Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
public void Encode_16Bit_WithV4Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel) |
|
|
|
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true); |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(WinBmpv5, PixelTypes.Rgba32, BmpBitsPerPixel.Pixel8)] |
|
|
|
[WithFile(Bit8Palette4, PixelTypes.Rgba32, 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)] |
|
|
|
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()) |
|
|
|
{ |
|
|
|
// There is no alpha in bmp with 24 bits per pixels, so the reference image will be made opaque.
|
|
|
|
if (bitsPerPixel == BmpBitsPerPixel.Pixel24) |
|
|
|
// There is no alpha in bmp with less then 32 bits per pixels, so the reference image will be made opaque.
|
|
|
|
if (bitsPerPixel != BmpBitsPerPixel.Pixel32) |
|
|
|
{ |
|
|
|
image.Mutate(c => c.MakeOpaque()); |
|
|
|
} |
|
|
|
@ -148,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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|