Browse Source

optimized ResizeTests output further, added Bike.png

pull/298/head
Anton Firszov 9 years ago
parent
commit
cd2e0a1be8
  1. 2
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  2. 4
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  3. 9
      tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
  4. 68
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  5. 2
      tests/ImageSharp.Tests/TestImages.cs
  6. 25
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  7. 16
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  8. 4
      tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs
  9. BIN
      tests/Images/Input/Png/Bike.png
  10. BIN
      tests/Images/Input/Png/CalliphoraPartialGrayscale.png

2
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -18,7 +18,7 @@
<ItemGroup>
<!--<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />-->
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
<!--<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />-->
</ItemGroup>
<ItemGroup>

4
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -13,8 +13,8 @@
<PackageReference Include="CoreCompat.System.Drawing" Version="1.0.0-beta006" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="xunit" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta3-build3705" />
<PackageReference Include="xunit" Version="2.3.0-beta4-build3742" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta4-build3742" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />

9
tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs

@ -12,8 +12,9 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
public class DetectEdgesTest : FileTestBase
{
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters
= new TheoryData<EdgeDetection>
public static readonly string[] CommonTestImages = { TestImages.Png.Bike };
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters = new TheoryData<EdgeDetection>
{
EdgeDetection.Kayyali,
EdgeDetection.Kirsch,
@ -29,7 +30,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)]
public void ImageShouldApplyDetectEdgesFilter<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
public void DetectEdges<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -41,7 +42,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)]
public void ImageShouldApplyDetectEdgesFilterInBox<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
public void DetectEdgesInBox<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())

68
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -12,7 +12,9 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
public class ResizeTests : FileTestBase
{
public static readonly string[] ResizeFiles = { TestImages.Png.CalliphoraPartial };
public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial };
public static readonly string[] GrayscaleTestImages = { TestImages.Png.CalliphoraPartialGrayscale };
public static readonly TheoryData<string, IResampler> AllReSamplers =
new TheoryData<string, IResampler>
@ -31,7 +33,7 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
{ "RobidouxSharp", new RobidouxSharpResampler() },
{ "Welch", new WelchResampler() }
};
[Theory]
[WithFile(TestImages.Gif.Giphy, DefaultPixelType)]
public void ResizeShouldApplyToAllFrames<TPixel>(TestImageProvider<TPixel> provider)
@ -46,8 +48,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
[Theory]
[WithTestPatternImages(nameof(AllReSamplers), 100, 100, DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(ResizeFiles), nameof(AllReSamplers), DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(ResizeFiles), nameof(AllReSamplers), DefaultPixelType, 0.3f)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllReSamplers), DefaultPixelType, 0.3f)]
public void ResizeFullImage<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler, float ratio)
where TPixel : struct, IPixel<TPixel>
{
@ -73,8 +75,8 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeFromSourceRectangle<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeFromSourceRectangle<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -83,13 +85,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Mutate(x => x.Resize(image.Width, image.Height, new BicubicResampler(), sourceRectangle, destRectangle, false));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWidthAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWidthAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -100,20 +102,20 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeHeightAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeHeightAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Resize(0, image.Height / 3, false));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithCropWidthMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithCropWidthMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -124,13 +126,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithCropHeightMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithCropHeightMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -141,13 +143,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithPadMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithPadMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -159,13 +161,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithBoxPadMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithBoxPadMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -177,13 +179,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithMaxMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithMaxMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -195,13 +197,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithMinMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithMinMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -213,13 +215,13 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), DefaultPixelType)]
public void ImageShouldResizeWithStretchMode<TPixel>(TestImageProvider<TPixel> provider)
[WithFileCollection(nameof(GrayscaleTestImages), DefaultPixelType)]
public void ResizeWithStretchMode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -231,7 +233,7 @@ namespace ImageSharp.Tests.Processing.Processors.Transforms
};
image.Mutate(x => x.Resize(options));
image.DebugSave(provider);
image.DebugSave(provider, grayscale: true);
}
}

2
tests/ImageSharp.Tests/TestImages.cs

