|
|
|
@ -109,6 +109,16 @@ namespace SixLabors.ImageSharp.Tests.Common |
|
|
|
AssertEvenRoundIsCorrect(r, v); |
|
|
|
} |
|
|
|
|
|
|
|
private bool SkipOnNonAvx2([CallerMemberName] string testCaseName = null) |
|
|
|
{ |
|
|
|
if (!SimdUtils.IsAvx2CompatibleArchitecture) |
|
|
|
{ |
|
|
|
this.Output.WriteLine("Skipping AVX2 specific test case: " + testCaseName); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(1, 0)] |
|
|
|
[InlineData(1, 8)] |
|
|
|
@ -116,6 +126,11 @@ namespace SixLabors.ImageSharp.Tests.Common |
|
|
|
[InlineData(3, 128)] |
|
|
|
public void BulkConvertNormalizedFloatToByte_WithRoundedData(int seed, int count) |
|
|
|
{ |
|
|
|
if (this.SkipOnNonAvx2()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
float[] orig = new Random(seed).GenerateRandomRoundedFloatArray(count, 0, 256); |
|
|
|
float[] normalized = orig.Select(f => f / 255f).ToArray(); |
|
|
|
|
|
|
|
@ -135,6 +150,11 @@ namespace SixLabors.ImageSharp.Tests.Common |
|
|
|
[InlineData(3, 128)] |
|
|
|
public void BulkConvertNormalizedFloatToByte_WithNonRoundedData(int seed, int count) |
|
|
|
{ |
|
|
|
if (this.SkipOnNonAvx2()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
float[] source = new Random(seed).GenerateRandomFloatArray(count, 0, 1f); |
|
|
|
|
|
|
|
byte[] dest = new byte[count]; |
|
|
|
@ -155,6 +175,11 @@ namespace SixLabors.ImageSharp.Tests.Common |
|
|
|
[InlineData(3, 128)] |
|
|
|
public void BulkConvertNormalizedFloatToByteClampOverflows(int seed, int count) |
|
|
|
{ |
|
|
|
if (this.SkipOnNonAvx2()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
float[] orig = new Random(seed).GenerateRandomRoundedFloatArray(count, -50, 444); |
|
|
|
float[] normalized = orig.Select(f => f / 255f).ToArray(); |
|
|
|
|
|
|
|
@ -185,6 +210,11 @@ namespace SixLabors.ImageSharp.Tests.Common |
|
|
|
[Fact] |
|
|
|
private void BulkConvertNormalizedFloatToByte_Step() |
|
|
|
{ |
|
|
|
if (this.SkipOnNonAvx2()) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
float[] source = {0, 7, 42, 255, 0.5f, 1.1f, 2.6f, 16f}; |
|
|
|
byte[] expected = source.Select(f => (byte)Math.Round(f)).ToArray(); |
|
|
|
|
|
|
|
|