@ -13,10 +13,7 @@ public partial class ResizeKernelMapTests
{
private ITestOutputHelper Output { get ; }
public ResizeKernelMapTests ( ITestOutputHelper output )
{
this . Output = output ;
}
public ResizeKernelMapTests ( ITestOutputHelper output ) = > this . Output = output ;
/// <summary>
/// resamplerName, srcSize, destSize
@ -24,71 +21,70 @@ public partial class ResizeKernelMapTests
public static readonly TheoryData < IResampler , int , int > KernelMapData
= new ( )
{
{ KnownResamplers . Bicubic , 1 5 , 1 0 } ,
{ KnownResamplers . Bicubic , 1 0 , 1 5 } ,
{ KnownResamplers . Bicubic , 2 0 , 2 0 } ,
{ KnownResamplers . Bicubic , 5 0 , 4 0 } ,
{ KnownResamplers . Bicubic , 4 0 , 5 0 } ,
{ KnownResamplers . Bicubic , 5 0 0 , 2 0 0 } ,
{ KnownResamplers . Bicubic , 2 0 0 , 5 0 0 } ,
{ KnownResamplers . Bicubic , 3 0 3 2 , 4 0 0 } ,
{ KnownResamplers . Bicubic , 1 0 , 2 5 } ,
{ KnownResamplers . Lanczos3 , 1 6 , 1 2 } ,
{ KnownResamplers . Lanczos3 , 1 2 , 1 6 } ,
{ KnownResamplers . Lanczos3 , 1 2 , 9 } ,
{ KnownResamplers . Lanczos3 , 9 , 1 2 } ,
{ KnownResamplers . Lanczos3 , 6 , 8 } ,
{ KnownResamplers . Lanczos3 , 8 , 6 } ,
{ KnownResamplers . Lanczos3 , 2 0 , 1 2 } ,
{ KnownResamplers . Lanczos3 , 5 , 2 5 } ,
{ KnownResamplers . Lanczos3 , 5 , 5 0 } ,
{ KnownResamplers . Lanczos3 , 2 5 , 5 } ,
{ KnownResamplers . Lanczos3 , 5 0 , 5 } ,
{ KnownResamplers . Lanczos3 , 4 9 , 5 } ,
{ KnownResamplers . Lanczos3 , 3 1 , 5 } ,
{ KnownResamplers . Lanczos8 , 5 0 0 , 2 0 0 } ,
{ KnownResamplers . Lanczos8 , 1 0 0 , 1 0 } ,
{ KnownResamplers . Lanczos8 , 1 0 0 , 8 0 } ,
{ KnownResamplers . Lanczos8 , 1 0 , 1 0 0 } ,
// Resize_WorksWithAllResamplers_Rgba32_CalliphoraPartial_Box-0.5:
{ KnownResamplers . Box , 3 7 8 , 1 4 9 } ,
{ KnownResamplers . Box , 3 4 9 , 1 7 4 } ,
// Accuracy-related regression-test cases cherry-picked from GeneratedImageResizeData
{ KnownResamplers . Box , 2 0 1 , 1 0 0 } ,
{ KnownResamplers . Box , 1 9 9 , 9 9 } ,
{ KnownResamplers . Box , 1 0 , 2 9 9 } ,
{ KnownResamplers . Box , 2 9 9 , 1 0 } ,
{ KnownResamplers . Box , 3 0 1 , 3 0 0 } ,
{ KnownResamplers . Box , 1 1 8 0 , 4 8 0 } ,
{ KnownResamplers . Lanczos2 , 3 2 6 4 , 3 0 3 2 } ,
{ KnownResamplers . Bicubic , 1 2 8 0 , 2 2 4 0 } ,
{ KnownResamplers . Bicubic , 1 9 2 0 , 1 6 8 0 } ,
{ KnownResamplers . Bicubic , 3 0 7 2 , 2 2 4 0 } ,
{ KnownResamplers . Welch , 3 0 0 , 2 0 0 8 } ,
// ResizeKernel.Length -related regression tests cherry-picked from GeneratedImageResizeData
{ KnownResamplers . Bicubic , 1 0 , 5 0 } ,
{ KnownResamplers . Bicubic , 4 9 , 3 0 1 } ,
{ KnownResamplers . Bicubic , 3 0 1 , 4 9 } ,
{ KnownResamplers . Bicubic , 1 6 8 0 , 1 2 0 0 } ,
{ KnownResamplers . Box , 1 3 , 2 9 9 } ,
{ KnownResamplers . Lanczos5 , 3 0 3 2 , 6 0 0 } ,
// Large number. https://github.com/SixLabors/ImageSharp/issues/1616
{ KnownResamplers . Bicubic , 2 0 7 7 7 3 , 5 1 9 4 3 }
} ;
public static TheoryData < string , int , int > GeneratedImageResizeData =
GenerateImageResizeData ( ) ;
{ KnownResamplers . Bicubic , 1 5 , 1 0 } ,
{ KnownResamplers . Bicubic , 1 0 , 1 5 } ,
{ KnownResamplers . Bicubic , 2 0 , 2 0 } ,
{ KnownResamplers . Bicubic , 5 0 , 4 0 } ,
{ KnownResamplers . Bicubic , 4 0 , 5 0 } ,
{ KnownResamplers . Bicubic , 5 0 0 , 2 0 0 } ,
{ KnownResamplers . Bicubic , 2 0 0 , 5 0 0 } ,
{ KnownResamplers . Bicubic , 3 0 3 2 , 4 0 0 } ,
{ KnownResamplers . Bicubic , 1 0 , 2 5 } ,
{ KnownResamplers . Lanczos3 , 1 6 , 1 2 } ,
{ KnownResamplers . Lanczos3 , 1 2 , 1 6 } ,
{ KnownResamplers . Lanczos3 , 1 2 , 9 } ,
{ KnownResamplers . Lanczos3 , 9 , 1 2 } ,
{ KnownResamplers . Lanczos3 , 6 , 8 } ,
{ KnownResamplers . Lanczos3 , 8 , 6 } ,
{ KnownResamplers . Lanczos3 , 2 0 , 1 2 } ,
{ KnownResamplers . Lanczos3 , 5 , 2 5 } ,
{ KnownResamplers . Lanczos3 , 5 , 5 0 } ,
{ KnownResamplers . Lanczos3 , 2 5 , 5 } ,
{ KnownResamplers . Lanczos3 , 5 0 , 5 } ,
{ KnownResamplers . Lanczos3 , 4 9 , 5 } ,
{ KnownResamplers . Lanczos3 , 3 1 , 5 } ,
{ KnownResamplers . Lanczos8 , 5 0 0 , 2 0 0 } ,
{ KnownResamplers . Lanczos8 , 1 0 0 , 1 0 } ,
{ KnownResamplers . Lanczos8 , 1 0 0 , 8 0 } ,
{ KnownResamplers . Lanczos8 , 1 0 , 1 0 0 } ,
// Resize_WorksWithAllResamplers_Rgba32_CalliphoraPartial_Box-0.5:
{ KnownResamplers . Box , 3 7 8 , 1 4 9 } ,
{ KnownResamplers . Box , 3 4 9 , 1 7 4 } ,
// Accuracy-related regression-test cases cherry-picked from GeneratedImageResizeData
{ KnownResamplers . Box , 2 0 1 , 1 0 0 } ,
{ KnownResamplers . Box , 1 9 9 , 9 9 } ,
{ KnownResamplers . Box , 1 0 , 2 9 9 } ,
{ KnownResamplers . Box , 2 9 9 , 1 0 } ,
{ KnownResamplers . Box , 3 0 1 , 3 0 0 } ,
{ KnownResamplers . Box , 1 1 8 0 , 4 8 0 } ,
{ KnownResamplers . Lanczos2 , 3 2 6 4 , 3 0 3 2 } ,
{ KnownResamplers . Bicubic , 1 2 8 0 , 2 2 4 0 } ,
{ KnownResamplers . Bicubic , 1 9 2 0 , 1 6 8 0 } ,
{ KnownResamplers . Bicubic , 3 0 7 2 , 2 2 4 0 } ,
{ KnownResamplers . Welch , 3 0 0 , 2 0 0 8 } ,
// ResizeKernel.Length -related regression tests cherry-picked from GeneratedImageResizeData
{ KnownResamplers . Bicubic , 1 0 , 5 0 } ,
{ KnownResamplers . Bicubic , 4 9 , 3 0 1 } ,
{ KnownResamplers . Bicubic , 3 0 1 , 4 9 } ,
{ KnownResamplers . Bicubic , 1 6 8 0 , 1 2 0 0 } ,
{ KnownResamplers . Box , 1 3 , 2 9 9 } ,
{ KnownResamplers . Lanczos5 , 3 0 3 2 , 6 0 0 } ,
// Large number. https://github.com/SixLabors/ImageSharp/issues/1616
{ KnownResamplers . Bicubic , 2 0 7 7 7 3 , 5 1 9 4 3 }
} ;
public static TheoryData < string , int , int > GeneratedImageResizeData = GenerateImageResizeData ( ) ;
[Theory(Skip = "Only for debugging and development")]
[MemberData(nameof(KernelMapData))]
public void PrintNonNormalizedKernelMap < TResampler > ( TResampler resampler , int srcSize , int destSize )
where TResampler : struct , IResampler
{
ReferenceKernelMap kernelMap = ReferenceKernelMap . Calculate < TResampler > ( in resampler , destSize , srcSize , false ) ;
ReferenceKernelMap kernelMap = ReferenceKernelMap . Calculate ( in resampler , destSize , srcSize , false ) ;
this . Output . WriteLine ( $"Actual KernelMap:\n{PrintKernelMap(kernelMap)}\n" ) ;
}
@ -97,9 +93,7 @@ public partial class ResizeKernelMapTests
[MemberData(nameof(KernelMapData))]
public void KernelMapContentIsCorrect < TResampler > ( TResampler resampler , int srcSize , int destSize )
where TResampler : struct , IResampler
{
this . VerifyKernelMapContentIsCorrect ( resampler , srcSize , destSize ) ;
}
= > this . VerifyKernelMapContentIsCorrect ( resampler , srcSize , destSize ) ;
// Comprehensive but expensive tests, for ResizeKernelMap.
// Enabling them can kill you, but sometimes you have to wear the burden!
@ -124,8 +118,8 @@ public partial class ResizeKernelMapTests
this . Output . WriteLine ( $"Expected KernelMap:\n{PrintKernelMap(referenceMap)}\n" ) ;
this . Output . WriteLine ( $"Actual KernelMap:\n{PrintKernelMap(kernelMap)}\n" ) ;
#endif
ApproximateFloatComparer comparer = new ( 1e-6f ) ;
ApproximateFloatComparer comparer = new ApproximateFloatComparer ( 1e-6f ) ;
for ( int i = 0 ; i < kernelMap . DestinationLength ; i + + )
{
ResizeKernel kernel = kernelMap . GetKernel ( ( uint ) i ) ;
@ -139,7 +133,23 @@ public partial class ResizeKernelMapTests
referenceKernel . Left = = kernel . StartIndex ,
$"referenceKernel.Left != kernel.Left: {referenceKernel.Left} != {kernel.StartIndex}" ) ;
float [ ] expectedValues = referenceKernel . Values ;
Span < float > actualValues = kernel . Values ;
Span < float > actualValues ;
if ( ResizeKernel . IsHardwareAccelerated )
{
Assert . Equal ( expectedValues . Length , kernel . Values . Length / 4 ) ;
actualValues = new float [ expectedValues . Length ] ;
for ( int j = 0 ; j < expectedValues . Length ; j + + )
{
actualValues [ j ] = kernel . Values [ j * 4 ] ;
}
}
else
{
actualValues = kernel . Values ;
}
Assert . Equal ( expectedValues . Length , actualValues . Length ) ;
@ -199,12 +209,13 @@ public partial class ResizeKernelMapTests
int [ ] dimensionVals =
[
// Arbitrary, small dimensions:
9 , 1 0 , 1 1 , 1 3 , 4 9 , 5 0 , 5 3 , 9 9 , 1 0 0 , 1 9 9 , 2 0 0 , 2 0 1 , 2 9 9 , 3 0 0 , 3 0 1 ,
9 , 1 0 , 1 1 , 1 3 , 4 9 , 5 0 , 5 3 , 9 9 , 1 0 0 , 1 9 9 , 2 0 0 , 2 0 1 , 2 9 9 , 3 0 0 , 3 0 1 ,
// Typical image sizes:
6 4 0 , 4 8 0 , 8 0 0 , 6 0 0 , 1 0 2 4 , 7 6 8 , 1 2 8 0 , 9 6 0 , 1 5 3 6 , 1 1 8 0 , 1 6 0 0 , 1 2 0 0 , 2 0 4 8 , 1 5 3 6 , 2 2 4 0 , 1 6 8 0 , 2 5 6 0 ,
1 9 2 0 , 3 0 3 2 , 2 0 0 8 , 3 0 7 2 , 2 3 0 4 , 3 2 6 4 , 2 4 4 8
// Typical image sizes:
6 4 0 , 4 8 0 , 8 0 0 , 6 0 0 , 1 0 2 4 , 7 6 8 , 1 2 8 0 , 9 6 0 , 1 5 3 6 , 1 1 8 0 , 1 6 0 0 , 1 2 0 0 , 2 0 4 8 , 1 5 3 6 , 2 2 4 0 , 1 6 8 0 , 2 5 6 0 ,
1 9 2 0 , 3 0 3 2 , 2 0 0 8 , 3 0 7 2 , 2 3 0 4 , 3 2 6 4 , 2 4 4 8
] ;
IOrderedEnumerable < ( int S , int D ) > source2Dest = dimensionVals