Add some quick convert buttons to texture editing.

This commit is contained in:
Ottermandias 2023-06-17 01:20:59 +02:00
parent 8436455936
commit d42a105687
3 changed files with 62 additions and 7 deletions

View file

@ -4,7 +4,6 @@ using System.Numerics;
using Dalamud.Interface;
using Lumina.Data.Files;
using OtterTex;
using Penumbra.Services;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
@ -41,6 +40,9 @@ public partial class CombinedTexture : IDisposable
public bool IsLoaded
=> _mode != Mode.Empty;
public bool IsLeftCopy
=> _mode == Mode.LeftCopy;
public Exception? SaveException { get; private set; } = null;

View file

@ -54,6 +54,22 @@ public sealed class Texture : IDisposable
public bool IsLoaded
=> TextureWrap != null;
public DXGIFormat Format
=> BaseImage switch
{
ScratchImage s => s.Meta.Format,
TexFile t => t.Header.Format.ToDXGI(),
_ => DXGIFormat.Unknown,
};
public int MipMaps
=> BaseImage switch
{
ScratchImage s => s.Meta.MipLevels,
TexFile t => t.Header.MipLevels,
_ => 1,
};
public void Draw(Vector2 size)
{
if (TextureWrap != null)
@ -151,6 +167,13 @@ public sealed class Texture : IDisposable
}
}
public void Reload(DalamudServices dalamud)
{
var path = Path;
Path = string.Empty;
Load(dalamud, path);
}
private bool LoadDds(DalamudServices dalamud)
{
Type = FileType.Dds;
@ -180,7 +203,7 @@ public sealed class Texture : IDisposable
using var stream = OpenTexStream(dalamud.GameData);
var scratch = TexFileParser.Parse(stream);
BaseImage = scratch;
var rgba = scratch.GetRGBA(out var f).ThrowIfError(f);
var rgba = scratch.GetRGBA(out var f).ThrowIfError(f);
RGBAPixels = rgba.Pixels[..(f.Meta.Width * f.Meta.Height * (f.Meta.Format.BitsPerPixel() / 8))].ToArray();
CreateTextureWrap(dalamud.UiBuilder, scratch.Meta.Width, scratch.Meta.Height);
return true;
@ -268,10 +291,6 @@ public sealed class Texture : IDisposable
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Recycle.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
"Reload the currently selected path.", false,
true))
{
var path = Path;
Path = string.Empty;
Load(dalamud, path);
}
Reload(dalamud);
}
}

View file

@ -5,6 +5,7 @@ using System.Numerics;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterTex;
using Penumbra.Import.Textures;
namespace Penumbra.UI.AdvancedWindow;
@ -133,6 +134,39 @@ public partial class ModEditWindow
_forceTextureStartPath = false;
}
if (_left.Type is Texture.FileType.Tex && _center.IsLeftCopy)
{
var buttonSize = new Vector2((ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemSpacing.X * 2) / 3, 0);
if (ImGuiUtil.DrawDisabledButton("Convert to BC7", buttonSize,
"This converts the texture to BC7 format in place. This is not revertible.",
_left.Format is DXGIFormat.BC7Typeless or DXGIFormat.BC7UNorm or DXGIFormat.BC7UNormSRGB))
{
_center.SaveAsTex(_left.Path, CombinedTexture.TextureSaveType.BC7, _left.MipMaps > 1);
_left.Reload(_dalamud);
}
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Convert to BC3", buttonSize,
"This converts the texture to BC3 format in place. This is not revertible.",
_left.Format is DXGIFormat.BC3Typeless or DXGIFormat.BC3UNorm or DXGIFormat.BC3UNormSRGB))
{
_center.SaveAsTex(_left.Path, CombinedTexture.TextureSaveType.BC3, _left.MipMaps > 1);
_left.Reload(_dalamud);
}
ImGui.SameLine();
if (ImGuiUtil.DrawDisabledButton("Convert to RGBA", buttonSize,
"This converts the texture to RGBA format in place. This is not revertible.",
_left.Format is DXGIFormat.B8G8R8A8UNorm or DXGIFormat.B8G8R8A8Typeless or DXGIFormat.B8G8R8A8UNormSRGB))
{
_center.SaveAsTex(_left.Path, CombinedTexture.TextureSaveType.Bitmap, _left.MipMaps > 1);
_left.Reload(_dalamud);
}
}
else
{
ImGui.NewLine();
}
ImGui.NewLine();
}