mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add some quick convert buttons to texture editing.
This commit is contained in:
parent
8436455936
commit
d42a105687
3 changed files with 62 additions and 7 deletions
|
|
@ -4,7 +4,6 @@ using System.Numerics;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using Lumina.Data.Files;
|
using Lumina.Data.Files;
|
||||||
using OtterTex;
|
using OtterTex;
|
||||||
using Penumbra.Services;
|
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Formats.Png;
|
using SixLabors.ImageSharp.Formats.Png;
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
|
@ -41,6 +40,9 @@ public partial class CombinedTexture : IDisposable
|
||||||
|
|
||||||
public bool IsLoaded
|
public bool IsLoaded
|
||||||
=> _mode != Mode.Empty;
|
=> _mode != Mode.Empty;
|
||||||
|
|
||||||
|
public bool IsLeftCopy
|
||||||
|
=> _mode == Mode.LeftCopy;
|
||||||
|
|
||||||
public Exception? SaveException { get; private set; } = null;
|
public Exception? SaveException { get; private set; } = null;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,22 @@ public sealed class Texture : IDisposable
|
||||||
public bool IsLoaded
|
public bool IsLoaded
|
||||||
=> TextureWrap != null;
|
=> 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)
|
public void Draw(Vector2 size)
|
||||||
{
|
{
|
||||||
if (TextureWrap != null)
|
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)
|
private bool LoadDds(DalamudServices dalamud)
|
||||||
{
|
{
|
||||||
Type = FileType.Dds;
|
Type = FileType.Dds;
|
||||||
|
|
@ -180,7 +203,7 @@ public sealed class Texture : IDisposable
|
||||||
using var stream = OpenTexStream(dalamud.GameData);
|
using var stream = OpenTexStream(dalamud.GameData);
|
||||||
var scratch = TexFileParser.Parse(stream);
|
var scratch = TexFileParser.Parse(stream);
|
||||||
BaseImage = scratch;
|
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();
|
RGBAPixels = rgba.Pixels[..(f.Meta.Width * f.Meta.Height * (f.Meta.Format.BitsPerPixel() / 8))].ToArray();
|
||||||
CreateTextureWrap(dalamud.UiBuilder, scratch.Meta.Width, scratch.Meta.Height);
|
CreateTextureWrap(dalamud.UiBuilder, scratch.Meta.Width, scratch.Meta.Height);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -268,10 +291,6 @@ public sealed class Texture : IDisposable
|
||||||
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Recycle.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
|
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Recycle.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
|
||||||
"Reload the currently selected path.", false,
|
"Reload the currently selected path.", false,
|
||||||
true))
|
true))
|
||||||
{
|
Reload(dalamud);
|
||||||
var path = Path;
|
|
||||||
Path = string.Empty;
|
|
||||||
Load(dalamud, path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System.Numerics;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using OtterGui;
|
using OtterGui;
|
||||||
using OtterGui.Raii;
|
using OtterGui.Raii;
|
||||||
|
using OtterTex;
|
||||||
using Penumbra.Import.Textures;
|
using Penumbra.Import.Textures;
|
||||||
|
|
||||||
namespace Penumbra.UI.AdvancedWindow;
|
namespace Penumbra.UI.AdvancedWindow;
|
||||||
|
|
@ -133,6 +134,39 @@ public partial class ModEditWindow
|
||||||
_forceTextureStartPath = false;
|
_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();
|
ImGui.NewLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue