mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
68 lines
2.7 KiB
C#
68 lines
2.7 KiB
C#
using System.Threading.Tasks;
|
|
using Wabbajack.Common;
|
|
using Xunit;
|
|
|
|
namespace Wabbajack.ImageHashing.Test
|
|
{
|
|
public class ImageLoadingTests
|
|
{
|
|
[Fact]
|
|
public async Task CanLoadAndCompareDDSImages()
|
|
{
|
|
var hash1 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
|
|
var state1 = await ImageState.GetState(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
|
|
|
|
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==");
|
|
|
|
|
|
Assert.Equal(1, hash1.Similarity(hash2));
|
|
Assert.True(hash1.Similarity(hash3) > 0.99f);
|
|
}
|
|
|
|
[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"));
|
|
|
|
Assert.Equal(64, state2!.Width);
|
|
Assert.Equal(64, state2!.Height);
|
|
Assert.Equal(DXGI_FORMAT.BC7_UNORM_SRGB, state2.Format);
|
|
|
|
Assert.True(hash1.Similarity(hash2) >= 0.8811f);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public async Task CanLoadAndCompareResizedVFlipImage()
|
|
{
|
|
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-vflip.dds"));
|
|
|
|
Assert.True(hash1.Similarity(hash2) >= 0.1948f);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CanLoadAndCompareRecompressedImage()
|
|
{
|
|
var hash1 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
|
|
|
|
var hash2 = await ImageState.GetPHash(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5-recompressed.dds"));
|
|
|
|
Assert.True(hash1.Similarity(hash2) >= 0.92f);
|
|
}
|
|
}
|
|
}
|