|
|
|
@ -3,21 +3,28 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
{ |
|
|
|
using System; |
|
|
|
|
|
|
|
using SixLabors.ImageSharp.Formats.Jpeg.Common; |
|
|
|
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; |
|
|
|
|
|
|
|
using Xunit; |
|
|
|
using Xunit.Abstractions; |
|
|
|
|
|
|
|
public partial class ReferenceImplementationsTests |
|
|
|
{ |
|
|
|
public class FastFloatingPointDCT |
|
|
|
public class FastFloatingPointDCT : JpegUtilityTestFixture |
|
|
|
{ |
|
|
|
public FastFloatingPointDCT(ITestOutputHelper output) |
|
|
|
: base(output) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(42, 0)] |
|
|
|
[InlineData(1, 0)] |
|
|
|
[InlineData(2, 0)] |
|
|
|
public void ForwardThenInverse(int seed, int startAt) |
|
|
|
{ |
|
|
|
int[] data = JpegUtilityTestFixture.Create8x8RandomIntData(-200, 200, seed); |
|
|
|
int[] data = JpegUtilityTestFixture.Create8x8RandomIntData(-1000, 1000, seed); |
|
|
|
float[] src = data.ConvertAllToFloat(); |
|
|
|
float[] dest = new float[64]; |
|
|
|
float[] temp = new float[64]; |
|
|
|
@ -25,13 +32,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
ReferenceImplementations.FastFloatingPointDCT.fDCT2D_llm(src, dest, temp, true); |
|
|
|
ReferenceImplementations.FastFloatingPointDCT.iDCT2D_llm(dest, src, temp); |
|
|
|
|
|
|
|
for (int i = startAt; i < 64; i++) |
|
|
|
{ |
|
|
|
float expected = data[i]; |
|
|
|
float actual = (float)src[i]; |
|
|
|
|
|
|
|
Assert.Equal(expected, actual, new ApproximateFloatComparer(2f)); |
|
|
|
} |
|
|
|
this.CompareBlocks(data.ConvertAllToFloat(), src, 2f); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
@ -40,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
[InlineData(2)] |
|
|
|
public void IDCT_IsEquivalentTo_StandardIntegerImplementation(int seed) |
|
|
|
{ |
|
|
|
int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-200, 200, seed); |
|
|
|
int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-1000, 1000, seed); |
|
|
|
Span<float> floatSrc = intData.ConvertAllToFloat(); |
|
|
|
|
|
|
|
ReferenceImplementations.StandardIntegerDCT.TransformIDCTInplace(intData); |
|
|
|
@ -50,13 +51,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
|
|
ReferenceImplementations.FastFloatingPointDCT.iDCT2D_llm(floatSrc, dest, temp); |
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
{ |
|
|
|
float expected = intData[i]; |
|
|
|
float actual = dest[i]; |
|
|
|
|
|
|
|
Assert.Equal(expected, actual, new ApproximateFloatComparer(1f)); |
|
|
|
} |
|
|
|
this.CompareBlocks(intData.ConvertAllToFloat(), dest, 1f); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
@ -65,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
[InlineData(2)] |
|
|
|
public void IDCT_IsEquivalentTo_AccurateImplementation(int seed) |
|
|
|
{ |
|
|
|
int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-200, 200, seed); |
|
|
|
int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-1000, 1000, seed); |
|
|
|
float[] floatSrc = intData.ConvertAllToFloat(); |
|
|
|
|
|
|
|
ReferenceImplementations.AccurateDCT.TransformIDCTInplace(intData); |
|
|
|
@ -75,13 +70,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
|
|
ReferenceImplementations.FastFloatingPointDCT.iDCT2D_llm(floatSrc, dest, temp); |
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
{ |
|
|
|
float expected = intData[i]; |
|
|
|
float actual = dest[i]; |
|
|
|
|
|
|
|
Assert.Equal(expected, actual, new ApproximateFloatComparer(1f)); |
|
|
|
} |
|
|
|
this.CompareBlocks(intData.ConvertAllToFloat(), dest, 1f); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
@ -90,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
[InlineData(2)] |
|
|
|
public void FDCT_IsEquivalentTo_StandardIntegerImplementation(int seed) |
|
|
|
{ |
|
|
|
int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-200, 200, seed); |
|
|
|
int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-1000, 1000, seed); |
|
|
|
float[] floatSrc = intData.ConvertAllToFloat(); |
|
|
|
|
|
|
|
ReferenceImplementations.StandardIntegerDCT.TransformFDCTInplace(intData); |
|
|
|
@ -100,14 +89,39 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
|
|
ReferenceImplementations.FastFloatingPointDCT.fDCT2D_llm(floatSrc, dest, temp, offsetSourceByNeg128: true); |
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) |
|
|
|
{ |
|
|
|
float expected = intData[i]; |
|
|
|
float actual = dest[i]; |
|
|
|
this.CompareBlocks(intData.ConvertAllToFloat(), dest, 2f); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[InlineData(42)] |
|
|
|
[InlineData(1)] |
|
|
|
[InlineData(2)] |
|
|
|
public void FDCT_IsEquivalentTo_AccurateImplementation(int seed) |
|
|
|
{ |
|
|
|
float[] floatData = JpegUtilityTestFixture.Create8x8RandomFloatData(-1000, 1000); |
|
|
|
|
|
|
|
Block8x8F source = default(Block8x8F); |
|
|
|
source.LoadFrom(floatData); |
|
|
|
|
|
|
|
Block8x8F expected = ReferenceImplementations.AccurateDCT.TransformFDCT(ref source); |
|
|
|
Block8x8F actual = ReferenceImplementations.FastFloatingPointDCT.TransformFDCT(ref source); |
|
|
|
|
|
|
|
this.CompareBlocks(expected, actual, 1f); |
|
|
|
|
|
|
|
//int[] intData = JpegUtilityTestFixture.Create8x8RandomIntData(-1000, 1000, seed);
|
|
|
|
//float[] floatSrc = intData.ConvertAllToFloat();
|
|
|
|
|
|
|
|
Assert.Equal(expected, actual, new ApproximateFloatComparer(1f)); |
|
|
|
} |
|
|
|
//ReferenceImplementations.AccurateDCT.TransformFDCTInplace(intData);
|
|
|
|
|
|
|
|
//float[] dest = new float[64];
|
|
|
|
//float[] temp = new float[64];
|
|
|
|
|
|
|
|
//ReferenceImplementations.FastFloatingPointDCT.fDCT2D_llm(floatSrc, dest, temp, offsetSourceByNeg128: false);
|
|
|
|
|
|
|
|
//this.CompareBlocks(intData.ConvertAllToFloat(), dest, 1f);
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |