@ -20,42 +20,82 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
public static readonly string [ ] CommonTestImages = { TestImages . Png . CalliphoraPartial } ;
private static readonly ImageComparer ValidatorComparer = ImageComparer . TolerantPercentage ( 0.07F ) ;
public static readonly TheoryData < string , IResampler > AllResamplers =
new TheoryData < string , IResampler >
public static readonly string [ ] AllResamplerNames = TestUtils . GetAllResamplerNames ( ) ;
public static readonly string [ ] SmokeTestResamplerNames =
{
{ "Bicubic" , KnownResamplers . Bicubic } ,
{ "Triangle" , KnownResamplers . Triangle } ,
{ "NearestNeighbor" , KnownResamplers . NearestNeighbor } ,
{ "Box" , KnownResamplers . Box } ,
// { "Lanczos2", KnownResamplers.Lanczos2 }, TODO: Add expected file
{ "Lanczos3" , KnownResamplers . Lanczos3 } ,
{ "Lanczos5" , KnownResamplers . Lanczos5 } ,
{ "MitchellNetravali" , KnownResamplers . MitchellNetravali } ,
{ "Lanczos8" , KnownResamplers . Lanczos8 } ,
{ "Hermite" , KnownResamplers . Hermite } ,
{ "Spline" , KnownResamplers . Spline } ,
{ "Robidoux" , KnownResamplers . Robidoux } ,
{ "RobidouxSharp" , KnownResamplers . RobidouxSharp } ,
{ "Welch" , KnownResamplers . Welch }
nameof ( KnownResamplers . NearestNeighbor ) ,
nameof ( KnownResamplers . Bicubic ) ,
nameof ( KnownResamplers . Box ) ,
nameof ( KnownResamplers . Lanczos5 ) ,
} ;
[Theory]
[WithTestPatternImages(nameof(AllResamplers), 100, 100, DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllResamplers), DefaultPixelType, 0.5f)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllResamplers), DefaultPixelType, 0.3f)]
public void Resize_WorksWithAllResamplers < TPixel > ( TestImageProvider < TPixel > provider , string name , IResampler sampler , float ratio )
[WithFileCollection(nameof(CommonTestImages), nameof(AllResamplerNames), DefaultPixelType, 0.5f, null, null)]
[WithFileCollection(nameof(CommonTestImages), nameof(SmokeTestResamplerNames), DefaultPixelType, 0.3f, null, null)]
[WithFileCollection(nameof(CommonTestImages), nameof(SmokeTestResamplerNames), DefaultPixelType, 1.8f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 100, 100, DefaultPixelType, 0.5f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 100, 100, DefaultPixelType, 1f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 50, 50, DefaultPixelType, 8f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 201, 199, DefaultPixelType, null, 100, 99)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 301, 1180, DefaultPixelType, null, 300, 480)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 49, 80, DefaultPixelType, null, 301, 100)]
public void Resize_WorksWithAllResamplers < TPixel > (
TestImageProvider < TPixel > provider ,
string samplerName ,
float? ratio ,
int? specificDestWidth ,
int? specificDestHeight )
where TPixel : struct , IPixel < TPixel >
{
using ( Image < TPixel > image = provider . GetImage ( ) )
{
SizeF newSize = image . Size ( ) * ratio ;
image . Mutate ( x = > x . Resize ( ( Size ) newSize , sampler , false ) ) ;
FormattableString details = $"{name}-{ratio.ToString(System.Globalization.CultureInfo.InvariantCulture)}" ;
IResampler sampler = TestUtils . GetResampler ( samplerName ) ;
image . DebugSave ( provider , details ) ;
image . CompareToReferenceOutput ( ImageComparer . TolerantPercentage ( 0.02f ) , provider , details ) ;
}
// NeirestNeighbourResampler is producing slightly different results With classic .NET framework on 32bit
// most likely because of differences in numeric behavior.
// The difference is well visible when comparing output for
// Resize_WorksWithAllResamplers_TestPattern301x1180_NearestNeighbor-300x480.png
// TODO: Should we investigate this?
bool allowHigherInaccuracy = ! TestEnvironment . Is64BitProcess
& & string . IsNullOrEmpty ( TestEnvironment . NetCoreVersion )
& & sampler is NearestNeighborResampler ;
var comparer = ImageComparer . TolerantPercentage ( allowHigherInaccuracy ? 0.3f : 0.017f ) ;
provider . RunValidatingProcessorTest (
ctx = >
{
SizeF newSize ;
string destSizeInfo ;
if ( ratio . HasValue )
{
newSize = ctx . GetCurrentSize ( ) * ratio . Value ;
destSizeInfo = ratio . Value . ToString ( System . Globalization . CultureInfo . InvariantCulture ) ;
}
else
{
if ( ! specificDestWidth . HasValue | | ! specificDestHeight . HasValue )
{
throw new InvalidOperationException (
"invalid dimensional input for Resize_WorksWithAllResamplers!" ) ;
}
newSize = new SizeF ( specificDestWidth . Value , specificDestHeight . Value ) ;
destSizeInfo = $"{newSize.Width}x{newSize.Height}" ;
}
FormattableString testOutputDetails = $"{samplerName}-{destSizeInfo}" ;
ctx . Apply (
img = > img . DebugSave (
provider ,
$"{testOutputDetails}-ORIGINAL" ,
appendPixelTypeToFileName : false ) ) ;
ctx . Resize ( ( Size ) newSize , sampler , false ) ;
return testOutputDetails ;
} ,
comparer ,
appendPixelTypeToFileName : false ) ;
}
[Theory]