mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Small cleanup, auto-formatting.
This commit is contained in:
parent
42b874413d
commit
87c5164367
3 changed files with 205 additions and 214 deletions
|
|
@ -66,7 +66,9 @@ public partial class CombinedTexture
|
|||
private const float GWeight = 0.7152f;
|
||||
private const float BWeight = 0.0722f;
|
||||
|
||||
private static readonly IReadOnlyList<(string Label, Matrix4x4 Multiplier, Vector4 Constant)> PredefinedColorTransforms = new (string, Matrix4x4, Vector4)[]
|
||||
// @formatter:off
|
||||
private static readonly IReadOnlyList<(string Label, Matrix4x4 Multiplier, Vector4 Constant)> PredefinedColorTransforms =
|
||||
new[]
|
||||
{
|
||||
("No Transform (Identity)", Matrix4x4.Identity, Vector4.Zero ),
|
||||
("Grayscale (Average)", new Matrix4x4(OneThird, OneThird, OneThird, 0.0f, OneThird, OneThird, OneThird, 0.0f, OneThird, OneThird, OneThird, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f), Vector4.Zero ),
|
||||
|
|
@ -78,6 +80,7 @@ public partial class CombinedTexture
|
|||
("Extract Blue", new Matrix4x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), Vector4.UnitW ),
|
||||
("Extract Alpha", new Matrix4x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f), Vector4.UnitW ),
|
||||
};
|
||||
// @formatter:on
|
||||
|
||||
private CombineOp GetActualCombineOp()
|
||||
{
|
||||
|
|
@ -99,8 +102,8 @@ public partial class CombinedTexture
|
|||
|
||||
return combineOp switch
|
||||
{
|
||||
CombineOp.LeftMultiply => (_multiplierLeft.IsIdentity && _constantLeft == Vector4.Zero) ? CombineOp.LeftCopy : CombineOp.LeftMultiply,
|
||||
CombineOp.RightMultiply => (_multiplierRight.IsIdentity && _constantRight == Vector4.Zero) ? CombineOp.RightCopy : CombineOp.RightMultiply,
|
||||
CombineOp.LeftMultiply when _multiplierLeft.IsIdentity && _constantLeft == Vector4.Zero => CombineOp.LeftCopy,
|
||||
CombineOp.RightMultiply when _multiplierRight.IsIdentity && _constantRight == Vector4.Zero => CombineOp.RightCopy,
|
||||
_ => combineOp,
|
||||
};
|
||||
}
|
||||
|
|
@ -116,9 +119,7 @@ public partial class CombinedTexture
|
|||
x += _offsetX;
|
||||
y += _offsetY;
|
||||
if (x < 0 || x >= _right.TextureWrap!.Width || y < 0 || y >= _right.TextureWrap!.Height)
|
||||
{
|
||||
return Vector4.Zero;
|
||||
}
|
||||
|
||||
var offset = (y * _right.TextureWrap!.Width + x) * 4;
|
||||
return CappedVector(_right.RgbaPixels, offset, _multiplierRight, _constantRight);
|
||||
|
|
@ -228,12 +229,11 @@ public partial class CombinedTexture
|
|||
|
||||
return (width, height);
|
||||
}
|
||||
|
||||
private static Vector4 CappedVector(IReadOnlyList<byte> bytes, int offset, Matrix4x4 transform, Vector4 constant)
|
||||
{
|
||||
if (bytes.Count == 0)
|
||||
{
|
||||
return Vector4.Zero;
|
||||
}
|
||||
|
||||
var rgba = new Rgba32(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);
|
||||
var transformed = Vector4.Transform(rgba.ToVector4(), transform) + constant;
|
||||
|
|
@ -251,9 +251,7 @@ public partial class CombinedTexture
|
|||
ImGui.TableNextColumn();
|
||||
ImGui.SetNextItemWidth(width);
|
||||
if (ImGui.DragFloat(label, ref tmp, 0.001f, -1f, 1f))
|
||||
{
|
||||
value = tmp;
|
||||
}
|
||||
|
||||
return ImGui.IsItemDeactivatedAfterEdit();
|
||||
}
|
||||
|
|
@ -263,10 +261,8 @@ public partial class CombinedTexture
|
|||
var ret = DrawMatrixInput(ref _multiplierLeft, ref _constantLeft, width);
|
||||
ret |= DrawMatrixTools(ref _multiplierLeft, ref _constantLeft);
|
||||
if (ret)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawMatrixInputRight(float width)
|
||||
{
|
||||
|
|
@ -283,7 +279,6 @@ public partial class CombinedTexture
|
|||
using (var c = ImRaii.Combo("Combine Operation", CombineOpLabels[(int)_combineOp]))
|
||||
{
|
||||
if (c)
|
||||
{
|
||||
foreach (var op in Enum.GetValues<CombineOp>())
|
||||
{
|
||||
if ((int)op < 0) // Negative codes are for internal use only.
|
||||
|
|
@ -298,7 +293,7 @@ public partial class CombinedTexture
|
|||
ImGuiUtil.SelectableHelpMarker(CombineOpTooltips[(int)op]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var dis = ImRaii.Disabled(_combineOp != CombineOp.CopyChannels))
|
||||
{
|
||||
ImGui.TextUnformatted("Copy");
|
||||
|
|
@ -308,24 +303,21 @@ public partial class CombinedTexture
|
|||
var copy = (_copyChannels & channel) != 0;
|
||||
if (ImGui.Checkbox(channel.ToString(), ref copy))
|
||||
{
|
||||
_copyChannels = copy ? ( _copyChannels | channel ) : ( _copyChannels & ~channel );
|
||||
_copyChannels = copy ? _copyChannels | channel : _copyChannels & ~channel;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool DrawMatrixInput(ref Matrix4x4 multiplier, ref Vector4 constant, float width)
|
||||
{
|
||||
using var table = ImRaii.Table(string.Empty, 5, ImGuiTableFlags.BordersInner | ImGuiTableFlags.SizingFixedFit);
|
||||
if (!table)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var changes = false;
|
||||
|
||||
|
|
@ -390,7 +382,6 @@ public partial class CombinedTexture
|
|||
using (var combo = ImRaii.Combo("Presets", string.Empty, ImGuiComboFlags.NoPreview))
|
||||
{
|
||||
if (combo)
|
||||
{
|
||||
foreach (var (label, preMultiplier, preConstant) in PredefinedColorTransforms)
|
||||
{
|
||||
if (ImGui.Selectable(label, multiplier == preMultiplier && constant == preConstant))
|
||||
|
|
@ -401,7 +392,6 @@ public partial class CombinedTexture
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.Dummy(ImGuiHelpers.ScaledVector2(20, 0));
|
||||
|
|
@ -415,24 +405,28 @@ public partial class CombinedTexture
|
|||
InvertBlue(ref multiplier, ref constant);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("R"))
|
||||
{
|
||||
InvertRed(ref multiplier, ref constant);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("G"))
|
||||
{
|
||||
InvertGreen(ref multiplier, ref constant);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("B"))
|
||||
{
|
||||
InvertBlue(ref multiplier, ref constant);
|
||||
changes = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("A"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -71,19 +71,14 @@ public partial class CombinedTexture : IDisposable
|
|||
|
||||
public void SaveAs(TextureType? texType, TextureManager textures, string path, TextureSaveType type, bool mipMaps)
|
||||
{
|
||||
TextureType finalTexType;
|
||||
if (texType.HasValue)
|
||||
finalTexType = texType.Value;
|
||||
else
|
||||
{
|
||||
finalTexType = Path.GetExtension(path).ToLowerInvariant() switch
|
||||
var finalTexType = texType
|
||||
?? Path.GetExtension(path).ToLowerInvariant() switch
|
||||
{
|
||||
".tex" => TextureType.Tex,
|
||||
".dds" => TextureType.Dds,
|
||||
".png" => TextureType.Png,
|
||||
_ => TextureType.Unknown,
|
||||
};
|
||||
}
|
||||
|
||||
switch (finalTexType)
|
||||
{
|
||||
|
|
@ -97,7 +92,8 @@ public partial class CombinedTexture : IDisposable
|
|||
SaveAsPng(textures, path);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Cannot save texture as TextureType {finalTexType} with extension {Path.GetExtension(path).ToLowerInvariant()}");
|
||||
throw new ArgumentException(
|
||||
$"Cannot save texture as TextureType {finalTexType} with extension {Path.GetExtension(path).ToLowerInvariant()}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,8 +128,7 @@ public partial class CombinedTexture : IDisposable
|
|||
Clean();
|
||||
switch (GetActualCombineOp())
|
||||
{
|
||||
case CombineOp.Invalid:
|
||||
break;
|
||||
case CombineOp.Invalid: break;
|
||||
case CombineOp.LeftCopy:
|
||||
_mode = Mode.LeftCopy;
|
||||
_current = _left;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,8 @@ public partial class ModEditWindow
|
|||
if (ImGui.Button("Save as TEX, DDS or PNG", buttonSize2))
|
||||
{
|
||||
var fileName = Path.GetFileNameWithoutExtension(_left.Path.Length > 0 ? _left.Path : _right.Path);
|
||||
_fileDialog.OpenSavePicker("Save Texture as TEX, DDS or PNG...", "Textures{.png,.dds,.tex},.tex,.dds,.png", fileName, ".tex", (a, b) =>
|
||||
_fileDialog.OpenSavePicker("Save Texture as TEX, DDS or PNG...", "Textures{.png,.dds,.tex},.tex,.dds,.png", fileName, ".tex",
|
||||
(a, b) =>
|
||||
{
|
||||
if (a)
|
||||
{
|
||||
|
|
@ -169,7 +170,8 @@ public partial class ModEditWindow
|
|||
ImGui.SameLine();
|
||||
if (ImGuiUtil.DrawDisabledButton("Convert to RGBA", buttonSize3,
|
||||
"This converts the texture to RGBA format in place. This is not revertible.",
|
||||
!canConvertInPlace || _left.Format is DXGIFormat.B8G8R8A8UNorm or DXGIFormat.B8G8R8A8Typeless or DXGIFormat.B8G8R8A8UNormSRGB))
|
||||
!canConvertInPlace
|
||||
|| _left.Format is DXGIFormat.B8G8R8A8UNorm or DXGIFormat.B8G8R8A8Typeless or DXGIFormat.B8G8R8A8UNormSRGB))
|
||||
{
|
||||
_center.SaveAsTex(_textures, _left.Path, CombinedTexture.TextureSaveType.Bitmap, _left.MipMaps > 1);
|
||||
AddReloadTask(_left.Path, false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue