Move all texture loading functionalities from IM to TM

This commit is contained in:
Soreepeong 2024-02-22 17:57:24 +09:00
parent 248c7911a0
commit 71b84bcf40
12 changed files with 230 additions and 298 deletions

View file

@ -302,17 +302,17 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
var buf = Array.Empty<byte>();
try
{
var im = (await Service<InterfaceManager.InterfaceManagerWithScene>.GetAsync()).Manager;
var tm = await Service<TextureManager>.GetAsync();
await using var stream = await this.CreateStreamAsync(asset);
var length = checked((int)stream.Length);
buf = ArrayPool<byte>.Shared.Rent(length);
stream.ReadExactly(buf, 0, length);
var image = purpose switch
{
DalamudAssetPurpose.TextureFromPng => im.LoadImage(buf),
DalamudAssetPurpose.TextureFromPng => await tm.GetFromImageAsync(buf),
DalamudAssetPurpose.TextureFromRaw =>
asset.GetAttribute<DalamudAssetRawTextureAttribute>() is { } raw
? im.LoadImageFromDxgiFormat(buf, raw.Pitch, raw.Width, raw.Height, raw.Format)
? await tm.GetFromRawAsync(raw.Specification, buf)
: throw new InvalidOperationException(
"TextureFromRaw must accompany a DalamudAssetRawTextureAttribute."),
_ => null,

View file

@ -1,4 +1,6 @@
using SharpDX.DXGI;
using Dalamud.Plugin.Services;
using SharpDX.DXGI;
namespace Dalamud.Storage.Assets;
@ -17,29 +19,11 @@ internal class DalamudAssetRawTextureAttribute : Attribute
/// <param name="format">The format.</param>
public DalamudAssetRawTextureAttribute(int width, int pitch, int height, Format format)
{
this.Width = width;
this.Pitch = pitch;
this.Height = height;
this.Format = format;
this.Specification = new(width, height, pitch, (int)format);
}
/// <summary>
/// Gets the width.
/// Gets the specification.
/// </summary>
public int Width { get; }
/// <summary>
/// Gets the pitch.
/// </summary>
public int Pitch { get; }
/// <summary>
/// Gets the height.
/// </summary>
public int Height { get; }
/// <summary>
/// Gets the format.
/// </summary>
public Format Format { get; }
public RawImageSpecification Specification { get; }
}