diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs index d96d3def5e..ff7e34733a 100644 --- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs @@ -8,28 +8,59 @@ using Xunit; namespace SixLabors.ImageSharp.Tests { + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + + using Xunit.Abstractions; + public class BmpEncoderTests : FileTestBase { - public static readonly TheoryData BitsPerPixel - = new TheoryData + private const PixelTypes PixelTypesToTest = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24; + + public static readonly TheoryData BitsPerPixel = + new TheoryData + { + BmpBitsPerPixel.Pixel24, + BmpBitsPerPixel.Pixel32 + }; + + public BmpEncoderTests(ITestOutputHelper output) { - BmpBitsPerPixel.Pixel24, - BmpBitsPerPixel.Pixel32 - }; + this.Output = output; + } + + private ITestOutputHelper Output { get; } [Theory] - [MemberData(nameof(BitsPerPixel))] - public void BitmapCanEncodeDifferentBitRates(BmpBitsPerPixel bitsPerPixel) + [WithTestPatternImages(nameof(BitsPerPixel), 48, 24, PixelTypesToTest)] + [WithTestPatternImages(nameof(BitsPerPixel), 47, 8, PixelTypesToTest)] + [WithTestPatternImages(nameof(BitsPerPixel), 49, 7, PixelTypesToTest)] + [WithSolidFilledImages(nameof(BitsPerPixel), 1, 1, 255, 100, 50, 255, PixelTypesToTest)] + [WithTestPatternImages(nameof(BitsPerPixel), 7, 5, PixelTypesToTest)] + public void Encode(TestImageProvider provider, BmpBitsPerPixel bitsPerPixel) + where TPixel : struct, IPixel { - string path = TestEnvironment.CreateOutputDirectory("Bmp"); - - foreach (TestFile file in Files) + + using (Image image = provider.GetImage()) { - string filename = file.GetFileNameWithoutExtension(bitsPerPixel); - using (Image image = file.CreateImage()) - { - image.Save($"{path}/{filename}.bmp", new BmpEncoder { BitsPerPixel = bitsPerPixel }); - } + // there is no alpha in bmp! + image.Mutate( + c => c.Opacity(1) + ); + + var encoder = new BmpEncoder { BitsPerPixel = bitsPerPixel }; + string path = provider.Utility.SaveTestOutputFile(image, "bmp", encoder, testOutputDetails:bitsPerPixel); + + this.Output.WriteLine(path); + + IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path); + string referenceOutputFile = provider.Utility.GetReferenceOutputFileName("bmp", bitsPerPixel, true); + + this.Output.WriteLine(referenceOutputFile); + + //using (var encodedImage = Image.Load(referenceOutputFile, referenceDecoder)) + //{ + // ImageComparer.Exact.CompareImagesOrFrames(image, encodedImage); + //} } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 0b48170879..7fc9e58d4e 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -86,9 +86,10 @@ namespace SixLabors.ImageSharp.Tests NamedColors.HotPink, NamedColors.Blue }; - int p = 0; + for (int y = top; y < bottom; y++) { + int p = 0; for (int x = left; x < right; x++) { if (x % stride == 0)