Browse Source

BmpEncoderTests using reference output

af/merge-core
Anton Firszov 8 years ago
parent
commit
d21064927b
  1. 48
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
  2. 28
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  3. 2
      tests/Images/External

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

@ -5,6 +5,7 @@ using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests
{
@ -31,36 +32,37 @@ namespace SixLabors.ImageSharp.Tests
private ITestOutputHelper Output { get; }
[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)
[WithTestPatternImages(nameof(BitsPerPixel), 24, 24, PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24)]
public void Encode_IsNotBoundToSinglePixelType<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{
TestBmpEncoderCore(provider, bitsPerPixel);
}
[Theory]
[WithTestPatternImages(nameof(BitsPerPixel), 48, 24, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel), 47, 8, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel), 49, 7, PixelTypes.Rgba32)]
[WithSolidFilledImages(nameof(BitsPerPixel), 1, 1, 255, 100, 50, 255, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel), 7, 5, PixelTypes.Rgba32)]
public void Encode_WorksWithDifferentSizes<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{
TestBmpEncoderCore(provider, bitsPerPixel);
}
private static void TestBmpEncoderCore<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
// 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);
image.Mutate(c => c.Opacity(1));
this.Output.WriteLine(path);
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path);
string referenceOutputFile = provider.Utility.GetReferenceOutputFileName("bmp", bitsPerPixel, true);
this.Output.WriteLine(referenceOutputFile);
var encoder = new BmpEncoder { BitsPerPixel = bitsPerPixel };
//using (var encodedImage = Image.Load<TPixel>(referenceOutputFile, referenceDecoder))
//{
// ImageComparer.Exact.CompareImagesOrFrames(image, encodedImage);
//}
// Does DebugSave & load reference CompareToReferenceInput():
image.VerifyEncoder(provider, "bmp", bitsPerPixel, encoder);
}
}
}

28
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -227,6 +227,33 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
/// <summary>
/// Loads the expected image with a reference decoder + compares it to <paramref name="image"/>.
/// Also performs a debug save using <see cref="ImagingTestCaseUtility.SaveTestOutputFile{TPixel}"/>.
/// </summary>
internal static void VerifyEncoder<TPixel>(this Image<TPixel> image,
ITestImageProvider provider,
string extension,
object testOutputDetails,
IImageEncoder encoder,
ImageComparer customComparer = null,
bool appendPixelTypeToFileName = true
)
where TPixel : struct, IPixel<TPixel>
{
string path = provider.Utility.SaveTestOutputFile(image, extension, encoder, testOutputDetails, appendPixelTypeToFileName);
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path);
string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, testOutputDetails, appendPixelTypeToFileName);
using (var encodedImage = Image.Load<TPixel>(referenceOutputFile, referenceDecoder))
{
ImageComparer comparer = customComparer ?? ImageComparer.Exact;
comparer.CompareImagesOrFrames(image, encodedImage);
}
}
internal static Image<Rgba32> ToGrayscaleImage(this Buffer2D<float> buffer, float scale)
{
var image = new Image<Rgba32>(buffer.Width, buffer.Height);
@ -242,5 +269,6 @@ namespace SixLabors.ImageSharp.Tests
return image;
}
}
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit 376605e05bb704d425b2d17bf5b310f5376da22e
Subproject commit 6508e097adf1ef6c38a8df17465c6868ed133256
Loading…
Cancel
Save