Add ITextureProvider.GetFromManifestResource(Assembly,string)

This commit is contained in:
Soreepeong 2024-02-28 21:04:57 +09:00
parent b52d4724e9
commit cc756c243c
5 changed files with 327 additions and 35 deletions

View file

@ -1,3 +1,7 @@
using System.Runtime.CompilerServices;
using Dalamud.Memory;
using ImGuiScene;
using Lumina.Data.Files;
@ -28,4 +32,25 @@ public static class TexFileExtensions
return dst;
}
/// <summary>Determines if the given data is possibly a <see cref="TexFile"/>.</summary>
/// <param name="data">The data.</param>
/// <returns><c>true</c> if it should be attempted to be interpreted as a <see cref="TexFile"/>.</returns>
internal static unsafe bool IsPossiblyTexFile2D(ReadOnlySpan<byte> data)
{
if (data.Length < Unsafe.SizeOf<TexFile.TexHeader>())
return false;
fixed (byte* ptr = data)
{
ref readonly var texHeader = ref MemoryHelper.Cast<TexFile.TexHeader>((nint)ptr);
if ((texHeader.Type & TexFile.Attribute.TextureTypeMask) != TexFile.Attribute.TextureType2D)
return false;
if (!Enum.IsDefined(texHeader.Format))
return false;
if (texHeader.Width == 0 || texHeader.Height == 0)
return false;
}
return true;
}
}