Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix cusp mapping mode to work properly with magentas.
Wolthera van Hövell tot Westerflierf987fb4e7357
diff --git a/libs/pigment/KoGamutMappingUtils.cpp b/libs/pigment/KoGamutMappingUtils.cppindex 766a6174b7..52f2fc1275 100644--- a/libs/pigment/KoGamutMappingUtils.cpp+++ b/libs/pigment/KoGamutMappingUtils.cpp@@ -333,23 +333,22 @@ QPointF KoGamutMappingUtils::cuspForHue(const QMap<float, QPointF> &gamutCuspDes{QPointF cusp;+ int foundAngle = -1;+for (int i = 0; i < gamutCuspDescription.size(); i++) {- const float angle = gamutCuspDescription.keys().at(i);- float nextAngle = gamutCuspDescription.keys().value(i+1, gamutCuspDescription.keys().first());- if (i +1 == gamutCuspDescription.size()) {- nextAngle += 1.0;- }- if (qFuzzyCompare(hue, angle)) {- cusp = gamutCuspDescription.value(angle);- break;- } else if (hue > angle && hue < nextAngle) {- QPointF lch1 = gamutCuspDescription.value(angle);- QPointF lch2 = gamutCuspDescription.value(nextAngle);- const float t = (hue - angle) / (nextAngle - angle);- cusp = QLineF(lch1, lch2).pointAt(t);+ if (hue < gamutCuspDescription.keys().at(i)) {break;}+ foundAngle = i;}+ if (foundAngle < 0) foundAngle = gamutCuspDescription.size()-1;+ const float angle = gamutCuspDescription.keys().at(foundAngle);+ float nextAngle = gamutCuspDescription.keys().value(foundAngle+1, gamutCuspDescription.keys().first());++ QPointF lch1 = gamutCuspDescription.value(angle);+ QPointF lch2 = gamutCuspDescription.value(nextAngle);+ const float t = (hue - angle) / (nextAngle - angle);+ cusp = QLineF(lch1, lch2).pointAt(t);return cusp;}diff --git a/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cpp b/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cppindex 1a35c27f81..2a3ea2c517 100644--- a/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cpp+++ b/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cpp@@ -47,8 +47,8 @@ struct xyzToOkLabModel {return channels;}- static ALWAYS_INLINE float linearizeLightness(float lightness) {- return powf(lightness, 3.0);+ static ALWAYS_INLINE float cuberootLightness(float lightness) {+ return lightness;}};@@ -76,8 +76,8 @@ struct xyzToICtCpModel {return channels;}- static ALWAYS_INLINE float linearizeLightness(float lightness) {- return removeSmpte2048Curve(lightness);+ static ALWAYS_INLINE float cuberootLightness(float lightness) {+ return cbrtf(removeSmpte2048Curve(lightness));}};@@ -97,8 +97,8 @@ struct labModel {return channels;}- static ALWAYS_INLINE float linearizeLightness(float lightness) {- return powf(lightness, 3.0);+ static ALWAYS_INLINE float cuberootLightness(float lightness) {+ return lightness;}};@@ -166,16 +166,18 @@ public:if (!m_cuspDescription.isEmpty()) {QPointF cusp = KoGamutMappingUtils::cuspForHue(m_cuspDescription, LCH[2]);- /// We are treating the cusp triangle as linear inside linear space.+ /// We are treating the cusp triangle as linear inside the SDR standard range.+ /// Within the standard range, cube root works better than hdr's PQ./// This is good enough for RGB profiles, CMYK profiles might get better/// results with the MINDE method. Overall though, we just want to move/// the colors into gamut enough so that we don't get hue shifts when converting,/// and this method delivers on that nicely.- const float L = ModelType::linearizeLightness(LCH[0]);- const float cuspL = ModelType::linearizeLightness(cusp.y());+ const float L = ModelType::cuberootLightness(LCH[0]);+ const float cuspL = ModelType::cuberootLightness(cusp.y());if (LCH[0] > cusp.y()) {const float t = (L - cuspL) / (1.0 - cuspL);const float c = qMax(0.0, cusp.x()* (1.0-t));+LCH[1] = qMin(LCH[1], c);} else {