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

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

@ -227,6 +227,33 @@ namespace SixLabors.ImageSharp.Tests
return image; 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) internal static Image<Rgba32> ToGrayscaleImage(this Buffer2D<float> buffer, float scale)
{ {
var image = new Image<Rgba32>(buffer.Width, buffer.Height); var image = new Image<Rgba32>(buffer.Width, buffer.Height);
@ -242,5 +269,6 @@ namespace SixLabors.ImageSharp.Tests
return image; return image;
} }
} }
} }

2
tests/Images/External

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