wabbajack/Wabbajack.ImageHashing.Test/ImageLoadingTests.cs

68 lines
2.7 KiB
C#
Raw Normal View History

2021-06-15 03:39:17 +00:00
using System.Threading.Tasks;
using Wabbajack.Common;
using Xunit;
namespace Wabbajack.ImageHashing.Test
{
public class ImageLoadingTests
{
[Fact]
2021-06-16 05:16:25 +00:00
public async Task CanLoadAndCompareDDSImages()
2021-06-15 03:39:17 +00:00
{
var hash1 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
var state1 = await ImageState.GetState(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
2021-07-11 22:54:06 +00:00
Assert.Equal(512, state1!.Width);
Assert.Equal(512, state1!.Height);
Assert.Equal(DXGI_FORMAT.BC3_UNORM, state1.Format);
var hash2 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
// From old embedded hashing method, we want to make sure the hashing algorithm hasn't changed so much that
// we've broken the old caches
var hash3 = PHash.FromBase64("cns+/2xel0ulcwCXeTlVW2x5aGtwaGl9glpthWZkb2ducnF0c2lvgQ==");
2021-06-16 05:16:25 +00:00
Assert.Equal(1, hash1.Similarity(hash2));
Assert.True(hash1.Similarity(hash3) > 0.99f);
2021-06-16 05:16:25 +00:00
}
[Fact]
public async Task CanLoadAndCompareResizedImage()
{
var hash1 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
var hash2 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5-small-bc7.dds"));
var state2 = await ImageState.GetState(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5-small-bc7.dds"));
2021-06-16 05:16:25 +00:00
2021-07-11 22:54:06 +00:00
Assert.Equal(64, state2!.Width);
Assert.Equal(64, state2!.Height);
Assert.Equal(DXGI_FORMAT.BC7_UNORM_SRGB, state2.Format);
2021-06-16 05:16:25 +00:00
2021-07-11 20:33:36 +00:00
Assert.True(hash1.Similarity(hash2) >= 0.8811f);
2021-06-16 05:16:25 +00:00
}
[Fact]
public async Task CanLoadAndCompareResizedVFlipImage()
{
var hash1 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
2021-06-16 05:16:25 +00:00
var hash2 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5-small-bc7-vflip.dds"));
2021-06-16 05:16:25 +00:00
2021-07-11 20:33:36 +00:00
Assert.True(hash1.Similarity(hash2) >= 0.1948f);
2021-06-16 05:16:25 +00:00
}
[Fact]
public async Task CanLoadAndCompareRecompressedImage()
{
var hash1 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
2021-06-16 05:16:25 +00:00
var hash2 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5-recompressed.dds"));
2021-06-16 05:16:25 +00:00
2021-07-11 20:33:36 +00:00
Assert.True(hash1.Similarity(hash2) >= 0.92f);
2021-06-15 03:39:17 +00:00
}
}
}