|
|
|
@ -4,9 +4,8 @@ |
|
|
|
using System.Numerics; |
|
|
|
|
|
|
|
using Xunit; |
|
|
|
|
|
|
|
public abstract class BulkPixelOperationsTests<TColor> |
|
|
|
where TColor : struct, IPixel<TColor> |
|
|
|
|
|
|
|
public abstract class BulkPixelOperationsTests |
|
|
|
{ |
|
|
|
public class ColorPixels : BulkPixelOperationsTests<Color> |
|
|
|
{ |
|
|
|
@ -15,118 +14,234 @@ |
|
|
|
public class ArgbPixels : BulkPixelOperationsTests<Argb> |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public abstract class BulkPixelOperationsTests<TColor> |
|
|
|
where TColor : struct, IPixel<TColor> |
|
|
|
{ |
|
|
|
public static TheoryData<int> ArraySizesData = new TheoryData<int> { 7, 16, 1111 }; |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackFromVector4(int count) |
|
|
|
public void PackFromVector4(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
Vector4[] source = CreateVector4TestData(count); |
|
|
|
TColor[] expected = new TColor[count]; |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
expected[i].PackFromVector4(source[i]); |
|
|
|
} |
|
|
|
|
|
|
|
TestOperation( |
|
|
|
source, |
|
|
|
expected, |
|
|
|
(ops, s, d) => ops.PackFromVector4(s, d, count) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackToVector4(int count) |
|
|
|
public void PackToVector4(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
TColor[] source = CreatePixelTestData(count); |
|
|
|
Vector4[] expected = new Vector4[count]; |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
expected[i] = source[i].ToVector4(); |
|
|
|
} |
|
|
|
|
|
|
|
TestOperation( |
|
|
|
source, |
|
|
|
expected, |
|
|
|
(ops, s, d) => ops.PackToVector4(s, d, count) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackToXyzBytes(int count) |
|
|
|
public void PackFromXyzBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
byte[] source = CreateByteTestData(count * 3); |
|
|
|
TColor[] expected = new TColor[count]; |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
int i3 = i * 3; |
|
|
|
|
|
|
|
expected[i].PackFromBytes(source[i3 + 0], source[i3 + 1], source[i3 + 2], 255); |
|
|
|
} |
|
|
|
|
|
|
|
TestOperation( |
|
|
|
source, |
|
|
|
expected, |
|
|
|
(ops, s, d) => ops.PackFromXyzBytes(s, d, count) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackFromXyzBytes(int count) |
|
|
|
public void PackToXyzBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
TColor[] source = CreatePixelTestData(count); |
|
|
|
byte[] expected = new byte[count * 3]; |
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
int i3 = i * 3; |
|
|
|
source[i].ToXyzBytes(expected, i3); |
|
|
|
} |
|
|
|
|
|
|
|
TestOperation( |
|
|
|
source, |
|
|
|
expected, |
|
|
|
(ops, s, d) => ops.PackToXyzBytes(s, d, count) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackToXyzwBytes(int count) |
|
|
|
public void PackToXyzwBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackFromXyzwBytes(int count) |
|
|
|
public void PackFromXyzwBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackToZyxBytes(int count) |
|
|
|
public void PackToZyxBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackFromZyxBytes(int count) |
|
|
|
public void PackFromZyxBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackToZyxwBytes(int count) |
|
|
|
public void PackToZyxwBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(ArraySizesData))] |
|
|
|
public virtual void PackFromZyxwBytes(int count) |
|
|
|
public void PackFromZyxwBytes(int count) |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
public class TestBuffers |
|
|
|
|
|
|
|
private class TestBuffers<TSource, TDest> : IDisposable |
|
|
|
where TSource : struct |
|
|
|
where TDest : struct |
|
|
|
{ |
|
|
|
internal static PinnedBuffer<Vector4> Vector4(int length) |
|
|
|
public PinnedBuffer<TSource> SourceBuffer { get; } |
|
|
|
public PinnedBuffer<TDest> ActualDestBuffer { get; } |
|
|
|
public PinnedBuffer<TDest> ExpectedDestBuffer { get; } |
|
|
|
|
|
|
|
public ArrayPointer<TSource> Source => this.SourceBuffer.GetArrayPointer(); |
|
|
|
public ArrayPointer<TDest> ActualDest => this.ActualDestBuffer.GetArrayPointer(); |
|
|
|
|
|
|
|
public TestBuffers(TSource[] source, TDest[] expectedDest) |
|
|
|
{ |
|
|
|
this.SourceBuffer = new PinnedBuffer<TSource>(source); |
|
|
|
this.ExpectedDestBuffer = new PinnedBuffer<TDest>(expectedDest); |
|
|
|
this.ActualDestBuffer = new PinnedBuffer<TDest>(expectedDest.Length); |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
{ |
|
|
|
Vector4[] result = new Vector4[length]; |
|
|
|
Random rnd = new Random(42); // Deterministic random values
|
|
|
|
this.SourceBuffer.Dispose(); |
|
|
|
this.ActualDestBuffer.Dispose(); |
|
|
|
this.ExpectedDestBuffer.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < result.Length; i++) |
|
|
|
public void Verify() |
|
|
|
{ |
|
|
|
int count = this.ExpectedDestBuffer.Count; |
|
|
|
TDest[] expected = this.ExpectedDestBuffer.Array; |
|
|
|
TDest[] actual = this.ActualDestBuffer.Array; |
|
|
|
for (int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
result[i] = GetVector(rnd); |
|
|
|
Assert.Equal(expected[i], actual[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new PinnedBuffer<Vector4>(result); |
|
|
|
private static void TestOperation<TSource, TDest>( |
|
|
|
TSource[] source, |
|
|
|
TDest[] expected, |
|
|
|
Action<BulkPixelOperations<TColor>, ArrayPointer<TSource>, ArrayPointer<TDest>> action) |
|
|
|
where TSource : struct |
|
|
|
where TDest : struct |
|
|
|
{ |
|
|
|
using (var buffers = new TestBuffers<TSource, TDest>(source, expected)) |
|
|
|
{ |
|
|
|
action(BulkPixelOperations<TColor>.Instance, buffers.Source, buffers.ActualDest); |
|
|
|
buffers.Verify(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
internal static PinnedBuffer<TColor> Pixel(int length) |
|
|
|
private static Vector4[] CreateVector4TestData(int length) |
|
|
|
{ |
|
|
|
Vector4[] result = new Vector4[length]; |
|
|
|
Random rnd = new Random(42); // Deterministic random values
|
|
|
|
|
|
|
|
for (int i = 0; i < result.Length; i++) |
|
|
|
{ |
|
|
|
TColor[] result = new TColor[length]; |
|
|
|
result[i] = GetVector(rnd); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
Random rnd = new Random(42); // Deterministic random values
|
|
|
|
private static TColor[] CreatePixelTestData(int length) |
|
|
|
{ |
|
|
|
TColor[] result = new TColor[length]; |
|
|
|
|
|
|
|
for (int i = 0; i < result.Length; i++) |
|
|
|
{ |
|
|
|
Vector4 v = GetVector(rnd); |
|
|
|
result[i].PackFromVector4(v); |
|
|
|
} |
|
|
|
Random rnd = new Random(42); // Deterministic random values
|
|
|
|
|
|
|
|
return new PinnedBuffer<TColor>(result); |
|
|
|
for (int i = 0; i < result.Length; i++) |
|
|
|
{ |
|
|
|
Vector4 v = GetVector(rnd); |
|
|
|
result[i].PackFromVector4(v); |
|
|
|
} |
|
|
|
|
|
|
|
private static Vector4 GetVector(Random rnd) |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private static byte[] CreateByteTestData(int length) |
|
|
|
{ |
|
|
|
byte[] result = new byte[length]; |
|
|
|
Random rnd = new Random(42); // Deterministic random values
|
|
|
|
|
|
|
|
for (int i = 0; i < result.Length; i++) |
|
|
|
{ |
|
|
|
return new Vector4( |
|
|
|
(float)rnd.NextDouble(), |
|
|
|
(float)rnd.NextDouble(), |
|
|
|
(float)rnd.NextDouble(), |
|
|
|
(float)rnd.NextDouble() |
|
|
|
); |
|
|
|
result[i] = (byte)rnd.Next(255); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private static Vector4 GetVector(Random rnd) |
|
|
|
{ |
|
|
|
return new Vector4( |
|
|
|
(float)rnd.NextDouble(), |
|
|
|
(float)rnd.NextDouble(), |
|
|
|
(float)rnd.NextDouble(), |
|
|
|
(float)rnd.NextDouble() |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |