diff --git a/docs/release-notes/v1.9.1.md b/docs/release-notes/v1.9.1.md
new file mode 100644
index 0000000..20becec
--- /dev/null
+++ b/docs/release-notes/v1.9.1.md
@@ -0,0 +1,9 @@
+# Gloam 1.9.1
+
+Gamma 2.2 and 2.4 now preserve HDR highlights above SDR white at 100% brightness.
+
+- Fixed a LUT shoulder that compressed highlight differences above SDR white, even when no dimming or color adjustment was active. With SDR white at 200 nits, the previous math mapped a 1,000-nit input to approximately 364 nits; gamma alone now leaves that input at 1,000 nits.
+- Brightness adjustments now follow the requested dimming curve throughout HDR headroom without an additional compression shoulder.
+- White-balance and measured-response adjustments fade from their correction at SDR white while retaining the HDR signal range. Constant-luminance night mode still accounts for the headroom consumed by boosted white.
+
+This changes live HDR LUT output. Validation: all 1,351 tests pass and the strict Release build has zero warnings or errors. Twelve new regression cases failed before the fix and pass afterward, covering both gamma modes, measured-response LUTs, dimming, shadow-only adjustments, and 256-entry hardware-ramp conversion. These are computed signal values, not physical measurements; no fresh display/colorimeter validation was performed.
diff --git a/scripts/render-comparison-images.py b/scripts/render-comparison-images.py
index c4a1890..aeb134e 100644
--- a/scripts/render-comparison-images.py
+++ b/scripts/render-comparison-images.py
@@ -5,7 +5,7 @@
Math is ported 1:1 from:
src/Gloam.Core/TransferFunctions.cs (PQ, sRGB)
- src/Gloam.Core/LutGenerator.cs (regrade + shoulder)
+ src/Gloam.Core/LutGenerator.cs (SDR regrade + HDR passthrough)
src/Gloam.Core/Calibration/HdrMhc2LutBuilder.cs:104
(the Windows SDR-in-HDR wire model)
@@ -104,14 +104,9 @@ def gloam_lut(gamma=GAMMA, sdr_white=SDR_WHITE, n=LUT_N):
sig = srgb_oetf(nits_in / sdr_white)
regraded = pq_inverse_eotf(sdr_white * np.power(sig, gamma))
- # smoothstep shoulder to passthrough above SDR white (LutGenerator.cs:288-315).
- # headroom target == v when brightness == 100 and no boost anchor.
- pq_white = pq_inverse_eotf(sdr_white)
- t = np.clip((v - pq_white) / max(1.0 - pq_white, 1e-9), 0.0, 1.0)
- blend = t * t * (3.0 - 2.0 * t)
- shouldered = regraded + (v - regraded) * blend
-
- return np.where(nits_in <= sdr_white, regraded, shouldered)
+ # With gamma alone, the correction at SDR white is zero. HDR headroom
+ # therefore stays identity at every level (LutGenerator.GenerateLutInternal).
+ return np.where(nits_in <= sdr_white, regraded, v)
def apply_lut(x, lut):
diff --git a/scripts/whitepaper-equations.json b/scripts/whitepaper-equations.json
index 2f8c9bc..dcbf1b6 100644
--- a/scripts/whitepaper-equations.json
+++ b/scripts/whitepaper-equations.json
@@ -26,7 +26,7 @@
[
"t = \\operatorname{clamp}\\!\\left(\\frac{V - \\mathrm{PQ}(W)}{1 - \\mathrm{PQ}(W)},\\; 0,\\; 1\\right)",
"s(t) = t^2(3 - 2t)",
- "\\text{output} = \\text{corrected} + s(t)\\left(\\text{headroom} - \\text{corrected}\\right)"
+ "\\text{output}_c = B(V) + (1-s(t))\\left(C_c(W) - B(\\mathrm{PQ}(W))\\right)"
],
[
"H(L) = A\\left(\\frac{L}{W}\\right)^{\\gamma'}, \\qquad \\gamma' = \\frac{\\ln(10000/A)}{\\ln(10000/W)}"
diff --git a/site/index.html b/site/index.html
index 55d140a..3fd8b2f 100644
--- a/site/index.html
+++ b/site/index.html
@@ -46,7 +46,7 @@
"applicationCategory": "UtilitiesApplication",
"applicationSubCategory": "Display calibration",
"operatingSystem": "Windows 10, Windows 11",
- "softwareVersion": "1.8.0",
+ "softwareVersion": "1.9.1",
"downloadUrl": "https://github.com/halideworks/gloam/releases/latest/download/GloamApp-win-Setup.exe",
"softwareHelp": "https://getgloam.org/guides",
"license": "https://opensource.org/licenses/MIT",
diff --git a/site/whitepaper.html b/site/whitepaper.html
index 88bf0d2..60b2791 100644
--- a/site/whitepaper.html
+++ b/site/whitepaper.html
@@ -295,7 +295,7 @@
4.2 HDR Output
Windows Default keeps LγLγ = P(V). The result is normalized
by W, adjusted in linear Rec.2020 RGB, returned to absolute luminance, and PQ-encoded
- per channel. Values above SDR white transition toward the headroom target described in §5.
+ per channel. Values above SDR white retain the headroom range described in §5.
4.3 SDR White
@@ -326,16 +326,25 @@ 5.1 PQ-Space Shoulder
Gamma and white-balance controls are intended mainly for the SDR desktop region. Applying
them unchanged to every HDR highlight would reshape mastered specular content. Above
- W, Gloam blends the adjusted result toward a headroom target in PQ signal space:
+ W, Gloam preserves the headroom target and fades only the correction at SDR white.
+ Let B(V) be the headroom target in PQ signal space, and Cc(W)
+ the adjusted SDR-white signal for channel c:
- Smoothstep gives zero first derivative at both ends. Blending in PQ space allocates the
- transition more evenly by perceptual code distance than a linear-nit blend.
+ With gamma alone at 100% brightness, the residual at white is zero: every HDR value
+ above SDR white passes through unchanged. With dimming alone, the output follows the
+ requested dimming curve throughout headroom. Blending the clamped SDR-white value
+ toward passthrough would instead flatten highlight differences just above white.
+
+
+ Smoothstep fades the white-point or calibration residual to zero at the PQ ceiling.
+ The output is continuous at SDR white, although the SDR curve and HDR target can have
+ different slopes there. The finite hardware ramp interpolates across that boundary.
5.2 Dimming and Constant-Luminance Night Mode
diff --git a/site/whitepaper.md b/site/whitepaper.md
index a870b31..9b12aa7 100644
--- a/site/whitepaper.md
+++ b/site/whitepaper.md
@@ -106,7 +106,7 @@ q = E_{\text{sRGB}}^{-1}\!\left(\frac{P(V)}{W}\right)
L_{\gamma} = W \cdot q^{\gamma_{\text{target}}}
```
-Windows Default keeps $L_{\gamma}$Lγ = *P*(*V*). The result is normalized by *W*, adjusted in linear Rec.2020 RGB, returned to absolute luminance, and PQ-encoded per channel. Values above SDR white transition toward the headroom target described in §5.
+Windows Default keeps $L_{\gamma}$Lγ = *P*(*V*). The result is normalized by *W*, adjusted in linear Rec.2020 RGB, returned to absolute luminance, and PQ-encoded per channel. Values above SDR white retain the headroom range described in §5.
### 4.3 SDR White
@@ -126,15 +126,17 @@ The diagnostic gray curve is derived from mean linear light, then encoded. In SD
### 5.1 PQ-Space Shoulder
-Gamma and white-balance controls are intended mainly for the SDR desktop region. Applying them unchanged to every HDR highlight would reshape mastered specular content. Above *W*, Gloam blends the adjusted result toward a headroom target in PQ signal space:
+Gamma and white-balance controls are intended mainly for the SDR desktop region. Applying them unchanged to every HDR highlight would reshape mastered specular content. Above *W*, Gloam preserves the headroom target and fades only the correction at SDR white. Let *B(V)* be the headroom target in PQ signal space, and *C_c(W)* the adjusted SDR-white signal for channel *c*:
```math
t = \operatorname{clamp}\!\left(\frac{V - \mathrm{PQ}(W)}{1 - \mathrm{PQ}(W)},\; 0,\; 1\right)
s(t) = t^2(3 - 2t)
-\text{output} = \text{corrected} + s(t)\left(\text{headroom} - \text{corrected}\right)
+\text{output}_c = B(V) + (1-s(t))\left(C_c(W) - B(\mathrm{PQ}(W))\right)
```
-Smoothstep gives zero first derivative at both ends. Blending in PQ space allocates the transition more evenly by perceptual code distance than a linear-nit blend.
+With gamma alone at 100% brightness, the residual at white is zero: every HDR value above SDR white passes through unchanged. With dimming alone, the output follows the requested dimming curve throughout headroom. Blending the clamped SDR-white value toward passthrough would instead flatten highlight differences just above white.
+
+Smoothstep fades the white-point or calibration residual to zero at the PQ ceiling. The output is continuous at SDR white, although the SDR curve and HDR target can have different slopes there. The finite hardware ramp interpolates across that boundary.
### 5.2 Dimming and Constant-Luminance Night Mode
diff --git a/src/Gloam.Core/LutGenerator.cs b/src/Gloam.Core/LutGenerator.cs
index b2563af..7d2644c 100644
--- a/src/Gloam.Core/LutGenerator.cs
+++ b/src/Gloam.Core/LutGenerator.cs
@@ -14,7 +14,7 @@ namespace Gloam.Core
/// 3. Apply target gamma curve (2.2 or 2.4)
/// 4. Apply calibration adjustments in linear space
/// 5. PQ OETF encode (linear nits to signal)
- /// 6. Blend toward passthrough in HDR headroom region
+ /// 6. Preserve HDR headroom, fading only the correction at SDR white
///
/// LUT results are cached to avoid redundant computation for identical parameters.
///
@@ -206,17 +206,14 @@ private static (double[] R, double[] G, double[] B, double[] Grey) GenerateLutIn
double blackLevel = 0.0;
- // Precompute the PQ-signal position of SDR white. The headroom blend runs in
- // PQ-signal space (perceptually uniform) rather than linear-nit space — with the
- // old linear blend a 1000-nit specular was only ~8% toward passthrough, so most
- // real HDR highlights stayed fully calibrated regardless of the user's intent.
+ // Above SDR white, preserve the headroom target's full signal range and fade
+ // only the adjustment at white. Blending a clamped SDR value toward the target
+ // instead flattens the lower highlights, even at 100% with gamma alone.
double pqSdrWhite = TransferFunctions.PqInverseEotf(sdrWhiteLevel);
- // Constant-Y boost anchor: when the SDR-region white is boosted above the plain
- // (dimmed) white, the headroom blend's target must START at the boosted value —
- // blending a flat boosted channel toward a target that begins below it produces a
- // dip (non-monotonic LUT) just above the SDR/HDR boundary. The anchor is the max
- // channel's output at input white through the full adjustment chain.
+ // Constant-Y boost anchor: start the headroom target at the brightest adjusted
+ // white channel. All channel residuals are then non-positive, so fading them
+ // toward zero preserves the target's monotonicity.
double boostAnchorNits = 0.0;
if (calibration.HasAdjustments && calibration.PreserveNightLuminance &&
calibration.NightLuminanceCeiling > 1.0 + 1e-9)
@@ -230,6 +227,9 @@ private static (double[] R, double[] G, double[] B, double[] Grey) GenerateLutIn
boostAnchorNits = anchor;
}
+ double headroomWhiteSignal = ComputeHeadroomTarget(
+ sdrWhiteLevel, calibration, sdrWhiteLevel, boostAnchorNits);
+
for (int i = 0; i < 1024; i++)
{
double normalized = i / 1023.0;
@@ -294,24 +294,24 @@ private static (double[] R, double[] G, double[] B, double[] Grey) GenerateLutIn
}
else
{
- // HDR headroom: blend the fully-calibrated output toward a
- // "dim-only passthrough". This preserves the creative grade of
- // HDR highlights (no re-gamma, no temperature tint on a 2000-nit
- // specular) while still honoring the brightness slider — so a
- // user dimming the screen sees highlights come down too.
+ // pqR/G/B/Grey above white are the adjusted SDR-white anchor (the
+ // SDR transfer/adjustment functions are bounded). Preserve the FULL
+ // headroom signal, adding only each anchor's residual correction.
+ // Gamma alone has zero residual, giving identity at EVERY HDR level;
+ // brightness alone gives the requested dimming without a second shoulder.
double headroomSignal = ComputeHeadroomTarget(linear, calibration, sdrWhiteLevel, boostAnchorNits);
- // Blend in PQ-signal space (perceptually uniform) with a smoothstep
- // for C¹ continuity at the SDR/HDR boundary, eliminating the visible
- // slope-kink the old linear blend produced in smooth gradients.
+ // Smoothstep fades the residual to zero at the PQ ceiling. It keeps
+ // the value continuous at SDR white; the SDR curve and HDR target can
+ // still have slightly different slopes at that boundary.
double t = (normalized - pqSdrWhite) / Math.Max(1.0 - pqSdrWhite, 1e-9);
t = Clamp01(t);
double blendFactor = t * t * (3.0 - 2.0 * t);
- lutR[i] = pqR + (headroomSignal - pqR) * blendFactor;
- lutG[i] = pqG + (headroomSignal - pqG) * blendFactor;
- lutB[i] = pqB + (headroomSignal - pqB) * blendFactor;
- lutGrey[i] = pqGrey + (headroomSignal - pqGrey) * blendFactor;
+ lutR[i] = headroomSignal + (pqR - headroomWhiteSignal) * (1.0 - blendFactor);
+ lutG[i] = headroomSignal + (pqG - headroomWhiteSignal) * (1.0 - blendFactor);
+ lutB[i] = headroomSignal + (pqB - headroomWhiteSignal) * (1.0 - blendFactor);
+ lutGrey[i] = headroomSignal + (pqGrey - headroomWhiteSignal) * (1.0 - blendFactor);
}
}
@@ -512,6 +512,7 @@ private static (double[] R, double[] G, double[] B, double[] Grey) GenerateCalib
// HDR Mode with calibration-aware compensation
double blackLevel = safeBlackLevel;
double pqSdrWhite = TransferFunctions.PqInverseEotf(sdrWhiteLevel);
+ double headroomWhiteSignal = ComputeHeadroomTarget(sdrWhiteLevel, calibration, sdrWhiteLevel);
for (int i = 0; i < 1024; i++)
{
@@ -583,17 +584,18 @@ private static (double[] R, double[] G, double[] B, double[] Grey) GenerateCalib
}
else
{
- // Headroom: blend toward a dim-aware passthrough in PQ-signal space
- // with a smoothstep. See GenerateLutInternal for rationale.
+ // The measured response is bounded at SDR white. Preserve the target's
+ // headroom range and fade only the compensated white residual, just as
+ // in GenerateLutInternal; do not extend the bounded response as a shelf.
double headroomSignal = ComputeHeadroomTarget(linear, calibration, sdrWhiteLevel);
double t = Clamp01((normalized - pqSdrWhite) / Math.Max(1.0 - pqSdrWhite, 1e-9));
double blendFactor = t * t * (3.0 - 2.0 * t);
- lutR[i] = pqR + (headroomSignal - pqR) * blendFactor;
- lutG[i] = pqG + (headroomSignal - pqG) * blendFactor;
- lutB[i] = pqB + (headroomSignal - pqB) * blendFactor;
- lutGrey[i] = pqGrey + (headroomSignal - pqGrey) * blendFactor;
+ lutR[i] = headroomSignal + (pqR - headroomWhiteSignal) * (1.0 - blendFactor);
+ lutG[i] = headroomSignal + (pqG - headroomWhiteSignal) * (1.0 - blendFactor);
+ lutB[i] = headroomSignal + (pqB - headroomWhiteSignal) * (1.0 - blendFactor);
+ lutGrey[i] = headroomSignal + (pqGrey - headroomWhiteSignal) * (1.0 - blendFactor);
}
}
diff --git a/src/Gloam/Gloam.csproj b/src/Gloam/Gloam.csproj
index 09afedf..fb5d11b 100644
--- a/src/Gloam/Gloam.csproj
+++ b/src/Gloam/Gloam.csproj
@@ -20,7 +20,7 @@
- 1.9.0
+ 1.9.1
$(Version).0
$(Version).0
$(Version)
diff --git a/tests/Gloam.Tests/HdrHighlightTests.cs b/tests/Gloam.Tests/HdrHighlightTests.cs
new file mode 100644
index 0000000..c21c7fd
--- /dev/null
+++ b/tests/Gloam.Tests/HdrHighlightTests.cs
@@ -0,0 +1,109 @@
+using Gloam.Core;
+using Gloam.Core.Calibration;
+using Xunit;
+
+namespace Gloam.Tests;
+
+public class HdrHighlightTests
+{
+ [Theory]
+ [InlineData(GammaMode.Gamma22)]
+ [InlineData(GammaMode.Gamma24)]
+ public void FullBrightness_PreservesEveryHdrHighlight(GammaMode mode)
+ {
+ foreach (double white in new[] { 80.0, 200.0, 480.0, 1000.0 })
+ {
+ var lut = LutGenerator.GenerateLut(mode, white);
+ AssertHighlightIdentity(lut, white);
+
+ // Check the actual 256-entry, 16-bit upload, including Windows' envelope.
+ var ramp = NativeGammaRamp.BuildRampChannel(lut, applyGdiEnvelope: true, out bool clamped);
+ Assert.False(clamped);
+ for (int i = 0; i < ramp.Length; i++)
+ {
+ // Both source interpolation knots must be above SDR white.
+ int lower = (int)(i / 255.0 * (lut.Length - 1));
+ if (TransferFunctions.PqEotf(lower / 1023.0) >= white)
+ Assert.Equal((ushort)(i * 257), ramp[i]);
+ }
+ }
+ }
+
+ [Theory]
+ [InlineData(2.2)]
+ [InlineData(2.4)]
+ public void MeasuredResponse_DoesNotCompressUnmeasuredHdrHeadroom(double gamma)
+ {
+ const double white = 200.0;
+ var display = new DisplayCharacterization
+ {
+ PeakLuminance = white,
+ BlackLevel = 0.0,
+ MeasuredGamma = 2.2
+ };
+ var lut = LutGenerator.GenerateCalibratedLut(
+ gamma, display, CalibrationSettings.Default, white, isHdr: true);
+
+ foreach (var channel in new[] { lut.R, lut.G, lut.B, lut.Grey })
+ AssertHighlightIdentity(channel, white);
+ }
+
+ [Theory]
+ [InlineData(GammaMode.WindowsDefault, false)]
+ [InlineData(GammaMode.Gamma22, false)]
+ [InlineData(GammaMode.Gamma24, false)]
+ [InlineData(GammaMode.WindowsDefault, true)]
+ [InlineData(GammaMode.Gamma22, true)]
+ [InlineData(GammaMode.Gamma24, true)]
+ public void Dimming_PreservesHdrRangeUsingOnlyRequestedBrightness(GammaMode mode, bool linearDimming)
+ {
+ const double white = 200.0;
+ foreach (double brightness in new[] { 10.0, 50.0, 80.0 })
+ {
+ var lut = LutGenerator.GenerateLut(mode, white, new CalibrationSettings
+ {
+ Brightness = brightness,
+ UseLinearBrightness = linearDimming
+ });
+ for (int i = 1; i < lut.R.Length; i++)
+ {
+ double nits = TransferFunctions.PqEotf(i / 1023.0);
+ if (nits < white) continue;
+
+ double expected = ColorAdjustments.ApplyDimmingNits(nits, brightness, white, linearDimming);
+ double actual = TransferFunctions.PqEotf(lut.R[i]);
+ Assert.True(Math.Abs(actual - expected) <= Math.Max(1e-8, expected * 1e-9),
+ $"{mode}, {brightness}%: {nits:F3} nits became {actual:F3}, expected {expected:F3}");
+ Assert.True(lut.R[i] > lut.R[i - 1], $"Highlight detail lost at sample {i}");
+ }
+ }
+ }
+
+ [Theory]
+ [InlineData(GammaMode.Gamma22)]
+ [InlineData(GammaMode.Gamma24)]
+ public void ShadowOnlyAdjustment_LeavesHdrHighlightsUntouched(GammaMode mode)
+ {
+ var lut = LutGenerator.GenerateLut(mode, 200.0, new CalibrationSettings
+ {
+ ShadowDetailStrength = 0.55,
+ ShadowDetailPivot = 0.10
+ });
+ foreach (var channel in new[] { lut.R, lut.G, lut.B, lut.Grey })
+ AssertHighlightIdentity(channel, 200.0);
+ }
+
+ private static void AssertHighlightIdentity(double[] lut, double white)
+ {
+ for (int i = 1; i < lut.Length; i++)
+ {
+ double input = i / 1023.0;
+ double nits = TransferFunctions.PqEotf(input);
+ if (nits < white) continue;
+
+ Assert.True(Math.Abs(lut[i] - input) < 1e-12,
+ $"White {white} nits: HDR input {nits:F3} became {TransferFunctions.PqEotf(lut[i]):F3} nits");
+ Assert.True(lut[i] > lut[i - 1], $"Highlight detail lost at sample {i}");
+ }
+ }
+}