From 15589c999781ec825163d62b800dcd43c7c8c242 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 26 Jun 2024 15:53:41 +0200 Subject: [PATCH] color management: change brightness information names to be shorter and more correct Brightness is a loose word for how bright we perceive things to be, but the values we're using are about objective measurements, about luminance instead. --- src/backends/drm/drm_egl_layer_surface.cpp | 14 +++--- src/backends/drm/drm_output.cpp | 8 ++-- src/backends/drm/icc.frag | 4 +- src/backends/drm/icc_core.frag | 4 +- src/backends/drm/icc_shader.cpp | 6 +-- src/backends/drm/icc_shader.h | 4 +- src/core/colorspace.cpp | 54 +++++++++++----------- src/core/colorspace.h | 36 +++++++-------- src/core/output.cpp | 8 ++-- src/core/output.h | 6 +-- src/core/outputconfiguration.h | 2 +- src/opengl/colormanagement.glsl | 10 ++-- src/opengl/glshader.cpp | 10 ++-- src/outputconfigurationstore.cpp | 14 +++--- src/outputconfigurationstore.h | 2 +- src/plugins/colorpicker/colorpicker.cpp | 2 +- src/wayland/frog_colormanagement_v1.cpp | 10 ++-- src/wayland/frog_colormanagement_v1.h | 2 +- src/wayland/outputdevice_v2.cpp | 10 ++-- src/wayland/outputmanagement_v2.cpp | 2 +- src/wayland/xx_colormanagement_v2.cpp | 6 +-- src/wayland/xx_colormanagement_v2.h | 2 +- 22 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/backends/drm/drm_egl_layer_surface.cpp b/src/backends/drm/drm_egl_layer_surface.cpp index 98d8664bb4..252ef436b5 100644 --- a/src/backends/drm/drm_egl_layer_surface.cpp +++ b/src/backends/drm/drm_egl_layer_surface.cpp @@ -116,8 +116,8 @@ std::optional EglGbmLayerSurface::startRendering(cons } if (enableColormanagement) { m_surface->intermediaryColorDescription = ColorDescription(colorDescription.containerColorimetry(), NamedTransferFunction::linear, - colorDescription.sdrBrightness(), colorDescription.minHdrBrightness(), - colorDescription.maxFrameAverageBrightness(), colorDescription.maxHdrHighlightBrightness(), + colorDescription.referenceLuminance(), colorDescription.minLuminance(), + colorDescription.maxAverageLuminance(), colorDescription.maxHdrLuminance(), colorDescription.containerColorimetry(), colorDescription.sdrColorimetry()); } else { m_surface->intermediaryColorDescription = colorDescription; @@ -188,12 +188,12 @@ bool EglGbmLayerSurface::endRendering(const QRegion &damagedRegion, OutputFrame GLFramebuffer::pushFramebuffer(fbo); ShaderBinder binder = m_surface->iccShader ? ShaderBinder(m_surface->iccShader->shader()) : ShaderBinder(ShaderTrait::MapTexture | ShaderTrait::TransformColorspace); if (m_surface->iccShader) { - m_surface->iccShader->setUniforms(m_surface->iccProfile, m_surface->intermediaryColorDescription.sdrBrightness(), m_surface->adaptedChannelFactors); + m_surface->iccShader->setUniforms(m_surface->iccProfile, m_surface->intermediaryColorDescription.referenceLuminance(), m_surface->adaptedChannelFactors); } else { // enforce a 25 nits minimum sdr brightness constexpr double minBrightness = 25; - const double sdrBrightness = m_surface->intermediaryColorDescription.sdrBrightness(); - const double brightnessFactor = (m_surface->brightness * (1 - (minBrightness / sdrBrightness))) + (minBrightness / sdrBrightness); + const double referenceLuminance = m_surface->intermediaryColorDescription.referenceLuminance(); + const double brightnessFactor = (m_surface->brightness * (1 - (minBrightness / referenceLuminance))) + (minBrightness / referenceLuminance); QMatrix4x4 ctm; ctm(0, 0) = m_surface->adaptedChannelFactors.x() * brightnessFactor; ctm(1, 1) = m_surface->adaptedChannelFactors.y() * brightnessFactor; @@ -201,8 +201,8 @@ bool EglGbmLayerSurface::endRendering(const QRegion &damagedRegion, OutputFrame binder.shader()->setUniform(GLShader::Mat4Uniform::ColorimetryTransformation, ctm); binder.shader()->setUniform(GLShader::IntUniform::SourceNamedTransferFunction, int(m_surface->intermediaryColorDescription.transferFunction())); binder.shader()->setUniform(GLShader::IntUniform::DestinationNamedTransferFunction, int(m_surface->targetColorDescription.transferFunction())); - binder.shader()->setUniform(GLShader::FloatUniform::SdrBrightness, m_surface->intermediaryColorDescription.sdrBrightness()); - binder.shader()->setUniform(GLShader::FloatUniform::MaxHdrBrightness, m_surface->intermediaryColorDescription.maxHdrHighlightBrightness().value_or(800)); + binder.shader()->setUniform(GLShader::FloatUniform::SdrBrightness, m_surface->intermediaryColorDescription.referenceLuminance()); + binder.shader()->setUniform(GLShader::FloatUniform::MaxHdrBrightness, m_surface->intermediaryColorDescription.maxHdrLuminance().value_or(800)); } QMatrix4x4 mat; mat.scale(1, -1); diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index a86acfcddd..704e6b41c6 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -381,10 +381,10 @@ ColorDescription DrmOutput::createColorDescription(const std::shared_ptrminBrightnessOverride.value_or(m_state.minBrightnessOverride).value_or(m_connector->edid()->desiredMinLuminance()) : 0; - const double maxAverageBrightness = effectiveHdr ? props->maxAverageBrightnessOverride.value_or(m_state.maxAverageBrightnessOverride).value_or(m_connector->edid()->desiredMaxFrameAverageLuminance().value_or(m_state.sdrBrightness)) : 200; + const double maxAverageBrightness = effectiveHdr ? props->maxAverageBrightnessOverride.value_or(m_state.maxAverageBrightnessOverride).value_or(m_connector->edid()->desiredMaxFrameAverageLuminance().value_or(m_state.referenceLuminance)) : 200; const double maxPeakBrightness = effectiveHdr ? props->maxPeakBrightnessOverride.value_or(m_state.maxPeakBrightnessOverride).value_or(m_connector->edid()->desiredMaxLuminance().value_or(800)) : 200; - const double sdrBrightness = effectiveHdr ? props->sdrBrightness.value_or(m_state.sdrBrightness) : maxPeakBrightness; - return ColorDescription(containerColorimetry, transferFunction, sdrBrightness, minBrightness, maxAverageBrightness, maxPeakBrightness, masteringColorimetry, sdrColorimetry); + const double referenceLuminance = effectiveHdr ? props->referenceLuminance.value_or(m_state.referenceLuminance) : maxPeakBrightness; + return ColorDescription(containerColorimetry, transferFunction, referenceLuminance, minBrightness, maxAverageBrightness, maxPeakBrightness, masteringColorimetry, sdrColorimetry); } void DrmOutput::applyQueuedChanges(const std::shared_ptr &props) @@ -405,7 +405,7 @@ void DrmOutput::applyQueuedChanges(const std::shared_ptr &props next.overscan = m_pipeline->overscan(); next.rgbRange = m_pipeline->rgbRange(); next.highDynamicRange = props->highDynamicRange.value_or(m_state.highDynamicRange); - next.sdrBrightness = props->sdrBrightness.value_or(m_state.sdrBrightness); + next.referenceLuminance = props->referenceLuminance.value_or(m_state.referenceLuminance); next.wideColorGamut = props->wideColorGamut.value_or(m_state.wideColorGamut); next.autoRotatePolicy = props->autoRotationPolicy.value_or(m_state.autoRotatePolicy); next.maxPeakBrightnessOverride = props->maxPeakBrightnessOverride.value_or(m_state.maxPeakBrightnessOverride); diff --git a/src/backends/drm/icc.frag b/src/backends/drm/icc.frag index 5f9963e6f0..0131505762 100644 --- a/src/backends/drm/icc.frag +++ b/src/backends/drm/icc.frag @@ -7,7 +7,7 @@ precision highp sampler3D; in vec2 texcoord0; uniform sampler2D src; -uniform float sdrBrightness; +uniform float referenceLuminance; uniform mat4 toXYZD50; @@ -38,7 +38,7 @@ void main() { vec4 tex = texture2D(src, texcoord0); tex.rgb /= max(tex.a, 0.001); - tex.rgb /= sdrBrightness; + tex.rgb /= referenceLuminance; tex.rgb = (toXYZD50 * vec4(tex.rgb, 1.0)).rgb; if (Bsize > 0) { tex.rgb = sample1DLut(tex.rgb, Bsampler, Bsize); diff --git a/src/backends/drm/icc_core.frag b/src/backends/drm/icc_core.frag index 1f23127803..ce83123173 100644 --- a/src/backends/drm/icc_core.frag +++ b/src/backends/drm/icc_core.frag @@ -10,7 +10,7 @@ in vec2 texcoord0; out vec4 fragColor; uniform sampler2D src; -uniform float sdrBrightness; +uniform float referenceLuminance; uniform mat4 toXYZD50; @@ -41,7 +41,7 @@ void main() { vec4 tex = texture(src, texcoord0); tex.rgb /= max(tex.a, 0.001); - tex.rgb /= sdrBrightness; + tex.rgb /= referenceLuminance; tex.rgb = (toXYZD50 * vec4(tex.rgb, 1.0)).rgb; if (Bsize > 0) { tex.rgb = sample1DLut(tex.rgb, Bsampler, Bsize); diff --git a/src/backends/drm/icc_shader.cpp b/src/backends/drm/icc_shader.cpp index b36fc34d65..791fa33c67 100644 --- a/src/backends/drm/icc_shader.cpp +++ b/src/backends/drm/icc_shader.cpp @@ -22,7 +22,7 @@ IccShader::IccShader() { m_locations = { .src = m_shader->uniformLocation("src"), - .sdrBrightness = m_shader->uniformLocation("sdrBrightness"), + .referenceLuminance = m_shader->uniformLocation("referenceLuminance"), .toXYZD50 = m_shader->uniformLocation("toXYZD50"), .bsize = m_shader->uniformLocation("Bsize"), .bsampler = m_shader->uniformLocation("Bsampler"), @@ -145,7 +145,7 @@ GLShader *IccShader::shader() const return m_shader.get(); } -void IccShader::setUniforms(const std::shared_ptr &profile, float sdrBrightness, const QVector3D &channelFactors) +void IccShader::setUniforms(const std::shared_ptr &profile, float referenceLuminance, const QVector3D &channelFactors) { // this failing can be silently ignored, it should only happen with GPU resets and gets corrected later setProfile(profile); @@ -155,7 +155,7 @@ void IccShader::setUniforms(const std::shared_ptr &profile, float sd nightColor(1, 1) = channelFactors.y(); nightColor(2, 2) = channelFactors.z(); m_shader->setUniform(m_locations.toXYZD50, m_toXYZD50 * nightColor); - m_shader->setUniform(m_locations.sdrBrightness, sdrBrightness); + m_shader->setUniform(m_locations.referenceLuminance, referenceLuminance); glActiveTexture(GL_TEXTURE1); if (m_B) { diff --git a/src/backends/drm/icc_shader.h b/src/backends/drm/icc_shader.h index faecfaca39..fe554213e8 100644 --- a/src/backends/drm/icc_shader.h +++ b/src/backends/drm/icc_shader.h @@ -25,7 +25,7 @@ public: ~IccShader(); GLShader *shader() const; - void setUniforms(const std::shared_ptr &profile, float sdrBrightness, const QVector3D &channelFactors); + void setUniforms(const std::shared_ptr &profile, float referenceLuminance, const QVector3D &channelFactors); private: bool setProfile(const std::shared_ptr &profile); @@ -42,7 +42,7 @@ private: struct Locations { int src; - int sdrBrightness; + int referenceLuminance; int toXYZD50; int bsize; int bsampler; diff --git a/src/core/colorspace.cpp b/src/core/colorspace.cpp index 444909ddb6..29f9535d17 100644 --- a/src/core/colorspace.cpp +++ b/src/core/colorspace.cpp @@ -200,30 +200,30 @@ const Colorimetry &Colorimetry::fromName(NamedColorimetry name) const ColorDescription ColorDescription::sRGB = ColorDescription(NamedColorimetry::BT709, NamedTransferFunction::gamma22, 100, 0, 100, 100); -ColorDescription::ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness) - : ColorDescription(containerColorimetry, tf, sdrBrightness, minHdrBrightness, maxFrameAverageBrightness, maxHdrHighlightBrightness, std::nullopt, Colorimetry::fromName(NamedColorimetry::BT709)) +ColorDescription::ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance) + : ColorDescription(containerColorimetry, tf, referenceLuminance, minLuminance, maxAverageLuminance, maxHdrLuminance, std::nullopt, Colorimetry::fromName(NamedColorimetry::BT709)) { } -ColorDescription::ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness) - : ColorDescription(Colorimetry::fromName(containerColorimetry), tf, sdrBrightness, minHdrBrightness, maxFrameAverageBrightness, maxHdrHighlightBrightness, std::nullopt, Colorimetry::fromName(NamedColorimetry::BT709)) +ColorDescription::ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance) + : ColorDescription(Colorimetry::fromName(containerColorimetry), tf, referenceLuminance, minLuminance, maxAverageLuminance, maxHdrLuminance, std::nullopt, Colorimetry::fromName(NamedColorimetry::BT709)) { } -ColorDescription::ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry) +ColorDescription::ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry) : m_containerColorimetry(containerColorimetry) , m_masteringColorimetry(masteringColorimetry) , m_transferFunction(tf) , m_sdrColorimetry(sdrColorimetry) - , m_sdrBrightness(sdrBrightness) - , m_minHdrBrightness(minHdrBrightness) - , m_maxFrameAverageBrightness(maxFrameAverageBrightness) - , m_maxHdrHighlightBrightness(maxHdrHighlightBrightness) + , m_referenceLuminance(referenceLuminance) + , m_minLuminance(minLuminance) + , m_maxAverageLuminance(maxAverageLuminance) + , m_maxHdrLuminance(maxHdrLuminance) { } -ColorDescription::ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry) - : ColorDescription(Colorimetry::fromName(containerColorimetry), tf, sdrBrightness, minHdrBrightness, maxFrameAverageBrightness, maxHdrHighlightBrightness, masteringColorimetry, sdrColorimetry) +ColorDescription::ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry) + : ColorDescription(Colorimetry::fromName(containerColorimetry), tf, referenceLuminance, minLuminance, maxAverageLuminance, maxHdrLuminance, masteringColorimetry, sdrColorimetry) { } @@ -247,24 +247,24 @@ NamedTransferFunction ColorDescription::transferFunction() const return m_transferFunction; } -double ColorDescription::sdrBrightness() const +double ColorDescription::referenceLuminance() const { - return m_sdrBrightness; + return m_referenceLuminance; } -double ColorDescription::minHdrBrightness() const +double ColorDescription::minLuminance() const { - return m_minHdrBrightness; + return m_minLuminance; } -std::optional ColorDescription::maxFrameAverageBrightness() const +std::optional ColorDescription::maxAverageLuminance() const { - return m_maxFrameAverageBrightness; + return m_maxAverageLuminance; } -std::optional ColorDescription::maxHdrHighlightBrightness() const +std::optional ColorDescription::maxHdrLuminance() const { - return m_maxHdrHighlightBrightness; + return m_maxHdrLuminance; } static float srgbToLinear(float sRGB) @@ -317,13 +317,13 @@ static QVector3D clamp(const QVector3D &vect, float min = 0, float max = 1) return QVector3D(std::clamp(vect.x(), min, max), std::clamp(vect.y(), min, max), std::clamp(vect.z(), min, max)); } -QVector3D ColorDescription::encodedToNits(const QVector3D &nits, NamedTransferFunction tf, double sdrBrightness) +QVector3D ColorDescription::encodedToNits(const QVector3D &nits, NamedTransferFunction tf, double referenceLuminance) { switch (tf) { case NamedTransferFunction::sRGB: - return sdrBrightness * QVector3D(srgbToLinear(nits.x()), srgbToLinear(nits.y()), srgbToLinear(nits.z())); + return referenceLuminance * QVector3D(srgbToLinear(nits.x()), srgbToLinear(nits.y()), srgbToLinear(nits.z())); case NamedTransferFunction::gamma22: - return sdrBrightness * QVector3D(std::pow(nits.x(), 2.2), std::pow(nits.y(), 2.2), std::pow(nits.z(), 2.2)); + return referenceLuminance * QVector3D(std::pow(nits.x(), 2.2), std::pow(nits.y(), 2.2), std::pow(nits.z(), 2.2)); case NamedTransferFunction::linear: return nits; case NamedTransferFunction::scRGB: @@ -334,15 +334,15 @@ QVector3D ColorDescription::encodedToNits(const QVector3D &nits, NamedTransferFu Q_UNREACHABLE(); } -QVector3D ColorDescription::nitsToEncoded(const QVector3D &rgb, NamedTransferFunction tf, double sdrBrightness) +QVector3D ColorDescription::nitsToEncoded(const QVector3D &rgb, NamedTransferFunction tf, double referenceLuminance) { switch (tf) { case NamedTransferFunction::sRGB: { - const auto clamped = clamp(rgb / sdrBrightness); + const auto clamped = clamp(rgb / referenceLuminance); return QVector3D(linearToSRGB(clamped.x()), linearToSRGB(clamped.y()), linearToSRGB(clamped.z())); } case NamedTransferFunction::gamma22: { - const auto clamped = clamp(rgb / sdrBrightness); + const auto clamped = clamp(rgb / referenceLuminance); return QVector3D(std::pow(clamped.x(), 1 / 2.2), std::pow(clamped.y(), 1 / 2.2), std::pow(clamped.z(), 1 / 2.2)); } case NamedTransferFunction::linear: @@ -357,8 +357,8 @@ QVector3D ColorDescription::nitsToEncoded(const QVector3D &rgb, NamedTransferFun QVector3D ColorDescription::mapTo(QVector3D rgb, const ColorDescription &dst) const { - rgb = encodedToNits(rgb, m_transferFunction, m_sdrBrightness); + rgb = encodedToNits(rgb, m_transferFunction, m_referenceLuminance); rgb = m_containerColorimetry.toOther(dst.containerColorimetry()) * rgb; - return nitsToEncoded(rgb, dst.transferFunction(), dst.sdrBrightness()); + return nitsToEncoded(rgb, dst.transferFunction(), dst.referenceLuminance()); } } diff --git a/src/core/colorspace.h b/src/core/colorspace.h index e228b313f3..f5eb356a44 100644 --- a/src/core/colorspace.h +++ b/src/core/colorspace.h @@ -105,16 +105,16 @@ public: /** * @param containerColorimetry the container colorimety of this description * @param tf the transfer function of this description - * @param sdrBrightness the brightness of SDR content - * @param minHdrBrightness the minimum brightness of HDR content - * @param maxFrameAverageBrightness the maximum brightness of HDR content, if the whole screen is white - * @param maxHdrHighlightBrightness the maximum brightness of HDR content, for a small part of the screen only + * @param referenceLuminance the brightness of SDR content + * @param minLuminance the minimum brightness of HDR content + * @param maxAverageLuminance the maximum brightness of HDR content, if the whole screen is white + * @param maxHdrLuminance the maximum brightness of HDR content, for a small part of the screen only * @param sdrColorimetry */ - explicit ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness); - explicit ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness); - explicit ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry); - explicit ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double sdrBrightness, double minHdrBrightness, std::optional maxFrameAverageBrightness, std::optional maxHdrHighlightBrightness, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry); + explicit ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance); + explicit ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance); + explicit ColorDescription(const Colorimetry &containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry); + explicit ColorDescription(NamedColorimetry containerColorimetry, NamedTransferFunction tf, double referenceLuminance, double minLuminance, std::optional maxAverageLuminance, std::optional maxHdrLuminance, std::optional masteringColorimetry, const Colorimetry &sdrColorimetry); /** * The primaries and whitepoint that colors are encoded for. This is used to convert between different colorspaces. @@ -129,10 +129,10 @@ public: const std::optional &masteringColorimetry() const; const Colorimetry &sdrColorimetry() const; NamedTransferFunction transferFunction() const; - double sdrBrightness() const; - double minHdrBrightness() const; - std::optional maxFrameAverageBrightness() const; - std::optional maxHdrHighlightBrightness() const; + double referenceLuminance() const; + double minLuminance() const; + std::optional maxAverageLuminance() const; + std::optional maxHdrLuminance() const; bool operator==(const ColorDescription &other) const = default; @@ -142,17 +142,17 @@ public: * This color description describes display-referred sRGB, with a gamma22 transfer function */ static const ColorDescription sRGB; - static QVector3D encodedToNits(const QVector3D &nits, NamedTransferFunction tf, double sdrBrightness); - static QVector3D nitsToEncoded(const QVector3D &rgb, NamedTransferFunction tf, double sdrBrightness); + static QVector3D encodedToNits(const QVector3D &nits, NamedTransferFunction tf, double referenceLuminance); + static QVector3D nitsToEncoded(const QVector3D &rgb, NamedTransferFunction tf, double referenceLuminance); private: Colorimetry m_containerColorimetry; std::optional m_masteringColorimetry; NamedTransferFunction m_transferFunction; Colorimetry m_sdrColorimetry; - double m_sdrBrightness; - double m_minHdrBrightness; - std::optional m_maxFrameAverageBrightness; - std::optional m_maxHdrHighlightBrightness; + double m_referenceLuminance; + double m_minLuminance; + std::optional m_maxAverageLuminance; + std::optional m_maxHdrLuminance; }; } diff --git a/src/core/output.cpp b/src/core/output.cpp index f316c9c588..f944480704 100644 --- a/src/core/output.cpp +++ b/src/core/output.cpp @@ -594,8 +594,8 @@ void Output::setState(const State &state) if (oldState.highDynamicRange != state.highDynamicRange) { Q_EMIT highDynamicRangeChanged(); } - if (oldState.sdrBrightness != state.sdrBrightness) { - Q_EMIT sdrBrightnessChanged(); + if (oldState.referenceLuminance != state.referenceLuminance) { + Q_EMIT referenceLuminanceChanged(); } if (oldState.wideColorGamut != state.wideColorGamut) { Q_EMIT wideColorGamutChanged(); @@ -706,9 +706,9 @@ bool Output::highDynamicRange() const return m_state.highDynamicRange; } -uint32_t Output::sdrBrightness() const +uint32_t Output::referenceLuminance() const { - return m_state.sdrBrightness; + return m_state.referenceLuminance; } Output::AutoRotationPolicy Output::autoRotationPolicy() const diff --git a/src/core/output.h b/src/core/output.h index 7a7938ba63..eb53ba836e 100644 --- a/src/core/output.h +++ b/src/core/output.h @@ -336,7 +336,7 @@ public: OutputTransform panelOrientation() const; bool wideColorGamut() const; bool highDynamicRange() const; - uint32_t sdrBrightness() const; + uint32_t referenceLuminance() const; AutoRotationPolicy autoRotationPolicy() const; std::shared_ptr iccProfile() const; QString iccProfilePath() const; @@ -418,7 +418,7 @@ Q_SIGNALS: void vrrPolicyChanged(); void rgbRangeChanged(); void wideColorGamutChanged(); - void sdrBrightnessChanged(); + void referenceLuminanceChanged(); void highDynamicRangeChanged(); void autoRotationPolicyChanged(); void iccProfileChanged(); @@ -468,7 +468,7 @@ protected: RgbRange rgbRange = RgbRange::Automatic; bool wideColorGamut = false; bool highDynamicRange = false; - uint32_t sdrBrightness = 200; + uint32_t referenceLuminance = 200; AutoRotationPolicy autoRotatePolicy = AutoRotationPolicy::InTabletMode; QString iccProfilePath; std::shared_ptr iccProfile; diff --git a/src/core/outputconfiguration.h b/src/core/outputconfiguration.h index 746b2c4a00..febf98f5d2 100644 --- a/src/core/outputconfiguration.h +++ b/src/core/outputconfiguration.h @@ -35,7 +35,7 @@ public: std::optional rgbRange; std::optional vrrPolicy; std::optional highDynamicRange; - std::optional sdrBrightness; + std::optional referenceLuminance; std::optional wideColorGamut; std::optional autoRotationPolicy; std::optional iccProfilePath; diff --git a/src/opengl/colormanagement.glsl b/src/opengl/colormanagement.glsl index 2645f5f034..1f6b14f408 100644 --- a/src/opengl/colormanagement.glsl +++ b/src/opengl/colormanagement.glsl @@ -7,7 +7,7 @@ const int gamma22_EOTF = 4; uniform mat4 colorimetryTransform; uniform int sourceNamedTransferFunction; uniform int destinationNamedTransferFunction; -uniform float sdrBrightness;// in nits +uniform float referenceLuminance;// in nits uniform float maxHdrBrightness; // in nits vec3 nitsToPq(vec3 nits) { @@ -63,7 +63,7 @@ vec3 doTonemapping(vec3 color, float maxBrightness) { vec4 encodingToNits(vec4 color, int sourceTransferFunction) { if (sourceTransferFunction == sRGB_EOTF) { color.rgb /= max(color.a, 0.001); - color.rgb = sdrBrightness * srgbToLinear(color.rgb); + color.rgb = referenceLuminance * srgbToLinear(color.rgb); color.rgb *= color.a; } else if (sourceTransferFunction == PQ_EOTF) { color.rgb /= max(color.a, 0.001); @@ -73,7 +73,7 @@ vec4 encodingToNits(vec4 color, int sourceTransferFunction) { color.rgb *= 80.0; } else if (sourceTransferFunction == gamma22_EOTF) { color.rgb /= max(color.a, 0.001); - color.rgb = sdrBrightness * pow(color.rgb, vec3(2.2)); + color.rgb = referenceLuminance * pow(color.rgb, vec3(2.2)); color.rgb *= color.a; } return color; @@ -88,7 +88,7 @@ vec4 sourceEncodingToNitsInDestinationColorspace(vec4 color) { vec4 nitsToEncoding(vec4 color, int destinationTransferFunction) { if (destinationTransferFunction == sRGB_EOTF) { color.rgb /= max(color.a, 0.001); - color.rgb = linearToSrgb(doTonemapping(color.rgb, sdrBrightness) / sdrBrightness); + color.rgb = linearToSrgb(doTonemapping(color.rgb, referenceLuminance) / referenceLuminance); color.rgb *= color.a; } else if (destinationTransferFunction == PQ_EOTF) { color.rgb /= max(color.a, 0.001); @@ -98,7 +98,7 @@ vec4 nitsToEncoding(vec4 color, int destinationTransferFunction) { color.rgb /= 80.0; } else if (destinationTransferFunction == gamma22_EOTF) { color.rgb /= max(color.a, 0.001); - color.rgb = pow(color.rgb / sdrBrightness, vec3(1.0 / 2.2)); + color.rgb = pow(color.rgb / referenceLuminance, vec3(1.0 / 2.2)); color.rgb *= color.a; } return color; diff --git a/src/opengl/glshader.cpp b/src/opengl/glshader.cpp index bd2c2243d7..d9783b9b9f 100644 --- a/src/opengl/glshader.cpp +++ b/src/opengl/glshader.cpp @@ -226,7 +226,7 @@ void GLShader::resolveLocations() m_floatLocations[FloatUniform::Saturation] = uniformLocation("saturation"); m_floatLocations[FloatUniform::MaxHdrBrightness] = uniformLocation("maxHdrBrightness"); - m_floatLocations[FloatUniform::SdrBrightness] = uniformLocation("sdrBrightness"); + m_floatLocations[FloatUniform::SdrBrightness] = uniformLocation("referenceLuminance"); m_colorLocations[ColorUniform::Color] = uniformLocation("geometryColor"); @@ -458,8 +458,8 @@ bool GLShader::setColorspaceUniforms(const ColorDescription &src, const ColorDes return setUniform(GLShader::Mat4Uniform::ColorimetryTransformation, srcColorimetry.toOther(dst.containerColorimetry())) && setUniform(GLShader::IntUniform::SourceNamedTransferFunction, int(src.transferFunction())) && setUniform(GLShader::IntUniform::DestinationNamedTransferFunction, int(dst.transferFunction())) - && setUniform(FloatUniform::SdrBrightness, dst.sdrBrightness()) - && setUniform(FloatUniform::MaxHdrBrightness, dst.maxHdrHighlightBrightness().value_or(10'000)); + && setUniform(FloatUniform::SdrBrightness, dst.referenceLuminance()) + && setUniform(FloatUniform::MaxHdrBrightness, dst.maxHdrLuminance().value_or(10'000)); } bool GLShader::setColorspaceUniformsFromSRGB(const ColorDescription &dst) @@ -472,7 +472,7 @@ bool GLShader::setColorspaceUniformsToSRGB(const ColorDescription &src) return setUniform(GLShader::Mat4Uniform::ColorimetryTransformation, src.containerColorimetry().toOther(src.sdrColorimetry())) && setUniform(GLShader::IntUniform::SourceNamedTransferFunction, int(src.transferFunction())) && setUniform(GLShader::IntUniform::DestinationNamedTransferFunction, int(NamedTransferFunction::gamma22)) - && setUniform(FloatUniform::SdrBrightness, src.sdrBrightness()) - && setUniform(FloatUniform::MaxHdrBrightness, src.sdrBrightness()); + && setUniform(FloatUniform::SdrBrightness, src.referenceLuminance()) + && setUniform(FloatUniform::MaxHdrBrightness, src.referenceLuminance()); } } diff --git a/src/outputconfigurationstore.cpp b/src/outputconfigurationstore.cpp index 8b5c2753f5..83fbbdf7f9 100644 --- a/src/outputconfigurationstore.cpp +++ b/src/outputconfigurationstore.cpp @@ -224,7 +224,7 @@ void OutputConfigurationStore::storeConfig(const QList &allOutputs, bo .rgbRange = changeSet->rgbRange.value_or(output->rgbRange()), .vrrPolicy = changeSet->vrrPolicy.value_or(output->vrrPolicy()), .highDynamicRange = changeSet->highDynamicRange.value_or(output->highDynamicRange()), - .sdrBrightness = changeSet->sdrBrightness.value_or(output->sdrBrightness()), + .referenceLuminance = changeSet->referenceLuminance.value_or(output->referenceLuminance()), .wideColorGamut = changeSet->wideColorGamut.value_or(output->wideColorGamut()), .autoRotation = changeSet->autoRotationPolicy.value_or(output->autoRotationPolicy()), .iccProfilePath = changeSet->iccProfilePath.value_or(output->iccProfilePath()), @@ -266,7 +266,7 @@ void OutputConfigurationStore::storeConfig(const QList &allOutputs, bo .rgbRange = output->rgbRange(), .vrrPolicy = output->vrrPolicy(), .highDynamicRange = output->highDynamicRange(), - .sdrBrightness = output->sdrBrightness(), + .referenceLuminance = output->referenceLuminance(), .wideColorGamut = output->wideColorGamut(), .autoRotation = output->autoRotationPolicy(), .iccProfilePath = output->iccProfilePath(), @@ -320,7 +320,7 @@ std::pair> OutputConfigurationStore::setupT .rgbRange = state.rgbRange, .vrrPolicy = state.vrrPolicy, .highDynamicRange = state.highDynamicRange, - .sdrBrightness = state.sdrBrightness, + .referenceLuminance = state.referenceLuminance, .wideColorGamut = state.wideColorGamut, .autoRotationPolicy = state.autoRotation, .iccProfilePath = state.iccProfilePath, @@ -450,7 +450,7 @@ std::pair> OutputConfigurationStore::genera .rgbRange = existingData.rgbRange.value_or(kscreenChangeSet.rgbRange.value_or(Output::RgbRange::Automatic)), .vrrPolicy = existingData.vrrPolicy.value_or(kscreenChangeSet.vrrPolicy.value_or(VrrPolicy::Automatic)), .highDynamicRange = existingData.highDynamicRange.value_or(false), - .sdrBrightness = existingData.sdrBrightness.value_or(std::clamp(output->maxAverageBrightness().value_or(200), 200.0, 500.0)), + .referenceLuminance = existingData.referenceLuminance.value_or(std::clamp(output->maxAverageBrightness().value_or(200), 200.0, 500.0)), .wideColorGamut = existingData.wideColorGamut.value_or(false), .autoRotationPolicy = existingData.autoRotation.value_or(Output::AutoRotationPolicy::InTabletMode), .colorProfileSource = existingData.colorProfileSource.value_or(Output::ColorProfileSource::sRGB), @@ -713,7 +713,7 @@ void OutputConfigurationStore::load() state.highDynamicRange = it->toBool(); } if (const auto it = data.find("sdrBrightness"); it != data.end() && it->isDouble()) { - state.sdrBrightness = it->toInt(200); + state.referenceLuminance = it->toInt(200); } if (const auto it = data.find("wideColorGamut"); it != data.end() && it->isBool()) { state.wideColorGamut = it->toBool(); @@ -945,8 +945,8 @@ void OutputConfigurationStore::save() if (output.highDynamicRange) { o["highDynamicRange"] = *output.highDynamicRange; } - if (output.sdrBrightness) { - o["sdrBrightness"] = int(*output.sdrBrightness); + if (output.referenceLuminance) { + o["sdrBrightness"] = int(*output.referenceLuminance); } if (output.wideColorGamut) { o["wideColorGamut"] = *output.wideColorGamut; diff --git a/src/outputconfigurationstore.h b/src/outputconfigurationstore.h index 3e4711780d..cec05731e4 100644 --- a/src/outputconfigurationstore.h +++ b/src/outputconfigurationstore.h @@ -73,7 +73,7 @@ private: std::optional rgbRange; std::optional vrrPolicy; std::optional highDynamicRange; - std::optional sdrBrightness; + std::optional referenceLuminance; std::optional wideColorGamut; std::optional autoRotation; std::optional iccProfilePath; diff --git a/src/plugins/colorpicker/colorpicker.cpp b/src/plugins/colorpicker/colorpicker.cpp index bc61ebb6d8..d85b07304f 100644 --- a/src/plugins/colorpicker/colorpicker.cpp +++ b/src/plugins/colorpicker/colorpicker.cpp @@ -65,7 +65,7 @@ void ColorPickerEffect::paintScreen(const RenderTarget &renderTarget, const Rend std::array data; constexpr GLsizei PIXEL_SIZE = 1; const QPoint texturePosition = viewport.mapToRenderTarget(m_scheduledPosition).toPoint(); - const ColorDescription sRGBencoding(Colorimetry::fromName(NamedColorimetry::BT709), NamedTransferFunction::gamma22, renderTarget.colorDescription().sdrBrightness(), 0, renderTarget.colorDescription().sdrBrightness(), renderTarget.colorDescription().sdrBrightness()); + const ColorDescription sRGBencoding(Colorimetry::fromName(NamedColorimetry::BT709), NamedTransferFunction::gamma22, renderTarget.colorDescription().referenceLuminance(), 0, renderTarget.colorDescription().referenceLuminance(), renderTarget.colorDescription().referenceLuminance()); glReadPixels(texturePosition.x(), renderTarget.size().height() - texturePosition.y() - PIXEL_SIZE, PIXEL_SIZE, PIXEL_SIZE, GL_RGBA, GL_FLOAT, data.data()); QVector3D sRGB = 255 * renderTarget.colorDescription().mapTo(QVector3D(data[0], data[1], data[2]), sRGBencoding); diff --git a/src/wayland/frog_colormanagement_v1.cpp b/src/wayland/frog_colormanagement_v1.cpp index a02427aae0..dca4f4f359 100644 --- a/src/wayland/frog_colormanagement_v1.cpp +++ b/src/wayland/frog_colormanagement_v1.cpp @@ -80,9 +80,9 @@ void FrogColorManagementSurfaceV1::setPreferredColorDescription(const ColorDescr encodePrimary(color.green().x()), encodePrimary(color.green().y()), encodePrimary(color.blue().x()), encodePrimary(color.blue().y()), encodePrimary(color.white().x()), encodePrimary(color.white().y()), - std::round(colorDescription.maxHdrHighlightBrightness().value_or(0)), - std::round(colorDescription.minHdrBrightness() / 0.0001), - std::round(colorDescription.maxFrameAverageBrightness().value_or(0))); + std::round(colorDescription.maxHdrLuminance().value_or(0)), + std::round(colorDescription.minLuminance() / 0.0001), + std::round(colorDescription.maxAverageLuminance().value_or(0))); } void FrogColorManagementSurfaceV1::frog_color_managed_surface_set_known_transfer_function(Resource *resource, uint32_t transfer_function) @@ -131,7 +131,7 @@ void FrogColorManagementSurfaceV1::frog_color_managed_surface_set_hdr_metadata(R uint32_t max_cll, uint32_t max_fall) { if (max_fall > 0) { - m_maxFrameAverageBrightness = max_fall; + m_maxAverageLuminance = max_fall; } if (max_cll > 0) { m_maxPeakBrightness = max_cll; @@ -161,7 +161,7 @@ void FrogColorManagementSurfaceV1::updateColorDescription() { if (m_surface) { SurfaceInterfacePrivate *priv = SurfaceInterfacePrivate::get(m_surface); - priv->pending->colorDescription = ColorDescription(m_containerColorimetry, m_transferFunction, 0, 0, m_maxFrameAverageBrightness, m_maxPeakBrightness, m_masteringColorimetry, Colorimetry::fromName(NamedColorimetry::BT709)); + priv->pending->colorDescription = ColorDescription(m_containerColorimetry, m_transferFunction, 0, 0, m_maxAverageLuminance, m_maxPeakBrightness, m_masteringColorimetry, Colorimetry::fromName(NamedColorimetry::BT709)); priv->pending->colorDescriptionIsSet = true; } } diff --git a/src/wayland/frog_colormanagement_v1.h b/src/wayland/frog_colormanagement_v1.h index c5fa1a87ba..787feda2ff 100644 --- a/src/wayland/frog_colormanagement_v1.h +++ b/src/wayland/frog_colormanagement_v1.h @@ -56,7 +56,7 @@ private: NamedTransferFunction m_transferFunction = NamedTransferFunction::sRGB; NamedColorimetry m_containerColorimetry = NamedColorimetry::BT709; std::optional m_masteringColorimetry; - std::optional m_maxFrameAverageBrightness; + std::optional m_maxAverageLuminance; std::optional m_maxPeakBrightness; }; diff --git a/src/wayland/outputdevice_v2.cpp b/src/wayland/outputdevice_v2.cpp index 6159db797a..f38d7a8335 100644 --- a/src/wayland/outputdevice_v2.cpp +++ b/src/wayland/outputdevice_v2.cpp @@ -131,7 +131,7 @@ public: vrr_policy m_vrrPolicy = vrr_policy_automatic; rgb_range m_rgbRange = rgb_range_automatic; bool m_highDynamicRange = false; - uint32_t m_sdrBrightness = 200; + uint32_t m_referenceLuminance = 200; bool m_wideColorGamut = false; auto_rotate_policy m_autoRotation = auto_rotate_policy::auto_rotate_policy_in_tablet_mode; QString m_iccProfilePath; @@ -253,7 +253,7 @@ OutputDeviceV2Interface::OutputDeviceV2Interface(Display *display, Output *handl connect(handle, &Output::rgbRangeChanged, this, &OutputDeviceV2Interface::updateRgbRange); connect(handle, &Output::highDynamicRangeChanged, this, &OutputDeviceV2Interface::updateHighDynamicRange); - connect(handle, &Output::sdrBrightnessChanged, this, &OutputDeviceV2Interface::updateSdrBrightness); + connect(handle, &Output::referenceLuminanceChanged, this, &OutputDeviceV2Interface::updateSdrBrightness); connect(handle, &Output::wideColorGamutChanged, this, &OutputDeviceV2Interface::updateWideColorGamut); connect(handle, &Output::autoRotationPolicyChanged, this, &OutputDeviceV2Interface::updateAutoRotate); connect(handle, &Output::iccProfileChanged, this, &OutputDeviceV2Interface::updateIccProfilePath); @@ -429,7 +429,7 @@ void OutputDeviceV2InterfacePrivate::sendHighDynamicRange(Resource *resource) void OutputDeviceV2InterfacePrivate::sendSdrBrightness(Resource *resource) { if (resource->version() >= KDE_OUTPUT_DEVICE_V2_SDR_BRIGHTNESS_SINCE_VERSION) { - send_sdr_brightness(resource->handle, m_sdrBrightness); + send_sdr_brightness(resource->handle, m_referenceLuminance); } } @@ -723,8 +723,8 @@ void OutputDeviceV2Interface::updateHighDynamicRange() void OutputDeviceV2Interface::updateSdrBrightness() { - if (d->m_sdrBrightness != d->m_handle->sdrBrightness()) { - d->m_sdrBrightness = d->m_handle->sdrBrightness(); + if (d->m_referenceLuminance != d->m_handle->referenceLuminance()) { + d->m_referenceLuminance = d->m_handle->referenceLuminance(); const auto clientResources = d->resourceMap(); for (const auto &resource : clientResources) { d->sendSdrBrightness(resource); diff --git a/src/wayland/outputmanagement_v2.cpp b/src/wayland/outputmanagement_v2.cpp index 1e07df4469..2cda11138e 100644 --- a/src/wayland/outputmanagement_v2.cpp +++ b/src/wayland/outputmanagement_v2.cpp @@ -273,7 +273,7 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_set_sdr_brightn return; } if (OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice)) { - config.changeSet(output->handle())->sdrBrightness = sdr_brightness; + config.changeSet(output->handle())->referenceLuminance = sdr_brightness; } } diff --git a/src/wayland/xx_colormanagement_v2.cpp b/src/wayland/xx_colormanagement_v2.cpp index 6fff429a1c..13f8c6d3d5 100644 --- a/src/wayland/xx_colormanagement_v2.cpp +++ b/src/wayland/xx_colormanagement_v2.cpp @@ -148,11 +148,11 @@ void XXColorParametricCreatorV2::xx_image_description_creator_params_v2_create(R wl_resource_post_error(resource->handle, error::error_incomplete_set, "colorimetry or transfer function missing"); return; } - if (m_transferFunction != NamedTransferFunction::PerceptualQuantizer && (m_maxFrameAverageBrightness || m_maxPeakBrightness)) { + if (m_transferFunction != NamedTransferFunction::PerceptualQuantizer && (m_maxAverageLuminance || m_maxPeakBrightness)) { wl_resource_post_error(resource->handle, error::error_inconsistent_set, "max_cll and max_fall must only be set with the PQ transfer function"); return; } - new XXImageDescriptionV2(resource->client(), image_description, resource->version(), ColorDescription(*m_colorimetry, *m_transferFunction, 100, 0, m_maxFrameAverageBrightness.value_or(100), m_maxPeakBrightness.value_or(100))); + new XXImageDescriptionV2(resource->client(), image_description, resource->version(), ColorDescription(*m_colorimetry, *m_transferFunction, 100, 0, m_maxAverageLuminance.value_or(100), m_maxPeakBrightness.value_or(100))); wl_resource_destroy(resource->handle); } @@ -235,7 +235,7 @@ void XXColorParametricCreatorV2::xx_image_description_creator_params_v2_set_max_ void XXColorParametricCreatorV2::xx_image_description_creator_params_v2_set_max_fall(Resource *resource, uint32_t max_fall) { - m_maxFrameAverageBrightness = max_fall; + m_maxAverageLuminance = max_fall; } XXImageDescriptionV2::XXImageDescriptionV2(wl_client *client, uint32_t id, uint32_t version, const ColorDescription &color) diff --git a/src/wayland/xx_colormanagement_v2.h b/src/wayland/xx_colormanagement_v2.h index 1f7c16a177..957139d93f 100644 --- a/src/wayland/xx_colormanagement_v2.h +++ b/src/wayland/xx_colormanagement_v2.h @@ -70,7 +70,7 @@ private: std::optional m_colorimetry; std::optional m_transferFunction; - std::optional m_maxFrameAverageBrightness; + std::optional m_maxAverageLuminance; std::optional m_maxPeakBrightness; };