@ -27,6 +27,8 @@ namespace ImageSharp.Tests
public const string Interlaced = "Png/interlaced.png";
public const string Rgb48Bpp = "Png/rgb-48bpp.png";
public const string CalliphoraPartial = "Png/CalliphoraPartial.png";
public const string CalliphoraPartialGrayscale = "Png/CalliphoraPartialGrayscale.png";
public const string Bike = "Png/Bike.png";
public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png";
// Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html

25
tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

@ -131,12 +131,13 @@ namespace ImageSharp.Tests
Image<TPixel> image,
string extension = null,
IImageEncoder encoder = null,
object settings = null)
object testOutputDetails = null,
bool grayscale = false)
where TPixel : struct, IPixel<TPixel>
{
string path = this.GetTestOutputFileName(extension: extension, settings: settings);
string path = this.GetTestOutputFileName(extension: extension, settings: testOutputDetails);
string extension1 = Path.GetExtension(path);
encoder = encoder ?? GetImageFormatByExtension(extension1);
encoder = encoder ?? GetImageFormatByExtension(extension1, grayscale);
using (FileStream stream = File.OpenWrite(path))
{
@ -158,11 +159,25 @@ namespace ImageSharp.Tests
this.Init(method.DeclaringType.Name, method.Name);
}
private static IImageEncoder GetImageFormatByExtension(string extension)
private static IImageEncoder GetImageFormatByExtension(string extension, bool grayscale)
{
extension = extension?.TrimStart('.');
var format = Configuration.Default.FindFormatByFileExtensions(extension);
return Configuration.Default.FindEncoder(format);
IImageEncoder encoder = Configuration.Default.FindEncoder(format);
PngEncoder pngEncoder = encoder as PngEncoder;
if (pngEncoder != null)
{
pngEncoder = new PngEncoder();
encoder = pngEncoder;
pngEncoder.CompressionLevel = 9;
if (grayscale)
{
pngEncoder.PngColorType = PngColorType.Grayscale;
}
}
return encoder;
}
private string GetTestOutputDir()

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

@ -28,7 +28,8 @@ namespace ImageSharp.Tests
this Image<TPixel> image,
ITestImageProvider provider,
object settings = null,
string extension = "png")
string extension = "png",
bool grayscale = false)
where TPixel : struct, IPixel<TPixel>
{
if (TestEnvironment.RunsOnCI)
@ -38,7 +39,11 @@ namespace ImageSharp.Tests
// We are running locally then we want to save it out
provider.Utility.SaveTestOutputFile(image, extension, settings: settings);
provider.Utility.SaveTestOutputFile(
image,
extension,
testOutputDetails: settings,
grayscale: grayscale);
return image;
}
@ -47,6 +52,7 @@ namespace ImageSharp.Tests
ITestImageProvider provider,
object settings = null,
string extension = "png",
bool monochrome1Bpp = false,
float imageTheshold = ImageComparer.DefaultImageThreshold,
byte segmentThreshold = ImageComparer.DefaultSegmentThreshold,
int scalingFactor = ImageComparer.DefaultScalingFactor)
@ -56,7 +62,11 @@ namespace ImageSharp.Tests
if (!TestEnvironment.RunsOnCI)
{
provider.Utility.SaveTestOutputFile(image, extension, settings: settings);
provider.Utility.SaveTestOutputFile(
image,
extension,
testOutputDetails: settings,
grayscale: monochrome1Bpp);
}
if (!File.Exists(referenceOutputFile))

4
tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs

@ -6,11 +6,11 @@ namespace ImageSharp.Tests
using Xunit;
using Xunit.Abstractions;
public class IntegrationTestUtilsTests
public class ReferenceCodecTests
{
private ITestOutputHelper Output { get; }
public IntegrationTestUtilsTests(ITestOutputHelper output)
public ReferenceCodecTests(ITestOutputHelper output)
{
this.Output = output;
}

BIN
tests/Images/Input/Png/Bike.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

BIN
tests/Images/Input/Png/CalliphoraPartialGrayscale.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Loading…
Cancel
Save