mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +01:00
Remove font gamma configuration
This commit is contained in:
parent
701d006db8
commit
e86c5458a2
7 changed files with 15 additions and 94 deletions
|
|
@ -148,12 +148,9 @@ internal sealed class DalamudConfiguration : IServiceType, IDisposable
|
|||
public bool UseAxisFontsFromGame { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the gamma value to apply for Dalamud fonts. Effects text thickness.
|
||||
///
|
||||
/// Before gamma is applied...
|
||||
/// * ...TTF fonts loaded with stb or FreeType are in linear space.
|
||||
/// * ...the game's prebaked AXIS fonts are in gamma space with gamma value of 1.4.
|
||||
/// Gets or sets the gamma value to apply for Dalamud fonts. Do not use.
|
||||
/// </summary>
|
||||
[Obsolete("It happens that nobody touched this setting", true)]
|
||||
public float FontGammaLevel { get; set; } = 1.4f;
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -199,16 +199,6 @@ internal class InterfaceManager : IDisposable, IServiceType
|
|||
/// </summary>
|
||||
public bool UseAxis => this.UseAxisOverride ?? Service<DalamudConfiguration>.Get().UseAxisFontsFromGame;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the overrided font gamma value, instead of using the value from configuration.
|
||||
/// </summary>
|
||||
public float? FontGammaOverride { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the font gamma value to use.
|
||||
/// </summary>
|
||||
public float FontGamma => Math.Max(0.1f, this.FontGammaOverride.GetValueOrDefault(Service<DalamudConfiguration>.Get().FontGammaLevel));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating the native handle of the game main window.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -66,13 +66,9 @@ internal class SettingsWindow : Window
|
|||
var configuration = Service<DalamudConfiguration>.Get();
|
||||
var interfaceManager = Service<InterfaceManager>.Get();
|
||||
|
||||
var rebuildFont =
|
||||
ImGui.GetIO().FontGlobalScale != configuration.GlobalUiScale ||
|
||||
interfaceManager.FontGamma != configuration.FontGammaLevel ||
|
||||
interfaceManager.UseAxis != configuration.UseAxisFontsFromGame;
|
||||
var rebuildFont = interfaceManager.UseAxis != configuration.UseAxisFontsFromGame;
|
||||
|
||||
ImGui.GetIO().FontGlobalScale = configuration.GlobalUiScale;
|
||||
interfaceManager.FontGammaOverride = null;
|
||||
interfaceManager.UseAxisOverride = null;
|
||||
|
||||
if (rebuildFont)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ public class SettingsTabLook : SettingsTab
|
|||
};
|
||||
|
||||
private float globalUiScale;
|
||||
private float fontGamma;
|
||||
|
||||
public override SettingsEntry[] Entries { get; } =
|
||||
{
|
||||
|
|
@ -202,33 +201,12 @@ public class SettingsTabLook : SettingsTab
|
|||
}
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text(Loc.Localize("DalamudSettingsFontGamma", "Font Gamma"));
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button(Loc.Localize("DalamudSettingsIndividualConfigResetToDefaultValue", "Reset") + "##DalamudSettingsFontGammaReset"))
|
||||
{
|
||||
this.fontGamma = 1.4f;
|
||||
interfaceManager.FontGammaOverride = this.fontGamma;
|
||||
interfaceManager.RebuildFonts();
|
||||
}
|
||||
|
||||
if (ImGui.DragFloat("##DalamudSettingsFontGammaDrag", ref this.fontGamma, 0.005f, 0.3f, 3f, "%.2f", ImGuiSliderFlags.AlwaysClamp))
|
||||
{
|
||||
interfaceManager.FontGammaOverride = this.fontGamma;
|
||||
interfaceManager.RebuildFonts();
|
||||
}
|
||||
|
||||
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, Loc.Localize("DalamudSettingsFontGammaHint", "Changes the thickness of text."));
|
||||
|
||||
base.Draw();
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
this.globalUiScale = Service<DalamudConfiguration>.Get().GlobalUiScale;
|
||||
this.fontGamma = Service<DalamudConfiguration>.Get().FontGammaLevel;
|
||||
|
||||
base.Load();
|
||||
}
|
||||
|
|
@ -236,7 +214,6 @@ public class SettingsTabLook : SettingsTab
|
|||
public override void Save()
|
||||
{
|
||||
Service<DalamudConfiguration>.Get().GlobalUiScale = this.globalUiScale;
|
||||
Service<DalamudConfiguration>.Get().FontGammaLevel = this.fontGamma;
|
||||
|
||||
base.Save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -381,7 +381,6 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
public unsafe void PreBuild()
|
||||
{
|
||||
var gamma = this.factory.InterfaceManager.FontGamma;
|
||||
var configData = this.data.ConfigData;
|
||||
foreach (ref var config in configData.DataSpan)
|
||||
{
|
||||
|
|
@ -400,7 +399,7 @@ internal sealed partial class FontAtlasFactory
|
|||
|
||||
config.GlyphOffset *= this.Scale;
|
||||
|
||||
config.RasterizerGamma *= gamma;
|
||||
config.RasterizerGamma *= 1.4f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,6 @@ internal sealed partial class FontAtlasFactory
|
|||
private readonly Task<ushort[]> defaultGlyphRanges;
|
||||
private readonly DalamudAssetManager dalamudAssetManager;
|
||||
|
||||
private float lastBuildGamma = -1f;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private FontAtlasFactory(
|
||||
DataManager dataManager,
|
||||
|
|
@ -210,18 +208,10 @@ internal sealed partial class FontAtlasFactory
|
|||
{
|
||||
lock (this.prebakedTextureWraps[texPathFormat])
|
||||
{
|
||||
var gamma = this.InterfaceManager.FontGamma;
|
||||
var wraps = ExtractResult(this.prebakedTextureWraps[texPathFormat]);
|
||||
if (Math.Abs(this.lastBuildGamma - gamma) > 0.0001f)
|
||||
{
|
||||
this.lastBuildGamma = gamma;
|
||||
wraps.AggregateToDisposable().Dispose();
|
||||
wraps.AsSpan().Clear();
|
||||
}
|
||||
|
||||
var fileIndex = textureIndex / 4;
|
||||
var channelIndex = FdtReader.FontTableEntry.TextureChannelOrder[textureIndex % 4];
|
||||
wraps[textureIndex] ??= this.GetChannelTexture(texPathFormat, fileIndex, channelIndex, gamma);
|
||||
wraps[textureIndex] ??= this.GetChannelTexture(texPathFormat, fileIndex, channelIndex);
|
||||
return CloneTextureWrap(wraps[textureIndex]);
|
||||
}
|
||||
}
|
||||
|
|
@ -232,13 +222,9 @@ internal sealed partial class FontAtlasFactory
|
|||
Span<byte> target,
|
||||
ReadOnlySpan<byte> source,
|
||||
int channelIndex,
|
||||
bool targetIsB4G4R4A4,
|
||||
float gamma)
|
||||
bool targetIsB4G4R4A4)
|
||||
{
|
||||
var numPixels = Math.Min(source.Length / 4, target.Length / (targetIsB4G4R4A4 ? 2 : 4));
|
||||
var gammaTable = stackalloc byte[256];
|
||||
for (var i = 0; i < 256; i++)
|
||||
gammaTable[i] = (byte)(MathF.Pow(Math.Clamp(i / 255f, 0, 1), 1.4f / gamma) * 255);
|
||||
|
||||
fixed (byte* sourcePtrImmutable = source)
|
||||
{
|
||||
|
|
@ -250,7 +236,7 @@ internal sealed partial class FontAtlasFactory
|
|||
var wptr = (ushort*)targetPtr;
|
||||
while (numPixels-- > 0)
|
||||
{
|
||||
*wptr = (ushort)((gammaTable[*rptr] << 8) | 0x0FFF);
|
||||
*wptr = (ushort)((*rptr << 8) | 0x0FFF);
|
||||
wptr++;
|
||||
rptr += 4;
|
||||
}
|
||||
|
|
@ -260,7 +246,7 @@ internal sealed partial class FontAtlasFactory
|
|||
var wptr = (uint*)targetPtr;
|
||||
while (numPixels-- > 0)
|
||||
{
|
||||
*wptr = (uint)((gammaTable[*rptr] << 24) | 0x00FFFFFF);
|
||||
*wptr = (uint)((*rptr << 24) | 0x00FFFFFF);
|
||||
wptr++;
|
||||
rptr += 4;
|
||||
}
|
||||
|
|
@ -292,41 +278,33 @@ internal sealed partial class FontAtlasFactory
|
|||
Span<byte> target,
|
||||
ReadOnlySpan<byte> source,
|
||||
int channelIndex,
|
||||
bool targetIsB4G4R4A4,
|
||||
float gamma)
|
||||
bool targetIsB4G4R4A4)
|
||||
{
|
||||
var numPixels = Math.Min(source.Length / 2, target.Length / (targetIsB4G4R4A4 ? 2 : 4));
|
||||
fixed (byte* sourcePtrImmutable = source)
|
||||
{
|
||||
var rptr = sourcePtrImmutable + (channelIndex / 2);
|
||||
var rshift = (channelIndex & 1) == 0 ? 0 : 4;
|
||||
var gammaTable = stackalloc byte[256];
|
||||
fixed (void* targetPtr = target)
|
||||
{
|
||||
if (targetIsB4G4R4A4)
|
||||
{
|
||||
for (var i = 0; i < 16; i++)
|
||||
gammaTable[i] = (byte)(MathF.Pow(Math.Clamp(i / 15f, 0, 1), 1.4f / gamma) * 15);
|
||||
|
||||
var wptr = (ushort*)targetPtr;
|
||||
while (numPixels-- > 0)
|
||||
{
|
||||
*wptr = (ushort)((gammaTable[(*rptr >> rshift) & 0xF] << 12) | 0x0FFF);
|
||||
*wptr = (ushort)(((*rptr >> rshift) << 12) | 0x0FFF);
|
||||
wptr++;
|
||||
rptr += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = 0; i < 256; i++)
|
||||
gammaTable[i] = (byte)(MathF.Pow(Math.Clamp(i / 255f, 0, 1), 1.4f / gamma) * 255);
|
||||
|
||||
var wptr = (uint*)targetPtr;
|
||||
while (numPixels-- > 0)
|
||||
{
|
||||
var v = (*rptr >> rshift) & 0xF;
|
||||
v |= v << 4;
|
||||
*wptr = (uint)((gammaTable[v] << 24) | 0x00FFFFFF);
|
||||
*wptr = (uint)((v << 24) | 0x00FFFFFF);
|
||||
wptr++;
|
||||
rptr += 4;
|
||||
}
|
||||
|
|
@ -335,7 +313,7 @@ internal sealed partial class FontAtlasFactory
|
|||
}
|
||||
}
|
||||
|
||||
private IDalamudTextureWrap GetChannelTexture(string texPathFormat, int fileIndex, int channelIndex, float gamma)
|
||||
private IDalamudTextureWrap GetChannelTexture(string texPathFormat, int fileIndex, int channelIndex)
|
||||
{
|
||||
var texFile = ExtractResult(ExtractResult(this.texFiles[texPathFormat])[fileIndex]);
|
||||
var numPixels = texFile.Header.Width * texFile.Header.Height;
|
||||
|
|
@ -351,15 +329,15 @@ internal sealed partial class FontAtlasFactory
|
|||
{
|
||||
case TexFile.TextureFormat.B4G4R4A4:
|
||||
// Game ships with this format.
|
||||
ExtractChannelFromB4G4R4A4(buffer, sliceSpan, channelIndex, targetIsB4G4R4A4, gamma);
|
||||
ExtractChannelFromB4G4R4A4(buffer, sliceSpan, channelIndex, targetIsB4G4R4A4);
|
||||
break;
|
||||
case TexFile.TextureFormat.B8G8R8A8:
|
||||
// In case of modded font textures.
|
||||
ExtractChannelFromB8G8R8A8(buffer, sliceSpan, channelIndex, targetIsB4G4R4A4, gamma);
|
||||
ExtractChannelFromB8G8R8A8(buffer, sliceSpan, channelIndex, targetIsB4G4R4A4);
|
||||
break;
|
||||
default:
|
||||
// Unlikely.
|
||||
ExtractChannelFromB8G8R8A8(buffer, texFile.ImageData, channelIndex, targetIsB4G4R4A4, gamma);
|
||||
ExtractChannelFromB8G8R8A8(buffer, texFile.ImageData, channelIndex, targetIsB4G4R4A4);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -334,7 +334,6 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal
|
|||
ArrayPool<TexFile>.Shared.Return(x);
|
||||
});
|
||||
|
||||
var fontGamma = this.interfaceManager.FontGamma;
|
||||
var pixels8Array = new byte*[toolkitPostBuild.NewImAtlas.Textures.Size];
|
||||
var widths = new int[toolkitPostBuild.NewImAtlas.Textures.Size];
|
||||
var heights = new int[toolkitPostBuild.NewImAtlas.Textures.Size];
|
||||
|
|
@ -447,21 +446,6 @@ internal class GamePrebakedFontHandle : IFontHandle.IInternal
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.Abs(fontGamma - 1.4f) >= 0.001)
|
||||
{
|
||||
// Gamma correction (stbtt/FreeType would output in linear space whereas most real world usages will apply 1.4 or 1.8 gamma; Windows/XIV prebaked uses 1.4)
|
||||
var xTo = rc->X + rc->Width;
|
||||
var yTo = rc->Y + rc->Height;
|
||||
for (int y = rc->Y; y < yTo; y++)
|
||||
{
|
||||
for (int x = rc->X; x < xTo; x++)
|
||||
{
|
||||
var i = (y * width) + x;
|
||||
pixels8[i] = (byte)(Math.Pow(pixels8[i] / 255.0f, 1.4f / fontGamma) * 255.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.lateBuildRanges.TryGetValue(font, out var buildRanges))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue