Fix texture recompression tests

This commit is contained in:
Timothy Baldridge 2021-07-17 04:21:26 -06:00
parent 51764ae619
commit 0c53a1480c
2 changed files with 11 additions and 5 deletions

View File

@ -51,6 +51,9 @@ namespace Wabbajack.ImageHashing
private static readonly Extension PNGExtension = new(".png");
public static async Task<PHash> GetPHash(AbsolutePath path)
{
if (!path.Exists)
throw new FileNotFoundException($"Can't hash non-existent file {path}");
await using var tmp = await TempFolder.Create();
await ConvertImage(path, tmp.Dir, 512, 512, DXGI_FORMAT.R8G8B8A8_UNORM, PNGExtension);
@ -75,7 +78,7 @@ namespace Wabbajack.ImageHashing
public static async Task ConvertImage(Stream from, ImageState state, Extension ext, AbsolutePath to)
{
await using var tmpFile = await TempFolder.Create();
var inFile = to.FileName.RelativeTo(tmpFile.Dir).WithExtension(ext);
var inFile = to.FileName.RelativeTo(tmpFile.Dir);
await inFile.WriteAllAsync(from);
await ConvertImage(inFile, to.Parent, state.Width, state.Height, state.Format, ext);
}

View File

@ -387,15 +387,18 @@ namespace Wabbajack.Test
{
var originalDDS = await ImageState.GetState(nativeFile);
await ImageState.ConvertImage(nativeFile, recompressedFile.Parent, originalDDS.Width, originalDDS.Height, DXGI_FORMAT.BC7_UNORM, recompressedFile.Extension);
await ImageState.ConvertImage(nativeFile, resizedFile.Parent, 128, 128, DXGI_FORMAT.BC7_UNORM, resizedFile.Extension);
await ImageState.ConvertImage(nativeFile, resizedFile.Parent, 1024, 1024, DXGI_FORMAT.BC7_UNORM, resizedFile.Extension);
}
await utils.Configure();
await CompileAndInstall(profile, true);
var compilerData = await CompileAndInstall(profile, true);
await utils.VerifyInstalledFile(mod, @"native\whitestagbody.dds");
Assert.True(0.99f <=(await ImageState.GetState(recompressedFile)).PerceptualHash.Similarity(await ImageState.GetPHash(utils.InstalledPath(mod, @"recompressed\whitestagbody.dds"))));
Assert.True(0.98f <=(await ImageState.GetState(resizedFile)).PerceptualHash.Similarity(await ImageState.GetPHash(utils.InstalledPath(mod, @"resized\whitestagbody.dds"))));
var directies = compilerData.Directives;
Assert.True(0.99f <= (await ImageState.GetState(recompressedFile)).PerceptualHash.Similarity(await ImageState.GetPHash(utils.InstalledPath(mod, @"recompressed\whitestagbody.dds"))));
Assert.True(0.98f <= (await ImageState.GetState(resizedFile)).PerceptualHash.Similarity(await ImageState.GetPHash(utils.InstalledPath(mod, @"resized\whitestagbody.dds"))));
}
[Fact]