[graphics/krita] plugins/dockers/smallcolorselector: Fix reference white point in KisSmallColorWidget

Wolthera van Hövell <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 2050199a9a30b4096a9c1bbf5afdd8d07c31872e by Wolthera van Hövell, on behalf of Dmitry Kazakov.
Committed on 16/07/2026 at 16:26.
Pushed by woltherav into branch 'master'.

Fix reference white point in KisSmallColorWidget

We scale the linear values to pass them into a PQ
color space of the screen, this way we (kind of)
guarantee that the colors displayed by the small
color selector have exact brightness set by the
slider.

Ideally, the reference white point of the image
and the output surface should be adjusted. But
that is not very true on Windows right now.

M  +11   -5    plugins/dockers/smallcolorselector/kis_small_color_widget.cc

https://invent.kde.org/graphics/krita/-/commit/2050199a9a30b4096a9c1bbf5afdd8d07c31872e

diff --git a/plugins/dockers/smallcolorselector/kis_small_color_widget.cc b/plugins/dockers/smallcolorselector/kis_small_color_widget.cc
index 63c33a09320..48e40dad9c6 100644
--- a/plugins/dockers/smallcolorselector/kis_small_color_widget.cc
+++ b/plugins/dockers/smallcolorselector/kis_small_color_widget.cc
@@ -54,7 +54,7 @@ struct KisSmallColorWidget::Private {
     int huePreferredHeight = 32;
     KisSliderSpinBox *dynamicRange = 0;
     qreal currentRelativeDynamicRange = 1.0;
-    qreal currenReferenceWhite = 80.0;
+    qreal currenOutputReferenceWhite = 80.0;
     KisDisplayColorConverter *displayColorConverter = KisDisplayColorConverter::dumbConverterInstance();
     KisSignalAutoConnectionsStore colorConverterConnections;
     bool hasHDR = false;
@@ -183,7 +183,7 @@ KisSmallColorWidget::KisSmallColorWidget(QWidget* parent)
         d->dynamicRange->setSingleStep(1);
         d->dynamicRange->setPageStep(100);
         d->dynamicRange->setSuffix("cd/m²");
-        d->dynamicRange->setValue(d->currenReferenceWhite * d->currentRelativeDynamicRange);
+        d->dynamicRange->setValue(d->currenOutputReferenceWhite * d->currentRelativeDynamicRange);
         connect(d->dynamicRange, SIGNAL(valueChanged(int)), SLOT(slotInitiateUpdateDynamicRange(int)));
     }
 
@@ -269,7 +269,7 @@ void KisSmallColorWidget::setColor(const KoColor &color)
         if (rangeCoeff < r || rangeCoeff < g || rangeCoeff < b) {
             rangeCoeff = std::max({r, g, b}) * 1.10f;
 
-            const int newMaxLuminance = qRound(d->currenReferenceWhite * rangeCoeff);
+            const int newMaxLuminance = qRound(d->currenOutputReferenceWhite * rangeCoeff);
             updateDynamicRange(newMaxLuminance);
             d->dynamicRange->setValue(newMaxLuminance);
         }
@@ -434,7 +434,7 @@ void KisSmallColorWidget::slotInitiateUpdateDynamicRange(int maxLuminance)
 void KisSmallColorWidget::updateDynamicRange(int maxLuminance)
 {
     const qreal oldRange = d->currentRelativeDynamicRange;
-    const qreal newRange = qreal(maxLuminance) / d->currenReferenceWhite;
+    const qreal newRange = qreal(maxLuminance) / d->currenOutputReferenceWhite;
 
     if (qFuzzyCompare(oldRange, newRange)) return;
 
@@ -493,7 +493,13 @@ void KisSmallColorWidget::slotDisplayConfigurationChanged()
                  cs->profile()->getTransferCharacteristics() == TRC_ITU_R_BT_2100_0_PQ);
 
         if (d->hasHDR) {
-            d->currenReferenceWhite = cs->profile()->hdrReferenceWhite().value_or(80.0);
+            const KoColorSpace *outputColorSpace = d->outputColorSpace();
+            if (!outputColorSpace->profile()->hdrReferenceWhite()) {
+                qWarning() << "WARNING: KisSmallColorWidget::slotDisplayConfigurationChanged(): output color space is "
+                              "not a PQ space, the meaning of the range slider may be wrong!";
+            }
+
+            d->currenOutputReferenceWhite = outputColorSpace->profile()->hdrReferenceWhite().value_or(80.0);
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.