Skip to content

Commit d42a105

Browse files
committed
Add some quick convert buttons to texture editing.
1 parent 8436455 commit d42a105

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

Penumbra/Import/Textures/CombinedTexture.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Dalamud.Interface;
55
using Lumina.Data.Files;
66
using OtterTex;
7-
using Penumbra.Services;
87
using SixLabors.ImageSharp;
98
using SixLabors.ImageSharp.Formats.Png;
109
using SixLabors.ImageSharp.PixelFormats;
@@ -41,6 +40,9 @@ private enum Mode
4140

4241
public bool IsLoaded
4342
=> _mode != Mode.Empty;
43+
44+
public bool IsLeftCopy
45+
=> _mode == Mode.LeftCopy;
4446

4547
public Exception? SaveException { get; private set; } = null;
4648

Penumbra/Import/Textures/Texture.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ public enum FileType
5454
public bool IsLoaded
5555
=> TextureWrap != null;
5656

57+
public DXGIFormat Format
58+
=> BaseImage switch
59+
{
60+
ScratchImage s => s.Meta.Format,
61+
TexFile t => t.Header.Format.ToDXGI(),
62+
_ => DXGIFormat.Unknown,
63+
};
64+
65+
public int MipMaps
66+
=> BaseImage switch
67+
{
68+
ScratchImage s => s.Meta.MipLevels,
69+
TexFile t => t.Header.MipLevels,
70+
_ => 1,
71+
};
72+
5773
public void Draw(Vector2 size)
5874
{
5975
if (TextureWrap != null)
@@ -151,6 +167,13 @@ private void Load(DalamudServices dalamud, string path)
151167
}
152168
}
153169

170+
public void Reload(DalamudServices dalamud)
171+
{
172+
var path = Path;
173+
Path = string.Empty;
174+
Load(dalamud, path);
175+
}
176+
154177
private bool LoadDds(DalamudServices dalamud)
155178
{
156179
Type = FileType.Dds;
@@ -180,7 +203,7 @@ private bool LoadTex(DalamudServices dalamud)
180203
using var stream = OpenTexStream(dalamud.GameData);
181204
var scratch = TexFileParser.Parse(stream);
182205
BaseImage = scratch;
183-
var rgba = scratch.GetRGBA(out var f).ThrowIfError(f);
206+
var rgba = scratch.GetRGBA(out var f).ThrowIfError(f);
184207
RGBAPixels = rgba.Pixels[..(f.Meta.Width * f.Meta.Height * (f.Meta.Format.BitsPerPixel() / 8))].ToArray();
185208
CreateTextureWrap(dalamud.UiBuilder, scratch.Meta.Width, scratch.Meta.Height);
186209
return true;
@@ -268,10 +291,6 @@ void UpdatePath(bool success, List<string> paths)
268291
if (ImGuiUtil.DrawDisabledButton(FontAwesomeIcon.Recycle.ToIconString(), new Vector2(ImGui.GetFrameHeight()),
269292
"Reload the currently selected path.", false,
270293
true))
271-
{
272-
var path = Path;
273-
Path = string.Empty;
274-
Load(dalamud, path);
275-
}
294+
Reload(dalamud);
276295
}
277296
}

Penumbra/UI/AdvancedWindow/ModEditWindow.Textures.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using ImGuiNET;
66
using OtterGui;
77
using OtterGui.Raii;
8+
using OtterTex;
89
using Penumbra.Import.Textures;
910

1011
namespace Penumbra.UI.AdvancedWindow;
@@ -133,6 +134,39 @@ private void DrawOutputChild(Vector2 size, Vector2 imageSize)
133134
_forceTextureStartPath = false;
134135
}
135136

137+
if (_left.Type is Texture.FileType.Tex && _center.IsLeftCopy)
138+
{
139+
var buttonSize = new Vector2((ImGui.GetContentRegionAvail().X - ImGui.GetStyle().ItemSpacing.X * 2) / 3, 0);
140+
if (ImGuiUtil.DrawDisabledButton("Convert to BC7", buttonSize,
141+
"This converts the texture to BC7 format in place. This is not revertible.",
142+
_left.Format is DXGIFormat.BC7Typeless or DXGIFormat.BC7UNorm or DXGIFormat.BC7UNormSRGB))
143+
{
144+
_center.SaveAsTex(_left.Path, CombinedTexture.TextureSaveType.BC7, _left.MipMaps > 1);
145+
_left.Reload(_dalamud);
146+
}
147+
148+
ImGui.SameLine();
149+
if (ImGuiUtil.DrawDisabledButton("Convert to BC3", buttonSize,
150+
"This converts the texture to BC3 format in place. This is not revertible.",
151+
_left.Format is DXGIFormat.BC3Typeless or DXGIFormat.BC3UNorm or DXGIFormat.BC3UNormSRGB))
152+
{
153+
_center.SaveAsTex(_left.Path, CombinedTexture.TextureSaveType.BC3, _left.MipMaps > 1);
154+
_left.Reload(_dalamud);
155+
}
156+
157+
ImGui.SameLine();
158+
if (ImGuiUtil.DrawDisabledButton("Convert to RGBA", buttonSize,
159+
"This converts the texture to RGBA format in place. This is not revertible.",
160+
_left.Format is DXGIFormat.B8G8R8A8UNorm or DXGIFormat.B8G8R8A8Typeless or DXGIFormat.B8G8R8A8UNormSRGB))
161+
{
162+
_center.SaveAsTex(_left.Path, CombinedTexture.TextureSaveType.Bitmap, _left.MipMaps > 1);
163+
_left.Reload(_dalamud);
164+
}
165+
}
166+
else
167+
{
168+
ImGui.NewLine();
169+
}
136170
ImGui.NewLine();
137171
}
138172

0 commit comments

Comments
 (0)