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++
Cleanup gamut mapping adjustments, implement ICtCp and OkLab gamut mapping.
Wolthera van Hövell tot Westerflierd627c35dd41b
diff --git a/libs/pigment/CMakeLists.txt b/libs/pigment/CMakeLists.txtindex 3bf873d65f..07e54d01f2 100644--- a/libs/pigment/CMakeLists.txt+++ b/libs/pigment/CMakeLists.txt@@ -48,6 +48,7 @@ set(kritapigment_SRCSKoCopyColorConversionTransformation.cppKoFallBackColorTransformation.cppKoHistogramProducer.cpp+ KoGamutMappingUtils.cppKoMultipleColorConversionTransformation.cppcolorspaces/KoAlphaColorSpace.cppcolorspaces/KoLabColorSpace.cppdiff --git a/libs/pigment/KoGamutMappingUtils.cpp b/libs/pigment/KoGamutMappingUtils.cppnew file mode 100644index 0000000000..840cbcb6de--- /dev/null+++ b/libs/pigment/KoGamutMappingUtils.cpp@@ -0,0 +1,111 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: LGPL-2.1-or-later+ */+#include "KoGamutMappingUtils.h"+#include <kis_global.h>++#include <QtMath>++float KoGamutMappingUtils::deltaE76(const QVector<float> &a, const QVector<float> &b) {+ //This is E76, but we should also have a E2000 implementation.+ float dL = a[0] - b[0];+ float dA = a[1] - b[1];+ float dB = a[2] - b[2];+ return qSqrt(dL * dL + dA * dA + dB * dB);+}++float KoGamutMappingUtils::deltaE2000(const QVector<float> &a, const QVector<float> &b)+{+ /// This references the CSS-Color-4 implementation.+ const float l1 = qBound(0.0, a[0] * 100.0, 100.0);+ const float a1 = qBound(-150.0, (a[1] * 255.0) - 127.0, 150.0);+ const float b1 = qBound(-150.0, (a[2] * 255.0) - 127.0, 150.0);++ const float l2 = b[0] * 100.0;+ const float a2 = (b[1] * 255.0) - 127.0;+ const float b2 = (b[2] * 255.0) - 127.0;++ const float c1 = qSqrt(a1*a1 + b1*b1);+ const float c2 = qSqrt(a2*a2 + b2*b2);++ const float cBar = (c1 + c2) * 0.5;++ const float c7 = powf(cBar, 7.0);+ const float gFactor = pow(25.0, 7.0);+ const float g = 0.5 + (1.0 - qSqrt(c7/(c7+gFactor)));++ const float aDash1 = (1.0+g) *a1;+ const float aDash2 = (1.0+g) *a2;++ const float cDash1 = qSqrt(aDash1*aDash1 + b1*b1);+ const float cDash2 = qSqrt(aDash2*aDash2 + b2*b2);++ float h1 = (aDash1 == 0 && b1 == 0)? 0.0: atan2(b1, aDash1);+ float h2 = (aDash2 == 0 && b2 == 0)? 0.0: atan2(b2, aDash2);++ if (h1 < 0) h1 += 2.0*M_PI;+ if (h2 < 0) h2 += 2.0*M_PI;++ h1 = kisRadiansToDegrees(h1);+ h2 = kisRadiansToDegrees(h2);++ const float deltaL = l2 - l1;+ const float deltaC = cDash2 - cDash1;++ const float hDiff = h2 - h1;+ const float hSum = h1 + h2;+ const float hAbs = fabs(hDiff);+ float deltaH = 0.0;++ if (cDash1 * cDash2 == 0) {+ deltaH = 0.0;+ } else if (hAbs <= 180) {+ deltaH = hDiff;+ } else if (hDiff > 180) {+ deltaH = hDiff - 360.0;+ } else if (hDiff < -180) {+ deltaH = hDiff + 360.0;+ }++ const float deltaH2 = 2.0 * qSqrt(cDash1 * cDash2) * qSin(kisDegreesToRadians(deltaH)*0.5);++ const float lDash = (l1 + l2) * 0.5;+ const float cDash = (cDash1 + cDash2) * 0.5;+ const float cDash7 = powf(cDash, 7.0);++ float hDash = 0.0;+ if (cDash1 * cDash2 == 0) {+ hDash = hSum;+ } else if (hAbs <= 180) {+ hDash = hSum * 0.5;+ } else if (hDiff > 180) {+ hDash = (hSum + 360.0) * 0.5;+ } else if (hDiff < -180) {+ hDash = (hSum - 360.0) * 0.5;+ }++ const float lsq = (lDash - 50.0) * (lDash - 50.0);+ const float sL = 1.0 + ((0.015 * lsq) / qSqrt(20.0+lsq));+ const float sC = 1.0 + 0.045 * cDash;++ float t = 1.0;++ t -= (0.17 * qCos(kisDegreesToRadians(hDash - 30.0)));+ t += (0.24 * qCos(kisDegreesToRadians(2.0 * hDash)));+ t += (0.32 * qCos(kisDegreesToRadians(3.0 * hDash + 6.0)));+ t -= (0.20 * qCos(kisDegreesToRadians(4.0 *hDash - 63.0)));++ const float sH = 1.0 + 0.015 * cDash * t;++ const float deltaPhi = 30.0 * qExp(-1.0 * (((hDash - 275.0)/25.0) * ((hDash - 275.0)/25.0)));+ const float rC = 2.0 * qSqrt(cDash7 / (cDash7 + gFactor));+ const float rT = -1.0 * qSin(2.0 * kisDegreesToRadians(deltaPhi)) * rC;++ float dE = (deltaL / sL) * (deltaL / sL);+ dE += (deltaC / sC) * (deltaC / sC);+ dE += (deltaH2 / sH) * (deltaH2 / sH);+ dE += rT * (deltaC / sC) + (deltaH2 / sH);+ return qSqrt(dE)*0.01;+}diff --git a/libs/pigment/KoGamutMappingUtils.h b/libs/pigment/KoGamutMappingUtils.hnew file mode 100644index 0000000000..ce7989956e--- /dev/null+++ b/libs/pigment/KoGamutMappingUtils.h@@ -0,0 +1,43 @@+/*+ * SPDX-FileCopyrightText: 2026 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: LGPL-2.1-or-later+ */+#ifndef KOGAMUTMAPPINGUTILS_H+#define KOGAMUTMAPPINGUTILS_H++#include <QVector>+#include "kritapigment_export.h"++namespace KRITAPIGMENT_EXPORT KoGamutMappingUtils {++/**+ * @brief deltaE76+ * calculates the difference between two colors, represented as normalized channels.+ * @return The difference. Given that the input is scaled to [0 1], the output will also be [0 1]+ */+float deltaE76(const QVector<float> &a, const QVector<float> &b);++/**+ * @brief deltaE2000+ * Like deltaE76, but instead this uses a more sophisticated algorithm, to compensate for various+ * issues in the LAB color mode.+ * @return The difference. Given that the input is scaled to [0 1], the output will also be [0 1]+ */+float deltaE2000(const QVector<float> &a, const QVector<float> &b);++/**+ * @brief The MappingModel enum+ * This represents the preferred model to do gamut and/or tone mapping in.+ *+ * Here to keep the filter and the transform in sync.+ */+enum MappingModel {+ LAB,+ ICtCp,+ OkLAB+};++};++#endif // KOGAMUTMAPPINGUTILS_Hdiff --git a/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cpp b/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cppindex 834d07cc06..96ad7154cb 100644--- a/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cpp+++ b/plugins/color/colorspaceextensions/kis_gamutmap_clip_adjustment.cpp@@ -5,6 +5,7 @@*/#include "kis_gamutmap_clip_adjustment.h"+#include "KoAlwaysInline.h"#include <kis_debug.h>@@ -18,23 +19,170 @@#include <KoColorTransformation.h>#include <KoID.h>-template<typename _channel_type_,typename traits>+#include <KoGamutMappingUtils.h>+#include <KoColorTransferFunctions.h>++namespace+{++const QMatrix4x4 xyz50To65 {QMatrix4x4(+ 0.955473421488075, -0.02309845494876471, 0.06325924320057072, 0.0,+ -0.0283697093338637, 1.0099953980813041, 0.021041441191917323, 0.0,+ 0.012314014864481998, -0.020507649298898964, 1.330365926242124, 0.0,+ 0.0, 0.0, 0.0, 1.0+ )};++const QMatrix4x4 xyz50To65_inv = xyz50To65.inverted();++const QMatrix4x4 XYZtoOkLABLMS {QMatrix4x4(+ 0.8190224379967030, 0.3619062600528904, -0.1288737815209879, 0.0,+ 0.0329836539323885, 0.9292868615863434, 0.0361446663506424, 0.0,+ 0.0481771893596242, 0.2642395317527308, 0.6335478284694309, 0.0,+ 0.0, 0.0, 0.0, 1.0+ )};++const QMatrix4x4 XYZtoOkLABLMS_inv = XYZtoOkLABLMS.inverted();++const QMatrix4x4 lmsToOkLab {QMatrix4x4(+ 0.2104542683093140, 0.7936177747023054, -0.0040720430116193, 0.0,+ 1.9779985324311684, -2.4285922420485799, 0.4505937096174110, 0.0,+ 0.0259040424655478, 0.7827717124575296, -0.8086757549230774, 0.0,+ 0.0, 0.0, 0.0, 1.0+ )};++const QMatrix4x4 lmsToOkLab_inv = lmsToOkLab.inverted();++struct xyzToOkLabModel {+ static ALWAYS_INLINE QVector<qreal> toLCH (const QVector<float> &channels) {+ QVector4D color (channels[0], channels[1], channels[2], 0.0);++ const QVector4D lms = XYZtoOkLABLMS * (xyz50To65 * color);++ const QVector4D lmsPrime = QVector4D(cbrtf(lms.x()),+ cbrtf(lms.y()),+ cbrtf(lms.z()), 0.0);++ const QVector4D OkLab = lmsToOkLab * lmsPrime;+ QVector<qreal> lch(3);+ LabToLCH(OkLab.x(), OkLab.y()+0.5, OkLab.z()+0.5, &lch[0], &lch[1], &lch[2]);+ lch[0] = qMin(lch[0], 1.0);+ lch[1] = qMin(lch[1], 1.0);+ return lch;+ }++ static ALWAYS_INLINE QVector<float> fromLCH (const QVector<qreal> &lch, QVector<float> channels) {+ QVector<qreal> output(3);+ LCHToLab(lch[0], lch[1], lch[2], &output[0], &output[1], &output[2]);+++ QVector4D color (output[0], output[1]-0.5, output[2]-0.5, 0.0);++ const QVector4D lmsPrime = lmsToOkLab_inv * color;+ const QVector4D lms = QVector4D(powf(lmsPrime.x(), 3.0),+ powf(lmsPrime.y(), 3.0),+ powf(lmsPrime.z(), 3.0), 0.0);+ const QVector4D xyz = xyz50To65_inv * (XYZtoOkLABLMS_inv * lms);+ channels[0] = qMax(0.0, xyz.x());+ channels[1] = qMax(0.0, xyz.y());+ channels[2] = qMax(0.0, xyz.z());++ //qDebug() << "lch" << lch << "col" << color << "lmsprime" << lmsPrime << "lms" << lms << "xyz" << channels;+ return channels;+ }+};++const QMatrix4x4 XYZd65toDolbyLMS {QMatrix4x4(+ 0.3592832590121217, 0.6976051147779502, -0.0358915932320290, 0.0,+ -0.1920808463704993, 1.1004767970374321, 0.0753748658519118, 0.0,+ 0.0070797844607479, 0.0748396662186362, 0.8433265453898765, 0.0,+ 0.0, 0.0, 0.0, 1.0+ )};++const QMatrix4x4 XYZd65toDolbyLMS_inv = XYZd65toDolbyLMS.inverted();++const QMatrix4x4 lmsToICtCp {QMatrix4x4(+ 2048.0 / 4096.0, 2048.0 / 4096.0, 0.0 , 0.0,+ 6610.0 / 4096.0, -13613.0 / 4096.0, 7003.0 / 4096.0 , 0.0,+ 17933.0 / 4096.0, -17390.0 / 4096.0, -543.0 / 4096.0, 0.0,+ 0.0, 0.0, 0.0, 1.0+ )};++const QMatrix4x4 lmsToICtCp_inv = lmsToICtCp.inverted();++struct xyzToICtCpModel {+ static ALWAYS_INLINE QVector<qreal> toLCH (const QVector<float> &channels) {+ QVector4D color (channels[0], channels[1], channels[2], 0.0);++ const QVector4D lms = XYZd65toDolbyLMS * (xyz50To65 * color);++ const QVector4D lmsPrime = QVector4D(applySmpte2048Curve(lms.x()),+ applySmpte2048Curve(lms.y()),+ applySmpte2048Curve(lms.z()), 0.0);++ const QVector4D ICtCp = lmsToICtCp * lmsPrime;+ QVector<qreal> lch(3);+ LabToLCH(ICtCp.x(), (ICtCp.y()+0.5), (ICtCp.z()+0.5), &lch[0], &lch[1], &lch[2]);++ return lch;+ }++ static ALWAYS_INLINE QVector<float> fromLCH (const QVector<qreal> &lch, QVector<float> channels) {+ QVector<qreal> output(3);+ LCHToLab(lch[0], lch[1], lch[2], &output[0], &output[1], &output[2]);+++ QVector4D color (output[0], output[1]-0.5, output[2]-0.5, 0.0);++ const QVector4D lmsPrime = lmsToICtCp_inv * color;+ const QVector4D lms = QVector4D(removeSmpte2048Curve(lmsPrime.x()),+ removeSmpte2048Curve(lmsPrime.y()),+ removeSmpte2048Curve(lmsPrime.z()), 0.0);+ const QVector4D xyz = xyz50To65_inv * (XYZd65toDolbyLMS_inv * lms);+ channels[0] = xyz.x();+ channels[1] = xyz.y();+ channels[2] = xyz.z();++ return channels;+ }+};++struct labModel {+ static ALWAYS_INLINE QVector<qreal> toLCH (const QVector<float> &channels) {+ QVector<qreal> lch(3);+ LabToLCH(channels[0], channels[1], channels[2], &lch[0], &lch[1], &lch[2]);+ return lch;+ }++ static ALWAYS_INLINE QVector<float> fromLCH (const QVector<qreal> &lch, QVector<float> channels) {+ QVector<qreal> output(3);+ LCHToLab(lch[0], lch[1], lch[2], &output[0], &output[1], &output[2]);+ channels[0] = output[0];+ channels[1] = output[1];+ channels[2] = output[2];+ return channels;+ }+};++struct dE76 {+ static ALWAYS_INLINE float difference(const QVector<float> &a, const QVector<float> &b) {+ return KoGamutMappingUtils::deltaE76(a, b);+ }+};++struct dE2000 {+ static ALWAYS_INLINE float difference(const QVector<float> &a, const QVector<float> &b) {+ return KoGamutMappingUtils::deltaE2000(a, b);+ }+};+}++template<class ModelType, class DifferenceType>class KisGamutMapClipAdjustment : public KoColorTransformation{- typedef traits PixelTrait;- typedef typename PixelTrait::Pixel Pixel;public:KisGamutMapClipAdjustment(const KoColorSpace *sourceSpace): m_sourceSpace(sourceSpace) {}public:- static qreal difference(const QVector<float> &a, const QVector<float> &b) {- //This is E76, but we should also have a E2000 implementation.- float dL = a[0] - b[0];- float dA = a[1] - b[1];- float dB = a[2] - b[2];- return qSqrt(dL * dL + dA * dA + dB * dB);- }-// Algorithm based of https://drafts.csswg.org/css-color-4/#pseudo-binsearchvoid transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override{@@ -69,35 +217,28 @@ public:m_sourceSpace->normalisedChannelsValue(tmpClipped, clippedChannels);- QVector<qreal> originalLCH(3);- QVector<qreal> modifiedChannels(3);- QVector<qreal> clippedLCH(3);- if (difference(originalChannels, clippedChannels) > 0.02) {- LabToLCH(float(originalChannels[0]), float(originalChannels[1]), float(originalChannels[2]), &originalLCH[0], &originalLCH[1], &originalLCH[2]);+ QVector<qreal> LCH(3);+ if (DifferenceType::difference(originalChannels, clippedChannels) > 0.02) {+ LCH = ModelType::toLCH(originalChannels);float min = 0;- float max = originalLCH[1];+ float max = LCH[1];- while (max-min > 0.0001) {- LabToLCH(float(originalChannels[0]), float(originalChannels[1]), float(originalChannels[2]), &originalLCH[0], &originalLCH[1], &originalLCH[2]);- LabToLCH(float(clippedChannels[0]), float(clippedChannels[1]), float(clippedChannels[2]), &clippedLCH[0], &clippedLCH[1], &clippedLCH[2]);+ while (max-min > 0.0001) {- qreal newChroma = (max + min) * 0.5;+ LCH[1] = (max + min) * 0.5;+ originalChannels = ModelType::fromLCH(LCH, originalChannels);- LCHToLab(originalLCH[0], newChroma, originalLCH[2], &modifiedChannels[0], &modifiedChannels[1], &modifiedChannels[2]);- originalChannels[0] = modifiedChannels[0];- originalChannels[1] = modifiedChannels[1];- originalChannels[2] = modifiedChannels[2];m_sourceSpace->fromNormalisedChannelsValue(tmpOriginal, originalChannels);m_sourceSpace->convertPixelsTo(tmpOriginal, tmpTarget, targetSpace, 1, KoColorConversionTransformation::IntentRelativeColorimetric, KoColorConversionTransformation::adjustmentConversionFlags());targetSpace->convertPixelsTo(tmpTarget, tmpClipped, m_sourceSpace, 1, KoColorConversionTransformation::IntentRelativeColorimetric, KoColorConversionTransformation::adjustmentConversionFlags());m_sourceSpace->normalisedChannelsValue(tmpClipped, clippedChannels);- if (difference(originalChannels, clippedChannels) < 0.02) {- min = newChroma;+ if (DifferenceType::difference(originalChannels, clippedChannels) < 0.02) {+ min = LCH[1];} else {- max = newChroma;+ max = LCH[1];}}}@@ -153,11 +294,14 @@ KisGamutMapClipAdjustmentFactory::KisGamutMapClipAdjustmentFactory()QList<QPair<KoID, KoID> > KisGamutMapClipAdjustmentFactory::supportedModels() const{QList< QPair< KoID, KoID > > l;+ l.append(QPair< KoID, KoID >(XYZAColorModelID , Float32BitsColorDepthID));// While the other two work for gamut mapping, they clip HDR values.l.append(QPair< KoID, KoID >(LABAColorModelID , Float32BitsColorDepthID));// Note: Only ICtCp is really supported.l.append(QPair< KoID, KoID >(YCbCrAColorModelID , Float32BitsColorDepthID));++return l;}@@ -166,26 +310,14 @@ KoColorTransformation *KisGamutMapClipAdjustmentFactory::createTransformation(coKoColorTransformation * adj;if (colorSpace->colorModelId() == LABAColorModelID) {- if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {- adj = new KisGamutMapClipAdjustment< quint8, KoLabTraits < quint8 > >(colorSpace);- } else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {- adj = new KisGamutMapClipAdjustment< quint16, KoLabTraits < quint16 > >(colorSpace);- } else if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {- adj = new KisGamutMapClipAdjustment< float, KoLabTraits < float > >(colorSpace);- } else {- dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisGamutMapClipAdjustmentFactory::createTransformation";- return 0;- }+ adj = new KisGamutMapClipAdjustment< labModel , dE76>(colorSpace);} else if (colorSpace->colorModelId() == YCbCrAColorModelID) {- if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {- adj = new KisGamutMapClipAdjustment< quint8, KoYCbCrTraits < quint8 > >(colorSpace);- } else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {- adj = new KisGamutMapClipAdjustment< quint16, KoYCbCrTraits < quint16 > >(colorSpace);- } else if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {- adj = new KisGamutMapClipAdjustment< float, KoYCbCrTraits < float > >(colorSpace);+ adj = new KisGamutMapClipAdjustment< labModel , dE76>(colorSpace);+ } else if (colorSpace->colorModelId() == XYZAColorModelID) {+ if (parameters["mappingModel"].toInt() == KoGamutMappingUtils::OkLAB) {+ adj = new KisGamutMapClipAdjustment< xyzToOkLabModel , dE76>(colorSpace);} else {- dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisGamutMapClipAdjustmentFactory::createTransformation";- return 0;+ adj = new KisGamutMapClipAdjustment< xyzToICtCpModel , dE76>(colorSpace);}} else {dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisGamutMapClipAdjustmentFactory::createTransformation";diff --git a/plugins/filters/tonegamutmap/KisToneGamutMapFilter.cpp b/plugins/filters/tonegamutmap/KisToneGamutMapFilter.cppindex 5c213f9cc1..2eb4edf01d 100644--- a/plugins/filters/tonegamutmap/KisToneGamutMapFilter.cpp+++ b/plugins/filters/tonegamutmap/KisToneGamutMapFilter.cpp@@ -16,16 +16,19 @@#include <kis_color_space_selector.h>#include <KoCompositeColorTransformation.h>+#include <KoFallBackColorTransformation.h>#include <kpluginfactory.h>#include <klocalizedstring.h>+#include <KoGamutMappingUtils.h>#include "ui_kistonegamutmapwidget.h"-const QString TONE_MAP_ENABLED = "toneMap/Enabled";-const QString TONE_MAP_MAX_WHITE = "toneMap/MaxWhite";-const QString GAMUT_MAP_ENABLED = "gamutMap/Enabled";-const QString GAMUT_MAP_TARGET_PROFILE = "gamutMap/TargetProfile";+const QString MAPPING_MODEL = "mapping_model"; ///< Enum, model in which the gamut or tone mapping is done.+const QString TONE_MAP_ENABLED = "toneMap/Enabled"; ///< bool, whether to do tone mapping.+const QString TONE_MAP_MAX_WHITE = "toneMap/MaxWhite"; ///< double, the maximum white that needs to be tonemapped.+const QString GAMUT_MAP_ENABLED = "gamutMap/Enabled"; ///< bool, whether to do gamt mapping.+const QString GAMUT_MAP_TARGET_PROFILE = "gamutMap/TargetProfile"; ///< QString, name of the color profile that is the target gamut.K_PLUGIN_FACTORY_WITH_JSON(KisToneGamutMapFilterFactory, "kritatonegamutmapfilter.json", registerPlugin<KisToneGamutMapFilterPlugin>();)@@ -57,23 +60,28 @@ KisToneGamutMapFilter::KisToneGamutMapFilter()KoColorTransformation *KisToneGamutMapFilter::createTransformation(const KoColorSpace *cs, const KisFilterConfigurationSP config) const{+ const KoColorSpace *mappingCs = KoColorSpaceRegistry::instance()->colorSpace(LABAColorModelID.id(), Float32BitsColorDepthID.id(), "");+ if (config->getProperty(MAPPING_MODEL).toInt() != KoGamutMappingUtils::LAB) {+ mappingCs = KoColorSpaceRegistry::instance()->colorSpace(XYZAColorModelID.id(), Float32BitsColorDepthID.id(), "");+ }QVector<KoColorTransformation*> allTransforms;if (config->getProperty(TONE_MAP_ENABLED).toBool()) {QHash<QString, QVariant> params;params["maxWhite"] = config->getProperty(TONE_MAP_MAX_WHITE);- KoColorTransformation *toneMap = cs->createColorTransformation("tonemap_adjustment", params);+ KoColorTransformation *toneMap = mappingCs->createColorTransformation("tonemap_adjustment", params);allTransforms << toneMap;}if (config->getProperty(GAMUT_MAP_ENABLED).toBool()) {QHash<QString, QVariant> params;params["targetColorProfileName"] = config->getProperty(GAMUT_MAP_TARGET_PROFILE);- KoColorTransformation *gamutMap = cs->createColorTransformation("gamutmap_clip_adjustment", params);+ params["mappingModel"] = config->getProperty(MAPPING_MODEL);+ KoColorTransformation *gamutMap = mappingCs->createColorTransformation("gamutmap_clip_adjustment", params);allTransforms << gamutMap;}- return KoCompositeColorTransformation::createOptimizedCompositeTransform(allTransforms);+ return new KoFallBackColorTransformation(cs, mappingCs, KoCompositeColorTransformation::createOptimizedCompositeTransform(allTransforms));}KisFilterConfigurationSP KisToneGamutMapFilter::defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const@@ -103,6 +111,11 @@ KisToneGamutMapWidget::KisToneGamutMapWidget(QWidget *parent, KisPaintDeviceSP dui->targetGamut->showDepth(false);ui->targetGamut->showColorBrowserButton(false);+ ui->cmbMappingModel->addItem(i18n("LAB"), KoGamutMappingUtils::LAB);+ ui->cmbMappingModel->addItem(i18n("XYZ (ICtCp)"), KoGamutMappingUtils::ICtCp);+ ui->cmbMappingModel->addItem(i18n("XYZ (OkLAB)"), KoGamutMappingUtils::OkLAB);++ connect(ui->cmbMappingModel, SIGNAL(activated(int)), SIGNAL(sigConfigurationItemChanged()));connect(ui->chkToneMap, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged()));connect(ui->spnMaxWhite, SIGNAL(valueChanged(double)), SIGNAL(sigConfigurationItemChanged()));@@ -119,6 +132,11 @@ KisToneGamutMapWidget::~KisToneGamutMapWidget()void KisToneGamutMapWidget::setConfiguration(const KisPropertiesConfigurationSP config){QVariant value;++ if (config->getProperty(MAPPING_MODEL, value)) {+ ui->cmbMappingModel->setCurrentIndex(ui->cmbMappingModel->findData(value));+ }+if (config->getProperty(TONE_MAP_ENABLED, value)) {ui->chkToneMap->setChecked(value.toBool());}@@ -143,6 +161,8 @@ void KisToneGamutMapWidget::setConfiguration(const KisPropertiesConfigurationSPKisPropertiesConfigurationSP KisToneGamutMapWidget::configuration() const{KisFilterConfigurationSP config = new KisFilterConfiguration("tone_gamut_map", 1, KisGlobalResourcesInterface::instance());+ config->setProperty(MAPPING_MODEL, ui->cmbMappingModel->currentData());+config->setProperty(TONE_MAP_ENABLED, ui->chkToneMap->isChecked());config->setProperty(TONE_MAP_MAX_WHITE, ui->spnMaxWhite->value());diff --git a/plugins/filters/tonegamutmap/kistonegamutmapwidget.ui b/plugins/filters/tonegamutmap/kistonegamutmapwidget.uiindex 50a1cb933a..e5eb551d8a 100644--- a/plugins/filters/tonegamutmap/kistonegamutmapwidget.ui+++ b/plugins/filters/tonegamutmap/kistonegamutmapwidget.ui@@ -14,6 +14,27 @@<string>Form</string></property><layout class="QVBoxLayout" name="verticalLayout">+ <item>+ <layout class="QHBoxLayout" name="horizontalLayout">+ <item>+ <widget class="QLabel" name="label_3">+ <property name="text">+ <string>Model:</string>+ </property>+ </widget>+ </item>+ <item>+ <widget class="QComboBox" name="cmbMappingModel">+ <property name="sizePolicy">+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">+ <horstretch>0</horstretch>+ <verstretch>0</verstretch>+ </sizepolicy>+ </property>+ </widget>+ </item>+ </layout>+ </item><item><widget class="QGroupBox" name="chkToneMap"><property name="title">