Browse Source

better BmpEncoderTests

pull/469/head
Anton Firszov 9 years ago
parent
commit
8e1a4f34b1
  1. 53
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
  2. 3
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

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

@ -8,28 +8,59 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit.Abstractions;
public class BmpEncoderTests : FileTestBase public class BmpEncoderTests : FileTestBase
{ {
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel private const PixelTypes PixelTypesToTest = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24;
= new TheoryData<BmpBitsPerPixel>
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
new TheoryData<BmpBitsPerPixel>
{ {
BmpBitsPerPixel.Pixel24, BmpBitsPerPixel.Pixel24,
BmpBitsPerPixel.Pixel32 BmpBitsPerPixel.Pixel32
}; };
[Theory] public BmpEncoderTests(ITestOutputHelper output)
[MemberData(nameof(BitsPerPixel))]
public void BitmapCanEncodeDifferentBitRates(BmpBitsPerPixel bitsPerPixel)
{ {
string path = TestEnvironment.CreateOutputDirectory("Bmp"); this.Output = output;
}
private ITestOutputHelper Output { get; }
foreach (TestFile file in Files) [Theory]
[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<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{ {
string filename = file.GetFileNameWithoutExtension(bitsPerPixel);
using (Image<Rgba32> image = file.CreateImage()) using (Image<TPixel> image = provider.GetImage())
{ {
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<TPixel>(referenceOutputFile, referenceDecoder))
//{
// ImageComparer.Exact.CompareImagesOrFrames(image, encodedImage);
//}
} }
} }
} }

3
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -86,9 +86,10 @@ namespace SixLabors.ImageSharp.Tests
NamedColors<TPixel>.HotPink, NamedColors<TPixel>.HotPink,
NamedColors<TPixel>.Blue NamedColors<TPixel>.Blue
}; };
int p = 0;
for (int y = top; y < bottom; y++) for (int y = top; y < bottom; y++)
{ {
int p = 0;
for (int x = left; x < right; x++) for (int x = left; x < right; x++)
{ {
if (x % stride == 0) if (x % stride == 0)

Loading…
Cancel
Save