Browse Source

Added test for TransposeInplace

pull/1847/head
Dmitry Pentin 5 years ago
parent
commit
92445c3581
  1. 5
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs
  2. 26
      tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs
  3. 17
      tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs

5
tests/ImageSharp.Tests/Formats/Jpg/Block8x8FTests.cs

@ -183,9 +183,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
Assert.Equal(expected, actual);
}
// This method has only 2 implementations:
// 1. AVX
// 2. Scalar
FeatureTestRunner.RunWithHwIntrinsicsFeature(
RunTest,
HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX | HwIntrinsics.DisableHWIntrinsic);
HwIntrinsics.AllowAll | HwIntrinsics.DisableHWIntrinsic);
}
private static float[] Create8x8ColorCropTestData()

26
tests/ImageSharp.Tests/Formats/Jpg/Block8x8Tests.cs

@ -276,5 +276,31 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
seed,
HwIntrinsics.AllowAll | HwIntrinsics.DisableAVX2);
}
[Fact]
public void TransposeInplace()
{
static void RunTest()
{
short[] expected = Create8x8ShortData();
ReferenceImplementations.Transpose8x8(expected);
var block8x8 = default(Block8x8);
block8x8.LoadFrom(Create8x8ShortData());
block8x8.TransposeInplace();
short[] actual = new short[64];
block8x8.CopyTo(actual);
Assert.Equal(expected, actual);
}
// This method has only 1 implementation:
// 1. Scalar
FeatureTestRunner.RunWithHwIntrinsicsFeature(
RunTest,
HwIntrinsics.DisableHWIntrinsic);
}
}
}

17
tests/ImageSharp.Tests/Formats/Jpg/Utils/ReferenceImplementations.cs

@ -40,6 +40,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils
}
}
/// <summary>
/// Transpose 8x8 block stored linearly in a <see cref="Span{T}"/> (inplace)
/// </summary>
internal static void Transpose8x8(Span<short> data)
{
for (int i = 1; i < 8; i++)
{
int i8 = i * 8;
for (int j = 0; j < i; j++)
{
short tmp = data[i8 + j];
data[i8 + j] = data[(j * 8) + i];
data[(j * 8) + i] = tmp;
}
}
}
/// <summary>
/// Transpose 8x8 block stored linearly in a <see cref="Span{T}"/>
/// </summary>

Loading…
Cancel
Save