mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Image hashing initial work
This commit is contained in:
parent
3dbdfa6121
commit
c9a2ea8180
15
Wabbajack.ImageHashing.Test/ImageLoadingTests.cs
Normal file
15
Wabbajack.ImageHashing.Test/ImageLoadingTests.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Xunit;
|
||||
|
||||
namespace Wabbajack.ImageHashing.Test
|
||||
{
|
||||
public class ImageLoadingTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CanLoadDDSFiles()
|
||||
{
|
||||
var file = DDSImage.FromFile(AbsolutePath.EntryPoint.Combine("Resources", "test-dxt5.dds"));
|
||||
}
|
||||
}
|
||||
}
|
BIN
Wabbajack.ImageHashing.Test/Resources/test-dxt5.dds
Normal file
BIN
Wabbajack.ImageHashing.Test/Resources/test-dxt5.dds
Normal file
Binary file not shown.
@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wabbajack.ImageHashing\Wabbajack.ImageHashing.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Resources\test-dxt5.dds">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
39
Wabbajack.ImageHashing/DDSImage.cs
Normal file
39
Wabbajack.ImageHashing/DDSImage.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using DirectXTexNet;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.ImageHashing
|
||||
{
|
||||
public class DDSImage : IImage
|
||||
{
|
||||
private DDSImage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static Extension DDSExtension = new(".dds");
|
||||
private ScratchImage _image;
|
||||
private TexMetadata _metaData;
|
||||
|
||||
public static DDSImage FromFile(AbsolutePath file)
|
||||
{
|
||||
if (file.Extension != DDSExtension)
|
||||
throw new Exception("File does not end in DDS");
|
||||
|
||||
var img = TexHelper.Instance.LoadFromDDSFile(file.ToString(), DDS_FLAGS.NONE);
|
||||
|
||||
return new DDSImage() {_image = img, _metaData = img.GetMetadata()};
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_image.IsDisposed)
|
||||
_image.Dispose();
|
||||
}
|
||||
|
||||
public int Width => _metaData.Width;
|
||||
public int Height => _metaData.Height;
|
||||
public GPUCompressionLevel CompressionLevel => GPUCompressionLevel.Uncompressed;
|
||||
public IImageState State { get; }
|
||||
}
|
||||
}
|
24
Wabbajack.ImageHashing/IImage.cs
Normal file
24
Wabbajack.ImageHashing/IImage.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace Wabbajack.ImageHashing
|
||||
{
|
||||
public interface IImage : IDisposable
|
||||
{
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
public GPUCompressionLevel CompressionLevel { get; }
|
||||
public IImageState State { get; }
|
||||
}
|
||||
|
||||
public interface IImageState
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public enum GPUCompressionLevel : int
|
||||
{
|
||||
Uncompressed = 0, // The Image is uncompressed on the GPU
|
||||
Old = 1, // The Image is compressed in a poor (old) format on the GPU
|
||||
New = 2 // The Image is compressed in a newer format (like BC7) on the GPU
|
||||
}
|
||||
}
|
16
Wabbajack.ImageHashing/Wabbajack.ImageHashing.csproj
Normal file
16
Wabbajack.ImageHashing/Wabbajack.ImageHashing.csproj
Normal file
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DirectXTexNet" Version="1.0.2" />
|
||||
<PackageReference Include="Magick.NET.Core" Version="7.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wabbajack.Common\Wabbajack.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -44,6 +44,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.Server", "Wabbaja
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wabbajack.Server.Test", "Wabbajack.Server.Test\Wabbajack.Server.Test.csproj", "{9DEC8DC8-B6E0-469B-9571-C4BAC0776D07}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.ImageHashing", "Wabbajack.ImageHashing\Wabbajack.ImageHashing.csproj", "{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.ImageHashing.Test", "Wabbajack.ImageHashing.Test\Wabbajack.ImageHashing.Test.csproj", "{96892D68-7400-4297-864C-39D0673775DE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -162,6 +166,22 @@ Global
|
||||
{9DEC8DC8-B6E0-469B-9571-C4BAC0776D07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9DEC8DC8-B6E0-469B-9571-C4BAC0776D07}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9DEC8DC8-B6E0-469B-9571-C4BAC0776D07}.Release|x64.Build.0 = Release|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{0C893E5F-1FD8-463E-AC3F-D020213ACD3B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{96892D68-7400-4297-864C-39D0673775DE}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user