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 RGB-based blendmodes in floating-point colorspaces
Dmitry Kazakovc012a01a306e
diff --git a/libs/pigment/KoColorSpaceMaths.h b/libs/pigment/KoColorSpaceMaths.hindex 65dc6c1813..35f177e632 100644--- a/libs/pigment/KoColorSpaceMaths.h+++ b/libs/pigment/KoColorSpaceMaths.h@@ -915,6 +915,8 @@ struct HSYTypeinline static TReal getSaturation(TReal r, TReal g, TReal b) {return Arithmetic::max(r,g,b) - Arithmetic::min(r,g,b);}++ static constexpr bool lightnessIsAverage = true;};struct HSIType@@ -933,6 +935,8 @@ struct HSITypereturn (chroma > std::numeric_limits<TReal>::epsilon()) ?(TReal(1.0) - min / getLightness(r, g, b)) : TReal(0.0);}++ static constexpr bool lightnessIsAverage = true;};struct HSLType@@ -957,6 +961,8 @@ struct HSLTypereturn TReal(0.0);}++ static constexpr bool lightnessIsAverage = true;};struct HSVType@@ -970,8 +976,10 @@ struct HSVTypeinline static TReal getSaturation(TReal r, TReal g, TReal b) {TReal max = Arithmetic::max(r, g, b);TReal min = Arithmetic::min(r, g, b);- return (max == TReal(0.0)) ? TReal(0.0) : (max - min) / max;+ return (max > std::numeric_limits<TReal>::epsilon()) ? (max - min) / max : TReal(0.0);}++ static constexpr bool lightnessIsAverage = false;};template<class TReal>@@ -1039,34 +1047,88 @@ inline static TReal getLightness(TReal r, TReal g, TReal b) {}template<class HSXType, class TReal>-inline void addLightness(TReal& r, TReal& g, TReal& b, TReal light)+inline void ToneMapping(TReal& r, TReal& g, TReal& b){using namespace Arithmetic;-- r += light;- g += light;- b += light;-++TReal l = HSXType::getLightness(r, g, b);TReal n = min(r, g, b);TReal x = max(r, g, b);-+if(n < TReal(0.0)) {- TReal iln = TReal(1.0) / (l-n);- r = l + ((r-l) * l) * iln;- g = l + ((g-l) * l) * iln;- b = l + ((b-l) * l) * iln;+ if (isZeroValueClampedFuzzy<float>(l)) {+ /**+ * The tonemapping method we use does **not** support lightness+ * values below 0.0, so we just clamp the value.+ *+ * TODO: use proper HSV/HSI shape-tracking clamping methods we use+ * in kis_hsv_adjustment.cpp+ */+ r = g = b = TReal(0.0);+ } else {+ const TReal stretch = l - n;++ if (stretch < std::numeric_limits<TReal>::epsilon()) {+ r = g = b = TReal(0.0);+ } else {+ TReal iln = TReal(1.0) / stretch;+ r = l + ((r-l) * l) * iln;+ g = l + ((g-l) * l) * iln;+ b = l + ((b-l) * l) * iln;+ }+ }}-- if(x > TReal(1.0) && (x-l) > std::numeric_limits<TReal>::epsilon()) {- TReal il = TReal(1.0) - l;- TReal ixl = TReal(1.0) / (x - l);- r = l + ((r-l) * il) * ixl;- g = l + ((g-l) * il) * ixl;- b = l + ((b-l) * il) * ixl;++ if(x > TReal(1.0)) {+ auto setFallbackValues = [&] () {+ if constexpr (HSXType::lightnessIsAverage) {+ r = g = b = TReal(1.0);+ } else {+ r = qMin(r, TReal(1.0));+ g = qMin(g, TReal(1.0));+ b = qMin(b, TReal(1.0));+ }+ };++ if (l > TReal(1.0)) {+ /**+ * The tonemapping method we use does **not** support lightness+ * values above 1.0, so we just clamp the value.+ *+ * TODO: use proper HSV/HSI shape-tracking clamping methods we use+ * in kis_hsv_adjustment.cpp+ */+ setFallbackValues();+ } else {+ const TReal stretch = x - l;++ if (stretch < std::numeric_limits<TReal>::epsilon()) {+ setFallbackValues();+ } else {+ TReal il = TReal(1.0) - l;+ TReal ixl = TReal(1.0) / stretch;++ r = l + ((r-l) * il) * ixl;+ g = l + ((g-l) * il) * ixl;+ b = l + ((b-l) * il) * ixl;+ }+ }}}+template<class HSXType, class TReal>+inline void addLightness(TReal& r, TReal& g, TReal& b, TReal light)+{+ using namespace Arithmetic;++ r += light;+ g += light;+ b += light;++ ToneMapping<HSXType, TReal>(r, g, b);+}+template<class HSXType, class TReal>inline void setLightness(TReal& r, TReal& g, TReal& b, TReal light){@@ -1104,7 +1166,7 @@ inline void setSaturation(TReal& r, TReal& g, TReal& b, TReal sat)mid = tmp;}- if((rgb[max] - rgb[min]) > TReal(0.0)) {+ if((rgb[max] - rgb[min]) > std::numeric_limits<TReal>::epsilon()) {rgb[mid] = ((rgb[mid]-rgb[min]) * sat) / (rgb[max]-rgb[min]);rgb[max] = sat;rgb[min] = TReal(0.0);@@ -1116,65 +1178,4 @@ inline void setSaturation(TReal& r, TReal& g, TReal& b, TReal sat)else r = g = b = TReal(0.0);}-template<class HSXType, class TReal>-inline void ToneMapping(TReal& r, TReal& g, TReal& b)-{- using namespace Arithmetic;--- TReal l = HSXType::getLightness(r, g, b);- TReal n = min(r, g, b);- TReal x = max(r, g, b);-- TReal _r,_g,_b;-- if(n < TReal(0.0)) {- TReal iln = TReal(1.0) / (l-n);- r = l + ((r-l) * l) * iln;- g = l + ((g-l) * l) * iln;- b = l + ((b-l) * l) * iln;- }-- if(x > TReal(1.0) && (x-l) > std::numeric_limits<TReal>::epsilon())- {- TReal il = TReal(1.0) - l;- TReal ixl = TReal(1.0) / (x - l);- _r = l + ((r-l) * il) * ixl;- _g = l + ((g-l) * il) * ixl;- _b = l + ((b-l) * il) * ixl;-- if(r >= _r)- {- if(r > 1.0){- r = 1.0;- }- }- else- {- r = _r;- }-- if(g >= _g)- {- if(g > 1.0){- g = 1.0;- }- }- else- {- g = _g;- }-- if(b >= _b)- {- if(b > 1.0){- b = 1.0;- }- }- else- {- b = _b;- }- }-}#endifdiff --git a/libs/pigment/compositeops/KoCompositeOpFunctions.h b/libs/pigment/compositeops/KoCompositeOpFunctions.hindex 58ef32b574..6d511740dc 100644--- a/libs/pigment/compositeops/KoCompositeOpFunctions.h+++ b/libs/pigment/compositeops/KoCompositeOpFunctions.h@@ -18,196 +18,296 @@#include "half.h"#endif-template<class HSXType, class TReal>-inline void cfReorientedNormalMapCombine(TReal srcR, TReal srcG, TReal srcB, TReal& dstR, TReal& dstG, TReal& dstB)+namespace {+template<typename channels_type>+inline void possiblyFixNegativeValuesNearZeroPoint(float& dstR, float& dstG, float& dstB){- // see https://blog.selfshadow.com/publications/blending-in-detail/ by Barre-Brisebois and Hill- TReal tx = 2*srcR-1;- TReal ty = 2*srcG-1;- TReal tz = 2*srcB;- TReal ux = -2*dstR+1;- TReal uy = -2*dstG+1;- TReal uz = 2*dstB-1;- TReal k = (tx*ux+ty*uy+tz*uz)/tz; // dot(t,u)/t.z- TReal rx = tx*k-ux;- TReal ry = ty*k-uy;- TReal rz = tz*k-uz;- k = 1/sqrt(rx*rx+ry*ry+rz*rz); // normalize result- rx *= k;- ry *= k;- rz *= k;- dstR = rx*0.5+0.5;- dstG = ry*0.5+0.5;- dstB = rz*0.5+0.5;+ /**+ * Some RGB-based blendmodes may generate slightly negative values after+ * applying setLightness(), so we should clamp them if the destination+ * channel is not of an integer type+ */+ if constexpr (!std::numeric_limits<channels_type>::is_integer) {+ dstR = qMax(dstR, 0.0f);+ dstG = qMax(dstG, 0.0f);+ dstB = qMax(dstB, 0.0f);+ }}-template<class HSXType, class TReal>-inline void cfColor(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- TReal lum = getLightness<HSXType>(dr, dg, db);- dr = sr;- dg = sg;- db = sb;- setLightness<HSXType>(dr, dg, db, lum);+template<typename channels_type>+inline void possiblyClampValuesToSDR(float& dstR, float& dstG, float& dstB)+{+ /**+ * Some RGB-based modes may go out of the SDR-range, e.g. tangent-normal,+ * so we should clamp them in case the target colorspace is not an integer+ * and is not going to be clamped later.+ */+ if constexpr (!std::numeric_limits<channels_type>::is_integer) {+ dstR = qBound(0.0f, dstR, 1.0f);+ dstG = qBound(0.0f, dstG, 1.0f);+ dstB = qBound(0.0f, dstB, 1.0f);+ }+}}-template<class HSXType, class TReal>-inline void cfLambertLighting(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db)+template<class HSXType, typename channels_type>+struct CFReorientedNormalMapCombine : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>{- TReal tr = sr * dr * (1.0 / 0.215686);- TReal tg = sg * dg * (1.0 / 0.215686);- TReal tb = sb * db * (1.0 / 0.215686);-- if (tr > 1.0) {- dr = 1.0 + (tr - 1.0) * (tr - 1.0) * 0.01925;- }- else {- dr = tr;- }-- if (tg > 1.0) {- dg = 1.0 + (tg - 1.0) * (tg - 1.0) * 0.01925;- }- else {- dg = tg;- }-- if (tb > 1.0) {- db = 1.0 + (tb - 1.0) * (tb - 1.0) * 0.01925;- }- else {- db = tb;- }--- ToneMapping<HSXType, TReal>(dr, dg, db);-}+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ // see https://blog.selfshadow.com/publications/blending-in-detail/ by Barre-Brisebois and Hill-template<class HSXType, class TReal>-inline void cfLambertLightingGamma2_2(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- TReal tr = sr * dr * 2.0;- TReal tg = sg * dg * 2.0;- TReal tb = sb * db * 2.0;-- if (tr > 1.0) {- dr = 1.0 + (tr - 1.0) * (tr - 1.0) * 0.4;- }- else {- dr = tr;- }-- if (tg > 1.0) {- dg = 1.0 + (tg - 1.0) * (tg - 1.0) * 0.4;- }- else {- dg = tg;- }-- if (tb > 1.0) {- db = 1.0 + (tb - 1.0) * (tb - 1.0) * 0.4;- }- else {- db = tb;- }-- ToneMapping<HSXType, TReal>(dr, dg, db);-}+ using namespace Arithmetic;-template<class HSXType, class TReal>-inline void cfLightness(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- setLightness<HSXType>(dr, dg, db, getLightness<HSXType>(sr, sg, sb));-}+ /**+ * If the source vector has zero height, then we should just+ * skip all the changes (with seems to be the bahavior of the+ * formula around the null point)+ */+ if (isZeroValueFuzzy(srcB)) {+ return;+ }-template<class HSXType, class TReal>-inline void cfIncreaseLightness(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- addLightness<HSXType>(dr, dg, db, getLightness<HSXType>(sr, sg, sb));-}+ /**+ * If the destination vector has zero height, then we should skip its+ * modification (since we cannot rotate it in any way+ */-template<class HSXType, class TReal>-inline void cfDecreaseLightness(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- addLightness<HSXType>(dr, dg, db, getLightness<HSXType>(sr, sg, sb) - TReal(1.0));-}+ float tx = 2*srcR-1;+ float ty = 2*srcG-1;+ float tz = 2*srcB;+ float ux = -2*dstR+1;+ float uy = -2*dstG+1;+ float uz = 2*dstB-1;+ float k = (tx*ux+ty*uy+tz*uz)/tz; // dot(t,u)/t.z+ float rx = tx*k-ux;+ float ry = ty*k-uy;+ float rz = tz*k-uz;-template<class HSXType, class TReal>-inline void cfSaturation(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- TReal sat = getSaturation<HSXType>(sr, sg, sb);- TReal light = getLightness<HSXType>(dr, dg, db);- setSaturation<HSXType>(dr, dg, db, sat);- setLightness<HSXType>(dr, dg, db, light);-}+ float finalLength = rx*rx+ry*ry+rz*rz;-template<class HSXType, class TReal>-inline void cfIncreaseSaturation(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- using namespace Arithmetic;- TReal sat = lerp(getSaturation<HSXType>(dr,dg,db), unitValue<TReal>(), getSaturation<HSXType>(sr,sg,sb));- TReal light = getLightness<HSXType>(dr, dg, db);- setSaturation<HSXType>(dr, dg, db, sat);- setLightness<HSXType>(dr, dg, db, light);-}-template<class HSXType, class TReal>-inline void cfDecreaseSaturation(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- using namespace Arithmetic;- TReal sat = lerp(zeroValue<TReal>(), getSaturation<HSXType>(dr,dg,db), getSaturation<HSXType>(sr,sg,sb));- TReal light = getLightness<HSXType>(dr, dg, db);- setSaturation<HSXType>(dr, dg, db, sat);- setLightness<HSXType>(dr, dg, db, light);-}+ /**+ * If the resulting length of the vector is zero, then just keep the+ * destination unchanged. Usually it means that the destination vector+ * is null (i.e. dstR == dstG == dstB == 0.5)+ */+ if (isZeroValueStrict(finalLength)) {+ return;+ }-template<class HSXType, class TReal>-inline void cfHue(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- TReal sat = getSaturation<HSXType>(dr, dg, db);- TReal lum = getLightness<HSXType>(dr, dg, db);- dr = sr;- dg = sg;- db = sb;- setSaturation<HSXType>(dr, dg, db, sat);- setLightness<HSXType>(dr, dg, db, lum);-}+ k = 1 / sqrt(finalLength); // normalize result+ rx *= k;+ ry *= k;+ rz *= k;+ dstR = rx*0.5+0.5;+ dstG = ry*0.5+0.5;+ dstB = rz*0.5+0.5;+ }+};-template<class HSXType, class TReal>-inline void cfTangentNormalmap(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {- using namespace Arithmetic;- TReal half=halfValue<TReal>();-- dr = sr+(dr-half);- dg = sg+(dg-half);- db = sb+(db-unitValue<TReal>());-}--template<class HSXType, class TReal>-inline void cfDarkerColor(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {-- TReal lum = getLightness<HSXType>(dr, dg, db);- TReal lum2 = getLightness<HSXType>(sr, sg, sb);- if (lum<lum2) {- sr = dr;- sg = dg;- sb = db;+template<class HSXType, typename channels_type>+struct CFColor : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ using namespace Arithmetic;+ float lum = getLightness<HSXType>(dstR, dstG, dstB);+ dstR = srcR;+ dstG = srcG;+ dstB = srcB;+ setLightness<HSXType>(dstR, dstG, dstB, lum);+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);}- else {- dr = sr;- dg = sg;- db = sb;+};++template<class HSXType, typename channels_type>+struct CFLambertLighting : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ float tr = srcR * dstR * (1.0 / 0.215686);+ float tg = srcG * dstG * (1.0 / 0.215686);+ float tb = srcB * dstB * (1.0 / 0.215686);++ if (tr > 1.0) {+ dstR = 1.0 + (tr - 1.0) * (tr - 1.0) * 0.01925;+ }+ else {+ dstR = tr;+ }++ if (tg > 1.0) {+ dstG = 1.0 + (tg - 1.0) * (tg - 1.0) * 0.01925;+ }+ else {+ dstG = tg;+ }++ if (tb > 1.0) {+ dstB = 1.0 + (tb - 1.0) * (tb - 1.0) * 0.01925;+ }+ else {+ dstB = tb;+ }++ ToneMapping<HSXType, float>(dstR, dstG, dstB);}+};-}+template<class HSXType, typename channels_type>+struct CFLambertLightingGamma2_2 : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ float tr = srcR * dstR * 2.0;+ float tg = srcG * dstG * 2.0;+ float tb = srcB * dstB * 2.0;-template<class HSXType, class TReal>-inline void cfLighterColor(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db) {-- TReal lum = getLightness<HSXType>(dr, dg, db);- TReal lum2 = getLightness<HSXType>(sr, sg, sb);- if (lum>lum2) {- sr = dr;- sg = dg;- sb = db;+ if (tr > 1.0) {+ dstR = 1.0 + (tr - 1.0) * (tr - 1.0) * 0.4;+ }+ else {+ dstR = tr;+ }++ if (tg > 1.0) {+ dstG = 1.0 + (tg - 1.0) * (tg - 1.0) * 0.4;+ }+ else {+ dstG = tg;+ }++ if (tb > 1.0) {+ dstB = 1.0 + (tb - 1.0) * (tb - 1.0) * 0.4;+ }+ else {+ dstB = tb;+ }++ ToneMapping<HSXType, float>(dstR, dstG, dstB);}- else {- dr = sr;- dg = sg;- db = sb;+};++template<class HSXType, typename channels_type>+struct CFLightness : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ setLightness<HSXType>(dstR, dstG, dstB, getLightness<HSXType>(srcR, srcG, srcB));+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);}-}+};+++template<class HSXType, typename channels_type>+struct CFIncreaseLightness : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ addLightness<HSXType>(dstR, dstG, dstB, getLightness<HSXType>(srcR, srcG, srcB));+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFDecreaseLightness : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ addLightness<HSXType>(dstR, dstG, dstB, getLightness<HSXType>(srcR, srcG, srcB) - 1.0f);+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFSaturation : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ float sat = getSaturation<HSXType>(srcR, srcG, srcB);+ float light = getLightness<HSXType>(dstR, dstG, dstB);+ setSaturation<HSXType>(dstR, dstG, dstB, sat);+ setLightness<HSXType>(dstR, dstG, dstB, light);+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFIncreaseSaturation : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ using namespace Arithmetic;+ float sat = lerp(getSaturation<HSXType>(dstR, dstG, dstB), unitValue<float>(), getSaturation<HSXType>(srcR, srcG, srcB));+ float light = getLightness<HSXType>(dstR, dstG, dstB);+ setSaturation<HSXType>(dstR, dstG, dstB, sat);+ setLightness<HSXType>(dstR, dstG, dstB, light);+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFDecreaseSaturation : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ using namespace Arithmetic;+ float sat = lerp(zeroValue<float>(), getSaturation<HSXType>(dstR, dstG, dstB), getSaturation<HSXType>(srcR, srcG, srcB));+ float light = getLightness<HSXType>(dstR, dstG, dstB);+ setSaturation<HSXType>(dstR, dstG, dstB, sat);+ setLightness<HSXType>(dstR, dstG, dstB, light);+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFHue : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ float sat = getSaturation<HSXType>(dstR, dstG, dstB);+ float lum = getLightness<HSXType>(dstR, dstG, dstB);++ dstR = srcR;+ dstG = srcG;+ dstB = srcB;++ setSaturation<HSXType>(dstR, dstG, dstB, sat);+ setLightness<HSXType>(dstR, dstG, dstB, lum);+ possiblyFixNegativeValuesNearZeroPoint<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFTangentNormalmap : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ using namespace Arithmetic;+ const float half = halfValue<float>();+ dstR = srcR + (dstR - half);+ dstG = srcG + (dstG - half);+ dstB = srcB + (dstB - unitValue<float>());+ possiblyClampValuesToSDR<channels_type>(dstR, dstG, dstB);+ }+};++template<class HSXType, typename channels_type>+struct CFDarkerColor : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ const float lum = getLightness<HSXType>(dstR, dstG, dstB);+ const float lum2 = getLightness<HSXType>(srcR, srcG, srcB);+ if (lum > lum2) {+ dstR = srcR;+ dstG = srcG;+ dstB = srcB;+ }+ }+};++template<class HSXType, typename channels_type>+struct CFLighterColor : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<channels_type>+{+ static void composeChannels(float srcR, float srcG, float srcB, float& dstR, float& dstG, float& dstB) {+ const float lum = getLightness<HSXType>(dstR, dstG, dstB);+ const float lum2 = getLightness<HSXType>(srcR, srcG, srcB);+ if (lum < lum2) {+ dstR = srcR;+ dstG = srcG;+ dstB = srcB;+ }+ }+};template<class T>struct CFColorBurn : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T>diff --git a/libs/pigment/compositeops/KoCompositeOpGeneric.h b/libs/pigment/compositeops/KoCompositeOpGeneric.hindex 40fab42701..80d0f30718 100644--- a/libs/pigment/compositeops/KoCompositeOpGeneric.h+++ b/libs/pigment/compositeops/KoCompositeOpGeneric.h@@ -27,6 +27,17 @@ struct CompositeFunctionWrapper : KoCompositeOpGenericFunctorBase<typename Trait}};+template <class Traits,+ void compositeFunc(float, float, float, float&, float&, float&)>+struct CompositeFunctionWrapperHSL : KoCompositeOpGenericFunctorBase<typename Traits::channels_type>+{+ using channels_type = typename Traits::channels_type;++ static inline void composeChannels(float sr, float sg, float sb, float &dr, float &dg, float &db) {+ return compositeFunc(sr, sg, sb, dr, dg, db);+ }+};+}/**@@ -166,7 +177,6 @@ public:}};-template<class Traits,typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type),@@ -187,18 +197,18 @@ public:* blending/compositing function. This template works with compositing functions* for RGB channels only (the channels can not be processed separately)*/-template<class Traits, void compositeFunc(float, float, float, float&, float&, float&)>-class KoCompositeOpGenericHSL: public KoCompositeOpBase< Traits, KoCompositeOpGenericHSL<Traits,compositeFunc> >+template<class Traits, typename CompositeOpFunctor>+class KoCompositeOpGenericHSLFunctor: public KoCompositeOpBase< Traits, KoCompositeOpGenericHSLFunctor<Traits,CompositeOpFunctor> >{- typedef KoCompositeOpBase< Traits, KoCompositeOpGenericHSL<Traits,compositeFunc> > base_class;- typedef typename Traits::channels_type channels_type;+ typedef KoCompositeOpBase< Traits, KoCompositeOpGenericHSLFunctor<Traits,CompositeOpFunctor>> base_class;+ typedef typename Traits::channels_type channels_type;static const qint32 red_pos = Traits::red_pos;static const qint32 green_pos = Traits::green_pos;static const qint32 blue_pos = Traits::blue_pos;public:- KoCompositeOpGenericHSL(const KoColorSpace* cs, const QString& id, const QString& category)+ KoCompositeOpGenericHSLFunctor(const KoColorSpace* cs, const QString& id, const QString& category): base_class(cs, id, category) { }public:@@ -212,15 +222,15 @@ public:if(alphaLocked) {if(dstAlpha != zeroValue<channels_type>()) {- float srcR = scale<float>(src[red_pos]);- float srcG = scale<float>(src[green_pos]);- float srcB = scale<float>(src[blue_pos]);+ float srcR = scale<float>(CompositeOpFunctor::clampSourceChannelValue(src[red_pos]));+ float srcG = scale<float>(CompositeOpFunctor::clampSourceChannelValue(src[green_pos]));+ float srcB = scale<float>(CompositeOpFunctor::clampSourceChannelValue(src[blue_pos]));- float dstR = scale<float>(dst[red_pos]);- float dstG = scale<float>(dst[green_pos]);- float dstB = scale<float>(dst[blue_pos]);+ float dstR = scale<float>(CompositeOpFunctor::clampDestinationChannelValue(dst[red_pos]));+ float dstG = scale<float>(CompositeOpFunctor::clampDestinationChannelValue(dst[green_pos]));+ float dstB = scale<float>(CompositeOpFunctor::clampDestinationChannelValue(dst[blue_pos]));- compositeFunc(srcR, srcG, srcB, dstR, dstG, dstB);+ CompositeOpFunctor::composeChannels(srcR, srcG, srcB, dstR, dstG, dstB);if(allChannelFlags || channelFlags.testBit(red_pos))dst[red_pos] = lerp(dst[red_pos], scale<channels_type>(dstR), srcAlpha);@@ -238,15 +248,15 @@ public:channels_type newDstAlpha = unionShapeOpacity(srcAlpha, dstAlpha);if(newDstAlpha != zeroValue<channels_type>()) {- float srcR = scale<float>(src[red_pos]);- float srcG = scale<float>(src[green_pos]);- float srcB = scale<float>(src[blue_pos]);+ float srcR = scale<float>(CompositeOpFunctor::clampSourceChannelValue(src[red_pos]));+ float srcG = scale<float>(CompositeOpFunctor::clampSourceChannelValue(src[green_pos]));+ float srcB = scale<float>(CompositeOpFunctor::clampSourceChannelValue(src[blue_pos]));- float dstR = scale<float>(dst[red_pos]);- float dstG = scale<float>(dst[green_pos]);- float dstB = scale<float>(dst[blue_pos]);+ float dstR = scale<float>(CompositeOpFunctor::clampDestinationChannelValue(dst[red_pos]));+ float dstG = scale<float>(CompositeOpFunctor::clampDestinationChannelValue(dst[green_pos]));+ float dstB = scale<float>(CompositeOpFunctor::clampDestinationChannelValue(dst[blue_pos]));- compositeFunc(srcR, srcG, srcB, dstR, dstG, dstB);+ CompositeOpFunctor::composeChannels(srcR, srcG, srcB, dstR, dstG, dstB);if(allChannelFlags || channelFlags.testBit(red_pos))dst[red_pos] = div(blend(src[red_pos], srcAlpha, dst[red_pos], dstAlpha, scale<channels_type>(dstR)), newDstAlpha);@@ -264,6 +274,14 @@ public:};+template<class Traits, void compositeFunc(float, float, float, float&, float&, float&)>+class KoCompositeOpGenericHSL : public KoCompositeOpGenericHSLFunctor<Traits, detail::CompositeFunctionWrapperHSL<Traits, compositeFunc>>+{+protected:+ using base_class = KoCompositeOpGenericHSLFunctor<Traits, detail::CompositeFunctionWrapperHSL<Traits, compositeFunc>>;+public:+ using base_class::base_class;+};/*** Generic CompositeOp for separable channel + alpha compositing functionsdiff --git a/libs/pigment/compositeops/KoCompositeOps.h b/libs/pigment/compositeops/KoCompositeOps.hindex af112c9620..60b4506279 100644--- a/libs/pigment/compositeops/KoCompositeOps.h+++ b/libs/pigment/compositeops/KoCompositeOps.h@@ -311,16 +311,15 @@ struct AddRGBOpstemplate<class Traits>struct AddRGBOps<Traits, true>{- typedef float Arg;+ typedef typename Traits::channels_type channels_type;static const qint32 red_pos = Traits::red_pos;static const qint32 green_pos = Traits::green_pos;static const qint32 blue_pos = Traits::blue_pos;- template<void compositeFunc(Arg, Arg, Arg, Arg&, Arg&, Arg&)>-+ template<typename Functor>static void add(KoColorSpace* cs, const QString& id, const QString& category) {- cs->addCompositeOp(new KoCompositeOpGenericHSL<Traits, compositeFunc>(cs, id, category));+ cs->addCompositeOp(new KoCompositeOpGenericHSLFunctor<Traits, Functor>(cs, id, category));}static void add(KoColorSpace* cs) {@@ -328,49 +327,53 @@ struct AddRGBOps<Traits, true>cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,red_pos >(cs, COMPOSITE_COPY_RED , KoCompositeOp::categoryMisc()));cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,green_pos>(cs, COMPOSITE_COPY_GREEN, KoCompositeOp::categoryMisc()));cs->addCompositeOp(new KoCompositeOpCopyChannel<Traits,blue_pos >(cs, COMPOSITE_COPY_BLUE , KoCompositeOp::categoryMisc()));- add<&cfTangentNormalmap <HSYType,Arg> >(cs, COMPOSITE_TANGENT_NORMALMAP , KoCompositeOp::categoryMisc());- add<&cfReorientedNormalMapCombine <HSYType, Arg> >(cs, COMPOSITE_COMBINE_NORMAL, KoCompositeOp::categoryMisc());-- add<&cfColor <HSYType,Arg> >(cs, COMPOSITE_COLOR , KoCompositeOp::categoryHSY());- add<&cfHue <HSYType,Arg> >(cs, COMPOSITE_HUE , KoCompositeOp::categoryHSY());- add<&cfSaturation <HSYType,Arg> >(cs, COMPOSITE_SATURATION , KoCompositeOp::categoryHSY());- add<&cfIncreaseSaturation<HSYType,Arg> >(cs, COMPOSITE_INC_SATURATION, KoCompositeOp::categoryHSY());- add<&cfDecreaseSaturation<HSYType,Arg> >(cs, COMPOSITE_DEC_SATURATION, KoCompositeOp::categoryHSY());- add<&cfLightness <HSYType,Arg> >(cs, COMPOSITE_LUMINIZE , KoCompositeOp::categoryHSY());- add<&cfIncreaseLightness <HSYType,Arg> >(cs, COMPOSITE_INC_LUMINOSITY, KoCompositeOp::categoryHSY());- add<&cfDecreaseLightness <HSYType,Arg> >(cs, COMPOSITE_DEC_LUMINOSITY, KoCompositeOp::categoryHSY());- add<&cfDarkerColor <HSYType,Arg> >(cs, COMPOSITE_DARKER_COLOR , KoCompositeOp::categoryDark());//darker color as PSD does it//- add<&cfLighterColor <HSYType,Arg> >(cs, COMPOSITE_LIGHTER_COLOR , KoCompositeOp::categoryLight());//lighter color as PSD does it//-- add<&cfLambertLighting <HSIType,Arg> >(cs, COMPOSITE_LAMBERT_LIGHTING, KoCompositeOp::categoryMix());- add<&cfLambertLightingGamma2_2 <HSIType, Arg> >(cs, COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, KoCompositeOp::categoryMix());-- add<&cfColor <HSIType,Arg> >(cs, COMPOSITE_COLOR_HSI , KoCompositeOp::categoryHSI());- add<&cfHue <HSIType,Arg> >(cs, COMPOSITE_HUE_HSI , KoCompositeOp::categoryHSI());- add<&cfSaturation <HSIType,Arg> >(cs, COMPOSITE_SATURATION_HSI , KoCompositeOp::categoryHSI());- add<&cfIncreaseSaturation<HSIType,Arg> >(cs, COMPOSITE_INC_SATURATION_HSI, KoCompositeOp::categoryHSI());- add<&cfDecreaseSaturation<HSIType,Arg> >(cs, COMPOSITE_DEC_SATURATION_HSI, KoCompositeOp::categoryHSI());- add<&cfLightness <HSIType,Arg> >(cs, COMPOSITE_INTENSITY , KoCompositeOp::categoryHSI());- add<&cfIncreaseLightness <HSIType,Arg> >(cs, COMPOSITE_INC_INTENSITY , KoCompositeOp::categoryHSI());- add<&cfDecreaseLightness <HSIType,Arg> >(cs, COMPOSITE_DEC_INTENSITY , KoCompositeOp::categoryHSI());-- add<&cfColor <HSLType,Arg> >(cs, COMPOSITE_COLOR_HSL , KoCompositeOp::categoryHSL());- add<&cfHue <HSLType,Arg> >(cs, COMPOSITE_HUE_HSL , KoCompositeOp::categoryHSL());- add<&cfSaturation <HSLType,Arg> >(cs, COMPOSITE_SATURATION_HSL , KoCompositeOp::categoryHSL());- add<&cfIncreaseSaturation<HSLType,Arg> >(cs, COMPOSITE_INC_SATURATION_HSL, KoCompositeOp::categoryHSL());- add<&cfDecreaseSaturation<HSLType,Arg> >(cs, COMPOSITE_DEC_SATURATION_HSL, KoCompositeOp::categoryHSL());- add<&cfLightness <HSLType,Arg> >(cs, COMPOSITE_LIGHTNESS , KoCompositeOp::categoryHSL());- add<&cfIncreaseLightness <HSLType,Arg> >(cs, COMPOSITE_INC_LIGHTNESS , KoCompositeOp::categoryHSL());- add<&cfDecreaseLightness <HSLType,Arg> >(cs, COMPOSITE_DEC_LIGHTNESS , KoCompositeOp::categoryHSL());-- add<&cfColor <HSVType,Arg> >(cs, COMPOSITE_COLOR_HSV , KoCompositeOp::categoryHSV());- add<&cfHue <HSVType,Arg> >(cs, COMPOSITE_HUE_HSV , KoCompositeOp::categoryHSV());- add<&cfSaturation <HSVType,Arg> >(cs, COMPOSITE_SATURATION_HSV , KoCompositeOp::categoryHSV());- add<&cfIncreaseSaturation<HSVType,Arg> >(cs, COMPOSITE_INC_SATURATION_HSV, KoCompositeOp::categoryHSV());- add<&cfDecreaseSaturation<HSVType,Arg> >(cs, COMPOSITE_DEC_SATURATION_HSV, KoCompositeOp::categoryHSV());- add<&cfLightness <HSVType,Arg> >(cs, COMPOSITE_VALUE , KoCompositeOp::categoryHSV());- add<&cfIncreaseLightness <HSVType,Arg> >(cs, COMPOSITE_INC_VALUE , KoCompositeOp::categoryHSV());- add<&cfDecreaseLightness <HSVType,Arg> >(cs, COMPOSITE_DEC_VALUE , KoCompositeOp::categoryHSV());++ add<CFTangentNormalmap<HSYType,channels_type> >(cs, COMPOSITE_TANGENT_NORMALMAP , KoCompositeOp::categoryMisc());+ add<CFReorientedNormalMapCombine<HSYType, channels_type>>(cs, COMPOSITE_COMBINE_NORMAL, KoCompositeOp::categoryMisc());+ add<CFColor<HSYType, channels_type>>(cs, COMPOSITE_COLOR, KoCompositeOp::categoryHSY());+ add<CFHue<HSYType, channels_type>>(cs, COMPOSITE_HUE, KoCompositeOp::categoryHSY());+ add<CFSaturation<HSYType, channels_type>>(cs, COMPOSITE_SATURATION, KoCompositeOp::categoryHSY());+ add<CFIncreaseSaturation<HSYType, channels_type>>(cs, COMPOSITE_INC_SATURATION, KoCompositeOp::categoryHSY());+ add<CFDecreaseSaturation<HSYType, channels_type>>(cs, COMPOSITE_DEC_SATURATION, KoCompositeOp::categoryHSY());++ add<CFLightness<HSYType,channels_type>>(cs, COMPOSITE_LUMINIZE, KoCompositeOp::categoryHSY());+ add<CFIncreaseLightness<HSYType,channels_type>>(cs, COMPOSITE_INC_LUMINOSITY, KoCompositeOp::categoryHSY());+ add<CFDecreaseLightness<HSYType,channels_type>>(cs, COMPOSITE_DEC_LUMINOSITY, KoCompositeOp::categoryHSY());+++ add<CFDarkerColor<HSYType, channels_type>>(cs, COMPOSITE_DARKER_COLOR, KoCompositeOp::categoryDark()); //darker color as PSD does it//+ add<CFLighterColor<HSYType, channels_type>>(cs, COMPOSITE_LIGHTER_COLOR, KoCompositeOp::categoryLight()); //lighter color as PSD does it//++ add<CFLambertLighting<HSIType,channels_type>>(cs, COMPOSITE_LAMBERT_LIGHTING, KoCompositeOp::categoryMix());+ add<CFLambertLightingGamma2_2<HSIType, channels_type>>(cs, COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, KoCompositeOp::categoryMix());++ add<CFColor <HSIType, channels_type> >(cs, COMPOSITE_COLOR_HSI , KoCompositeOp::categoryHSI());+ add<CFHue <HSIType, channels_type> >(cs, COMPOSITE_HUE_HSI , KoCompositeOp::categoryHSI());+ add<CFSaturation <HSIType, channels_type> >(cs, COMPOSITE_SATURATION_HSI , KoCompositeOp::categoryHSI());+ add<CFIncreaseSaturation<HSIType, channels_type> >(cs, COMPOSITE_INC_SATURATION_HSI, KoCompositeOp::categoryHSI());+ add<CFDecreaseSaturation<HSIType, channels_type> >(cs, COMPOSITE_DEC_SATURATION_HSI, KoCompositeOp::categoryHSI());+ add<CFLightness <HSIType, channels_type> >(cs, COMPOSITE_INTENSITY , KoCompositeOp::categoryHSI());+ add<CFIncreaseLightness <HSIType, channels_type> >(cs, COMPOSITE_INC_INTENSITY , KoCompositeOp::categoryHSI());+ add<CFDecreaseLightness <HSIType, channels_type> >(cs, COMPOSITE_DEC_INTENSITY , KoCompositeOp::categoryHSI());++ add<CFColor <HSLType, channels_type> >(cs, COMPOSITE_COLOR_HSL , KoCompositeOp::categoryHSL());+ add<CFHue <HSLType, channels_type> >(cs, COMPOSITE_HUE_HSL , KoCompositeOp::categoryHSL());+ add<CFSaturation <HSLType, channels_type> >(cs, COMPOSITE_SATURATION_HSL , KoCompositeOp::categoryHSL());+ add<CFIncreaseSaturation<HSLType, channels_type> >(cs, COMPOSITE_INC_SATURATION_HSL, KoCompositeOp::categoryHSL());+ add<CFDecreaseSaturation<HSLType, channels_type> >(cs, COMPOSITE_DEC_SATURATION_HSL, KoCompositeOp::categoryHSL());+ add<CFLightness <HSLType, channels_type> >(cs, COMPOSITE_LIGHTNESS , KoCompositeOp::categoryHSL());+ add<CFIncreaseLightness <HSLType, channels_type> >(cs, COMPOSITE_INC_LIGHTNESS , KoCompositeOp::categoryHSL());+ add<CFDecreaseLightness <HSLType, channels_type> >(cs, COMPOSITE_DEC_LIGHTNESS , KoCompositeOp::categoryHSL());++ add<CFColor <HSVType, channels_type> >(cs, COMPOSITE_COLOR_HSV , KoCompositeOp::categoryHSV());+ add<CFHue <HSVType, channels_type> >(cs, COMPOSITE_HUE_HSV , KoCompositeOp::categoryHSV());+ add<CFSaturation <HSVType, channels_type> >(cs, COMPOSITE_SATURATION_HSV , KoCompositeOp::categoryHSV());+ add<CFIncreaseSaturation<HSVType, channels_type> >(cs, COMPOSITE_INC_SATURATION_HSV, KoCompositeOp::categoryHSV());+ add<CFDecreaseSaturation<HSVType, channels_type> >(cs, COMPOSITE_DEC_SATURATION_HSV, KoCompositeOp::categoryHSV());+ add<CFLightness <HSVType, channels_type> >(cs, COMPOSITE_VALUE , KoCompositeOp::categoryHSV());+ add<CFIncreaseLightness <HSVType, channels_type> >(cs, COMPOSITE_INC_VALUE , KoCompositeOp::categoryHSV());+ add<CFDecreaseLightness <HSVType, channels_type> >(cs, COMPOSITE_DEC_VALUE , KoCompositeOp::categoryHSV());+}};diff --git a/libs/pigment/tests/KisColorPairSampler.h b/libs/pigment/tests/KisColorPairSampler.hindex efb6cea9c7..95a70eb6e9 100644--- a/libs/pigment/tests/KisColorPairSampler.h+++ b/libs/pigment/tests/KisColorPairSampler.h@@ -13,16 +13,22 @@struct KisColorPairSampler{- std::vector<qreal> colorValues;- std::vector<qreal> alphaValues;+ std::vector<qreal> redColorValues = {0.0};+ std::vector<qreal> greenColorValues = {0.0};+ std::vector<qreal> blueColorValues = {0.0};+ std::vector<qreal> alphaValues = {1.0};size_t numSamples() const {returnalphaValues.size() *alphaValues.size() *alphaValues.size() *- colorValues.size() *- colorValues.size();+ redColorValues.size() *+ redColorValues.size() *+ greenColorValues.size() *+ greenColorValues.size() *+ blueColorValues.size() *+ blueColorValues.size();}struct SampleIndex {@@ -33,11 +39,23 @@ struct KisColorPairSamplersize_t rest = index;- dstColorIndex = rest % sampler.colorValues.size();- rest /= sampler.colorValues.size();+ dstBlueColorIndex = rest % sampler.blueColorValues.size();+ rest /= sampler.blueColorValues.size();- srcColorIndex = rest % sampler.colorValues.size();- rest /= sampler.colorValues.size();+ dstGreenColorIndex = rest % sampler.greenColorValues.size();+ rest /= sampler.greenColorValues.size();++ dstRedColorIndex = rest % sampler.redColorValues.size();+ rest /= sampler.redColorValues.size();++ srcBlueColorIndex = rest % sampler.blueColorValues.size();+ rest /= sampler.blueColorValues.size();++ srcGreenColorIndex = rest % sampler.greenColorValues.size();+ rest /= sampler.greenColorValues.size();++ srcRedColorIndex = rest % sampler.redColorValues.size();+ rest /= sampler.redColorValues.size();dstAlphaIndex = rest % sampler.alphaValues.size();rest /= sampler.alphaValues.size();@@ -57,8 +75,12 @@ struct KisColorPairSamplersize_t opacityIndex = 0;size_t srcAlphaIndex = 0;size_t dstAlphaIndex = 0;- size_t srcColorIndex = 0;- size_t dstColorIndex = 0;+ size_t srcRedColorIndex = 0;+ size_t srcGreenColorIndex = 0;+ size_t srcBlueColorIndex = 0;+ size_t dstRedColorIndex = 0;+ size_t dstGreenColorIndex = 0;+ size_t dstBlueColorIndex = 0;};class const_iterator@@ -82,14 +104,18 @@ struct KisColorPairSampler{}KoColor srcColor(const KoColorSpace *colorSpace) const {- return createColor(m_sampler->colorValues[m_sampleIndex.srcColorIndex],+ return createColor(m_sampler->redColorValues[m_sampleIndex.srcRedColorIndex],+ m_sampler->greenColorValues[m_sampleIndex.srcGreenColorIndex],+ m_sampler->blueColorValues[m_sampleIndex.srcBlueColorIndex],m_sampler->alphaValues[m_sampleIndex.srcAlphaIndex],colorSpace);}KoColor dstColor(const KoColorSpace *colorSpace) const {- return createColor(m_sampler->colorValues[m_sampleIndex.dstColorIndex],+ return createColor(m_sampler->redColorValues[m_sampleIndex.dstRedColorIndex],+ m_sampler->greenColorValues[m_sampleIndex.dstGreenColorIndex],+ m_sampler->blueColorValues[m_sampleIndex.dstBlueColorIndex],m_sampler->alphaValues[m_sampleIndex.dstAlphaIndex],colorSpace);}@@ -107,63 +133,62 @@ struct KisColorPairSampler}qreal srcColor() const {- return m_sampler->colorValues[m_sampleIndex.srcColorIndex];+ return m_sampler->redColorValues[m_sampleIndex.srcRedColorIndex];}qreal dstColor() const {- return m_sampler->colorValues[m_sampleIndex.dstColorIndex];+ return m_sampler->redColorValues[m_sampleIndex.dstRedColorIndex];}private:- static KoColor createColorU (qreal colorF, qreal alphaF, const KoColorSpace *colorSpace) {+ static KoColor createColorU (qreal redF, qreal greenF, qreal blueF, qreal alphaF, const KoColorSpace *colorSpace) {using namespace Arithmetic;+ auto scaleChannel = [] (qreal value) -> quint16 {+ return qFuzzyCompare(value, 0.5) ?+ KoColorSpaceMathsTraits<quint16>::halfValue :+ qRound(qBound(0.0, value, 1.0) * unitValue<quint16>());+ };+/*** Some composite ops reply on the halfValue to decide about the* processing they do, so we should make sure that float and uint16* modes use the same half-point in the test*/- const quint16 color = qFuzzyCompare(colorF, 0.5) ?- KoColorSpaceMathsTraits<quint16>::halfValue :- qRound(qBound(0.0, colorF, 1.0) * unitValue<quint16>());+ const quint16 red = scaleChannel(redF);+ const quint16 green = scaleChannel(greenF);+ const quint16 blue = scaleChannel(blueF);const quint16 alpha = qRound(qBound(0.0, alphaF, 1.0) * unitValue<quint16>());KoColor c(colorSpace);quint16 *ptr = reinterpret_cast<quint16*>(c.data());- ptr[2] = color;+ ptr[0] = blue;+ ptr[1] = green;+ ptr[2] = red;ptr[3] = alpha;return c;};- static KoColor createColorF32(qreal color, qreal alpha, const KoColorSpace *colorSpace) {- KoColor c(colorSpace);- float *ptr = reinterpret_cast<float*>(c.data());- ptr[0] = color;- ptr[3] = alpha;- return c;- };+ static inline KoColor createColor(qreal red, qreal green, qreal blue, qreal alpha, const KoColorSpace *colorSpace) {- static KoColor createColorF16(qreal color, qreal alpha, const KoColorSpace *colorSpace) {- KoColor c(colorSpace);- half *ptr = reinterpret_cast<half*>(c.data());- ptr[0] = color;- ptr[3] = alpha;- return c;- };- static KoColor createColor(qreal color, qreal alpha, const KoColorSpace *colorSpace) {- KoColor result;+ if (colorSpace->hasHighDynamicRange()) {+ KoColor result(colorSpace);++ QVector<float> colors;+ colors.resize(4);+ colors[0] = red;+ colors[1] = green;+ colors[2] = blue;+ colors[3] = alpha;++ colorSpace->fromNormalisedChannelsValue(result.data(), colors);++ return result;- if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {- result = createColorF32(color, alpha, colorSpace);- } else if (colorSpace->colorDepthId() == Float16BitsColorDepthID) {- result = createColorF16(color, alpha, colorSpace);- } else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {- result = createColorU(color, alpha, colorSpace);} else {- qFatal("bit depth is not implemented");+ return createColorU(red, green, blue, alpha, colorSpace);}- return result;};private:diff --git a/libs/pigment/tests/TestCompositeOpInversion.cpp b/libs/pigment/tests/TestCompositeOpInversion.cppindex 797788c0ef..d690561d44 100644--- a/libs/pigment/tests/TestCompositeOpInversion.cpp+++ b/libs/pigment/tests/TestCompositeOpInversion.cpp@@ -10,6 +10,8 @@#include <simpletest.h>+#include <QPainter>+#include <KoColor.h>#include <KoColorSpace.h>#include <KoColorSpaceRegistry.h>@@ -226,13 +228,12 @@ void TestCompositeOpInversion::test_data()void TestCompositeOpInversion::testColorPairSampler(){- const KoColorSpace* csU = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Integer16BitsColorDepthID.id(), 0);- const KoColorSpace* csF = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);+ // const KoColorSpace* csF = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);KisColorPairSampler sampler;sampler.alphaValues = {0.0, 0.3, 0.9};- sampler.colorValues = {0.1, 0.4, 0.6, 1.0};+ sampler.redColorValues = {0.1, 0.4, 0.6, 1.0};KisColorPairSampler::const_iterator it = sampler.begin();KisColorPairSampler::const_iterator end = sampler.end();@@ -240,9 +241,33 @@ void TestCompositeOpInversion::testColorPairSampler()QCOMPARE(sampler.numSamples(), 3 * 3 * 3 * 4 * 4);QCOMPARE(std::distance(it, end), sampler.numSamples());- // for (; it != end; ++it) {+ for (; it != end; ++it) {// qDebug() << ppVar(it.opacity()) << ppVar(it.srcColor(csF)) << ppVar(it.dstColor(csF));- // }+ }+}++void TestCompositeOpInversion::testColorPairSamplerRGB()+{+ // const KoColorSpace* csF = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);++ KisColorPairSampler sampler;++ sampler.alphaValues = {0.0, 0.3, 0.9};+ sampler.redColorValues = {0.1, 0.4, 0.6, 1.0};+ sampler.greenColorValues = {0.3, 0.7};+ sampler.blueColorValues = {0.2, 0.8};++ KisColorPairSampler::const_iterator it = sampler.begin();+ KisColorPairSampler::const_iterator end = sampler.end();++ qDebug() << ppVar(sampler.numSamples());++ QCOMPARE(sampler.numSamples(), 3 * 3 * 3 * 4 * 4 * 2 * 2 * 2 * 2);+ QCOMPARE(std::distance(it, end), sampler.numSamples());++ for (; it != end; ++it) {+ //qDebug() << ppVar(it.opacity()) << ppVar(it.srcColor(csF)) << ppVar(it.dstColor(csF));+ }}@@ -273,34 +298,84 @@ QDebug operator<<(QDebug debug, const Wrapper &w) {return debug.space();}-Wrapper dumpPixel(const KoColor &color) {- return {color, 0};+Wrapper dumpPixel(const KoColor &color, int channelIndex = 0) {+ return {color, channelIndex};}-float getColorValue(const KoColor &c) {+float getColorValue(const KoColor &c, int channelIndex = 0) {float result = 777.0;if (c.colorSpace()->colorDepthId() == Float32BitsColorDepthID) {const float *ptr = reinterpret_cast<const float*>(c.data());- result = ptr[0];+ result = ptr[channelIndex];} else if (c.colorSpace()->colorDepthId() == Float16BitsColorDepthID) {const half *ptr = reinterpret_cast<const half*>(c.data());- result = ptr[0];+ result = ptr[channelIndex];} else if (c.colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {using namespace Arithmetic;const quint16 *ptr = reinterpret_cast<const quint16*>(c.data());- result = qreal(ptr[2]) / unitValue<quint16>();+ const int realChannelIndex = channelIndex == 3 ? channelIndex : 2 - channelIndex;+ result = qreal(ptr[realChannelIndex]) / unitValue<quint16>();}return result;}-quint16 getColorValueU(const KoColor &c) {- KIS_ASSERT(c.colorSpace()->colorDepthId() == Integer16BitsColorDepthID);+void dumpChannelsState(qreal opacity, float tolerance,+ int numChannelsToTest,+ int failedChannelIndex,+ const KoColor &srcColorF,+ const KoColor &dstColorF,+ const KoColor &resultColorF,+ const KoColor &srcColorU,+ const KoColor &dstColorU,+ const KoColor &resultColorU)+{+ qDebug() << "--- failed to verify the channels ---";+ qDebug() << ppVar(opacity) << ppVar(tolerance);++ if (numChannelsToTest > 1) {+ qDebug();+ qDebug() << ppVar(srcColorF);+ qDebug() << ppVar(dstColorF);+ qDebug() << ppVar(resultColorF);+ qDebug();+ qDebug() << ppVar(srcColorU);+ qDebug() << ppVar(dstColorU);+ qDebug() << ppVar(resultColorU);+ qDebug();++ const QString channelName = srcColorF.colorSpace()->channels()[failedChannelIndex]->name();+ qDebug() << "Failed channel:" << channelName;+ }+ qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)+ << "s:" << dumpPixel(srcColorU, failedChannelIndex) << "+" << "d:" << dumpPixel(dstColorU, failedChannelIndex) << "->" << dumpPixel(resultColorU, failedChannelIndex);+ qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)+ << "s:" << dumpPixel(srcColorF, failedChannelIndex) << "+" << "d:" << dumpPixel(dstColorF, failedChannelIndex) << "->" << dumpPixel(resultColorF, failedChannelIndex);+}- using namespace Arithmetic;- const quint16 *ptr = reinterpret_cast<const quint16*>(c.data());- return ptr[2];+void dumpChannelsState(qreal opacity, float tolerance,+ int numChannelsToTest,+ int failedChannelIndex,+ const KoColor &srcColorF,+ const KoColor &dstColorF,+ const KoColor &resultColorF)+{+ qDebug() << "--- failed to verify the channels ---";+ qDebug() << ppVar(opacity) << ppVar(tolerance);++ if (numChannelsToTest > 1) {+ qDebug();+ qDebug() << ppVar(srcColorF);+ qDebug() << ppVar(dstColorF);+ qDebug() << ppVar(resultColorF);+ qDebug();++ const QString channelName = srcColorF.colorSpace()->channels()[failedChannelIndex]->name();+ qDebug() << "Failed channel:" << channelName;+ }+ qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)+ << "s:" << dumpPixel(srcColorF, failedChannelIndex) << "+" << "d:" << dumpPixel(dstColorF, failedChannelIndex) << "->" << dumpPixel(resultColorF, failedChannelIndex);}}@@ -317,6 +392,9 @@ enum TestFlag {HasUnboundedRange = 0x20,PositivePreserveStable = 0x40,PositivePreserveUnstable = 0x80,+ SampleWholeRGBRange = 0x100,+ SdrRangeCanGenerateSmallErrors = 0x200,+ GenerateF32SampleSheetOnly = 0x400};Q_DECLARE_FLAGS(TestFlags, TestFlag)Q_DECLARE_OPERATORS_FOR_FLAGS(TestFlags)@@ -336,6 +414,14 @@ std::vector<qreal> generateOpacityValues()};}+template<typename T = float>+std::vector<qreal> generateNarrowOpacityValues()+{+ return {+ 1.0+ };+}+template<typename T = float>std::vector<qreal> generateWideColorValues(){@@ -355,6 +441,25 @@ std::vector<qreal> generateWideColorValues()1.5};}+template<typename T = float>+std::vector<qreal> generateNarrowColorValues()+{+ return {-0.1,+ 0 - std::numeric_limits<T>::epsilon(),+ 0,+ 0 + std::numeric_limits<T>::epsilon(),+ 0.2,+ 0.5 - 2 * std::numeric_limits<T>::epsilon(),+ 0.5,+ 0.5 + 2 * std::numeric_limits<T>::epsilon(),+ 0.8,+ 1.0 - std::numeric_limits<T>::epsilon(),+ 1.0,+ 1.0 + std::numeric_limits<T>::epsilon(),+ 1.1};+}++std::vector<std::pair<QString, TestFlags>> generateCompositeOpIdSet(){std::vector<std::pair<QString, TestFlags>> result;@@ -442,45 +547,49 @@ std::vector<std::pair<QString, TestFlags>> generateCompositeOpIdSet()result.emplace_back(COMPOSITE_GAMMA_LIGHT, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);result.emplace_back(COMPOSITE_GAMMA_ILLUMINATION, SrcCannotMakeNegative | SdrRangePreserveUnstable | PositivePreserveStable);- result.emplace_back(COMPOSITE_TANGENT_NORMALMAP, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_COMBINE_NORMAL, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_COLOR, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_HUE, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_SATURATION, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_SATURATION, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_SATURATION, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_LUMINIZE, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_LUMINOSITY, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_LUMINOSITY, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DARKER_COLOR, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_LIGHTER_COLOR, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_LAMBERT_LIGHTING, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_COLOR_HSI, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_HUE_HSI, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_SATURATION_HSI, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_SATURATION_HSI, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_SATURATION_HSI, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INTENSITY, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_INTENSITY, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_INTENSITY, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_COLOR_HSL, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_HUE_HSL, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_SATURATION_HSL, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_SATURATION_HSL, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_SATURATION_HSL, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_LIGHTNESS, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_LIGHTNESS, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_LIGHTNESS, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_COLOR_HSV, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_HUE_HSV, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_SATURATION_HSV, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_SATURATION_HSV, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_SATURATION_HSV, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_VALUE, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_INC_VALUE, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);- result.emplace_back(COMPOSITE_DEC_VALUE, SrcCannotMakeNegative | SdrRangePreserveStable | PositivePreserveStable);+ result.emplace_back(COMPOSITE_TANGENT_NORMALMAP, SampleWholeRGBRange | SdrRangePreserveStable | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_COMBINE_NORMAL, SampleWholeRGBRange | SdrRangePreserveStable | PositivePreserveStable | GenerateF32SampleSheetOnly);++ result.emplace_back(COMPOSITE_COLOR, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_HUE, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_SATURATION, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_SATURATION, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_SATURATION, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_LUMINIZE, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_LUMINOSITY, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_LUMINOSITY, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);++ result.emplace_back(COMPOSITE_COLOR_HSI, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_HUE_HSI, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_SATURATION_HSI, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_SATURATION_HSI, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_SATURATION_HSI, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INTENSITY, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_INTENSITY, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_INTENSITY, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);++ result.emplace_back(COMPOSITE_COLOR_HSL, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_HUE_HSL, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_SATURATION_HSL, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_SATURATION_HSL, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_SATURATION_HSL, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_LIGHTNESS, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_LIGHTNESS, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_LIGHTNESS, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);++ result.emplace_back(COMPOSITE_COLOR_HSV, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_HUE_HSV, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_SATURATION_HSV, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_SATURATION_HSV, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_SATURATION_HSV, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_VALUE, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_INC_VALUE, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_DEC_VALUE, SampleWholeRGBRange | SdrRangePreserveStable | SdrRangeCanGenerateSmallErrors | PositivePreserveStable | GenerateF32SampleSheetOnly);++ result.emplace_back(COMPOSITE_DARKER_COLOR, SampleWholeRGBRange | SdrRangePreserveStable | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_LIGHTER_COLOR, SampleWholeRGBRange | SdrRangePreserveStable | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_LAMBERT_LIGHTING, SampleWholeRGBRange | SdrRangePreserveStable | PositivePreserveStable | GenerateF32SampleSheetOnly);+ result.emplace_back(COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, SampleWholeRGBRange | SdrRangePreserveStable | PositivePreserveStable | GenerateF32SampleSheetOnly);return result;}@@ -492,6 +601,7 @@ void addAllOps(const std::vector<std::pair<QString, TestFlags>> &ops)auto fixId = [] (QString id) {id.replace(' ', '_');+ id.replace('.', '_');return id;};@@ -509,6 +619,25 @@ void TestCompositeOpInversion::testF32ModesNaN_data()addAllOps(generateCompositeOpIdSet());}+int initSampler(KisColorPairSampler &sampler, TestFlags flags)+{+ int numChannelsToTest = 0;++ if (flags.testFlag(SampleWholeRGBRange)) {+ sampler.alphaValues = generateNarrowOpacityValues();+ sampler.redColorValues = generateNarrowColorValues();+ sampler.greenColorValues = generateNarrowColorValues();+ sampler.blueColorValues = generateNarrowColorValues();+ numChannelsToTest = 3;+ } else {+ sampler.alphaValues = generateOpacityValues();+ sampler.redColorValues = generateWideColorValues();+ numChannelsToTest = 1;+ }++ return numChannelsToTest;+}+void TestCompositeOpInversion::testF32ModesNaN(){QFETCH(QString, id);@@ -518,8 +647,7 @@ void TestCompositeOpInversion::testF32ModesNaN()const KoCompositeOp *opF = createOp(csF, id, flags.testFlag(HDR));KisColorPairSampler sampler;- sampler.alphaValues = generateOpacityValues();- sampler.colorValues = generateWideColorValues();+ const int numChannelsToTest = initSampler(sampler, flags);for (auto it = sampler.begin(); it != sampler.end(); ++it) {KoColor srcColorF = it.srcColor(csF);@@ -531,26 +659,32 @@ void TestCompositeOpInversion::testF32ModesNaN()1, 1,it.opacity());- float resultColorValueF = getColorValue(resultColorF);-- if (std::isnan(resultColorValueF)) {- qDebug() << "--- NaN value is found! ---";- qDebug() << ppVar(it.opacity());- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);- QFAIL("NaN value is found!");- }+ for (int channelIndex = 0; channelIndex < numChannelsToTest; ++channelIndex) {+ float resultColorValueF = getColorValue(resultColorF, channelIndex);++ if (std::isnan(resultColorValueF)) {+ dumpChannelsState(it.opacity(), 0,+ numChannelsToTest,+ channelIndex,+ srcColorF,+ dstColorF,+ resultColorF);+ QFAIL("NaN value is found!");+ }- if (std::isinf(resultColorValueF)) {- qDebug() << "--- inf value is found! ---";- qDebug() << ppVar(it.opacity());- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);- QFAIL("inf value is found!");+ if (std::isinf(resultColorValueF)) {+ dumpChannelsState(it.opacity(), 0,+ numChannelsToTest,+ channelIndex,+ srcColorF,+ dstColorF,+ resultColorF);+ QFAIL("inf value is found!");+ }}}}-+#if 0void TestCompositeOpInversion::testU16ModesConsistent_data(){auto ids = generateCompositeOpIdSet();@@ -585,7 +719,7 @@ void TestCompositeOpInversion::testU16ModesConsistent()KisColorPairSampler sampler;sampler.alphaValues = generateOpacityValues();- sampler.colorValues = generateWideColorValues();+ sampler.redColorValues = generateWideColorValues();for (auto it = sampler.begin(); it != sampler.end(); ++it) {KIS_ASSERT(!flags.testFlag(HDR));@@ -623,6 +757,10 @@ void TestCompositeOpInversion::testU16ModesConsistent()maxDifference = minOpacity > 0.99 ? 1 : 10;}+ if (id == COMPOSITE_COMBINE_NORMAL && Arithmetic::isZeroValueStrict(it.srcColor())) {+ continue;+ }+/*** We have changed CompositeGeneric so now there is a precise* case for alpha-unity values@@ -653,7 +791,7 @@ void TestCompositeOpInversion::testU16ModesConsistent()}}}-+#endifvoid TestCompositeOpInversion::testF32vsU16ConsistencyInSDR_data(){addAllOps(generateCompositeOpIdSet());@@ -671,8 +809,13 @@ void TestCompositeOpInversion::testF32vsU16ConsistencyInSDR()const KoCompositeOp *opU = createOp(csU, id, flags.testFlag(HDR));KisColorPairSampler sampler;- sampler.alphaValues = generateOpacityValues();- sampler.colorValues = generateWideColorValues();+ const int numChannelsToTest = initSampler(sampler, flags);++ // allocate the temporary buffers **outside** the main loop+ QVector<float> srcColorsF(4);+ QVector<float> dstColorsF(4);+ QVector<float> resultColorsF(4);+ QVector<float> resultColorsU(4);for (auto it = sampler.begin(); it != sampler.end(); ++it) {@@ -692,8 +835,6 @@ void TestCompositeOpInversion::testF32vsU16ConsistencyInSDR()1, 1,it.opacity());- float resultColorValueF = getColorValue(resultColorF);-KoColor srcColorU = it.srcColor(csU);KoColor dstColorU = it.dstColor(csU);KoColor resultColorU = dstColorU;@@ -703,141 +844,192 @@ void TestCompositeOpInversion::testF32vsU16ConsistencyInSDR()1, 1,it.opacity());- float resultColorValueU = getColorValue(resultColorU);+ csF->normalisedChannelsValue(srcColorF.data(), srcColorsF);+ csF->normalisedChannelsValue(dstColorF.data(), dstColorsF);+ csF->normalisedChannelsValue(resultColorF.data(), resultColorsF);+ csU->normalisedChannelsValue(resultColorU.data(), resultColorsU);+ std::swap(resultColorsU[0], resultColorsU[2]);- auto checkInSdrRangeImpl = [] (qreal value, bool useStrictRange) {- return useStrictRange ?- (value >= 0.0 && value <= 1.0) :- (value >= -std::numeric_limits<float>::epsilon() &&- value <= 1.0 + std::numeric_limits<float>::epsilon());- };+ for (int channelIndex = 0; channelIndex < numChannelsToTest; channelIndex++) {+ const float srcColorValueF = srcColorsF[channelIndex];+ const float dstColorValueF = dstColorsF[channelIndex];- auto checkInSdrRange = [=] (qreal value) {- return checkInSdrRangeImpl(value, flags.testFlag(VerifyConsistencyInStrictSdrRange));- };+ const float resultColorValueF = resultColorsF[channelIndex];+ const float resultColorValueU = resultColorsU[channelIndex];- const bool isInSdrRange =- checkInSdrRange(it.dstColor()) &&- checkInSdrRange(it.srcColor());+ auto checkInSdrRangeImpl = [] (qreal value, bool useStrictRange) {+ return useStrictRange ?+ (value >= 0.0 && value <= 1.0) :+ (value >= -std::numeric_limits<float>::epsilon() &&+ value <= 1.0 + std::numeric_limits<float>::epsilon());+ };- if (isInSdrRange &&- qAbs(resultColorValueF - resultColorValueU) > tolerance) {+ auto checkInSdrRange = [=] (qreal value) {+ return checkInSdrRangeImpl(value, flags.testFlag(VerifyConsistencyInStrictSdrRange));+ };- /**- * HARD_MIX_PHOTOSHOP is not contiguous near the unit sum point,- * so we should just skip this test case- */- if (id == COMPOSITE_HARD_MIX_PHOTOSHOP &&- Arithmetic::isUnitValueFuzzy<float>(float(it.srcColor()) + float(it.dstColor()))) {- continue;- }+ const bool isInSdrRange =+ checkInSdrRange(dstColorValueF) &&+ checkInSdrRange(srcColorValueF);- if (id == COMPOSITE_HARD_OVERLAY) {- if (Arithmetic::isUnitValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isZeroValueClampedFuzzy<float>(it.dstColor())) {+ if (isInSdrRange &&+ qAbs(resultColorValueF - resultColorValueU) > tolerance) {+ /**+ * HARD_MIX_PHOTOSHOP is not contiguous near the unit sum point,+ * so we should just skip this test case+ */+ if (id == COMPOSITE_HARD_MIX_PHOTOSHOP &&+ Arithmetic::isUnitValueFuzzy<float>(float(srcColorValueF) + float(dstColorValueF))) {continue;}- }- if (id == COMPOSITE_HARD_OVERLAY && flags.testFlag(HDR)) {- if (Arithmetic::isUnitValueClampedFuzzy<float>(it.srcColor())) {- continue;+ if (id == COMPOSITE_HARD_OVERLAY) {+ if (Arithmetic::isUnitValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isZeroValueClampedFuzzy<float>(dstColorValueF)) {++ continue;+ }}- }- if (id == COMPOSITE_DODGE) {- if (Arithmetic::isUnitValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isZeroValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_HARD_OVERLAY && flags.testFlag(HDR)) {+ if (Arithmetic::isUnitValueClampedFuzzy<float>(srcColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_DODGE && flags.testFlag(HDR)) {- if (Arithmetic::isUnitValueClampedFuzzy<float>(it.srcColor())) {- continue;+ if (id == COMPOSITE_DODGE) {+ if (Arithmetic::isUnitValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isZeroValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_BURN) {- if (Arithmetic::isZeroValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isUnitValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_DODGE && flags.testFlag(HDR)) {+ if (Arithmetic::isUnitValueClampedFuzzy<float>(srcColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_VIVID_LIGHT) {- if (Arithmetic::isUnitValueClampedFuzzy<float>(it.srcColor()) ||- Arithmetic::isZeroValueClampedFuzzy<float>(it.srcColor())) {- continue;+ if (id == COMPOSITE_BURN) {+ if (Arithmetic::isZeroValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isUnitValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_DIVIDE) {- if (Arithmetic::isZeroValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isZeroValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_VIVID_LIGHT) {+ if (Arithmetic::isUnitValueClampedFuzzy<float>(srcColorValueF) ||+ Arithmetic::isZeroValueClampedFuzzy<float>(srcColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_ARC_TANGENT) {- if (Arithmetic::isZeroValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isZeroValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_DIVIDE) {+ if (Arithmetic::isZeroValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isZeroValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_GAMMA_DARK) {- if (Arithmetic::isZeroValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isUnitValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_ARC_TANGENT) {+ if (Arithmetic::isZeroValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isZeroValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_GAMMA_LIGHT) {- if (Arithmetic::isZeroValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_GAMMA_DARK) {+ if (Arithmetic::isZeroValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isUnitValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }}- }- if (id == COMPOSITE_GAMMA_ILLUMINATION) {- if (Arithmetic::isUnitValueClampedFuzzy<float>(it.srcColor()) &&- Arithmetic::isZeroValueClampedFuzzy<float>(it.dstColor())) {- continue;+ if (id == COMPOSITE_GAMMA_LIGHT) {+ if (Arithmetic::isZeroValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }}- }- // normal extension into HDR- bool isStraightUnitExtension =- Arithmetic::isUnitValueFuzzy<float>(resultColorValueU) &&- qAbs(resultColorValueU - qMin(1.0f, resultColorValueF)) <= 0.001;-- // clipped extension into HDR (when opacity < 1.0)- isStraightUnitExtension |=- resultColorValueU > minOpacity && resultColorValueF > 1.0;-- if (Arithmetic::isZeroValueFuzzy<float>(resultColorValueU) &&- qAbs(resultColorValueU - qMax(0.0f, resultColorValueF)) <= 0.001) {- // noop, should be fine result- } else if (isStraightUnitExtension) {- // noop, should be fine result as well- } else if (resultColorValueF < 0.0) {- qDebug() << "--- resulting value in SDR range is negative! ---";- qDebug() << ppVar(it.opacity());- qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);- QFAIL("resulting value in SDR range is negative!");- } else {-- qDebug() << "--- inconsistent result in SDR range ---";- qDebug() << ppVar(it.opacity());- qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);- QFAIL("inconsistent result in SDR range!");+ if (id == COMPOSITE_GAMMA_ILLUMINATION) {+ if (Arithmetic::isUnitValueClampedFuzzy<float>(srcColorValueF) &&+ Arithmetic::isZeroValueClampedFuzzy<float>(dstColorValueF)) {+ continue;+ }+ }++ if (id == COMPOSITE_COMBINE_NORMAL) {+ if (Arithmetic::isHalfValueFuzzy<float>(srcColorValueF) ||+ Arithmetic::isHalfValueFuzzy<float>(dstColorValueF)) {+ continue;+ }+ }++ // all blendmodes that have setSaturation(dst) are unstable near the point+ // when all three channels have the same value+ if (id == COMPOSITE_SATURATION+ || id == COMPOSITE_SATURATION_HSV+ || id == COMPOSITE_SATURATION_HSI+ || id == COMPOSITE_SATURATION_HSL+ || id == COMPOSITE_DEC_SATURATION+ || id == COMPOSITE_DEC_SATURATION_HSV+ || id == COMPOSITE_DEC_SATURATION_HSI+ || id == COMPOSITE_DEC_SATURATION_HSL+ || id == COMPOSITE_INC_SATURATION+ || id == COMPOSITE_INC_SATURATION_HSV+ || id == COMPOSITE_INC_SATURATION_HSI+ || id == COMPOSITE_INC_SATURATION_HSL+ || id == COMPOSITE_HUE+ || id == COMPOSITE_HUE_HSV+ || id == COMPOSITE_HUE_HSI+ || id == COMPOSITE_HUE_HSL) {+ if (qFuzzyCompare(dstColorsF[0], dstColorsF[1]) &&+ qFuzzyCompare(dstColorsF[1], dstColorsF[2])) {+ continue;+ }+ }++ // all hue related modes cannot handle the case when the source is gray+ if (id == COMPOSITE_HUE+ || id == COMPOSITE_HUE_HSV+ || id == COMPOSITE_HUE_HSI+ || id == COMPOSITE_HUE_HSL) {+ if (qFuzzyCompare(srcColorsF[0], srcColorsF[1]) &&+ qFuzzyCompare(srcColorsF[1], srcColorsF[2])) {+ continue;+ }+ }++ // normal extension into HDR+ bool isStraightUnitExtension =+ Arithmetic::isUnitValueFuzzy<float>(resultColorValueU) &&+ qAbs(resultColorValueU - qMin(1.0f, resultColorValueF)) <= 0.001;++ // clipped extension into HDR (when opacity < 1.0)+ isStraightUnitExtension |=+ resultColorValueU > minOpacity && resultColorValueF > 1.0;++ if (Arithmetic::isZeroValueFuzzy<float>(resultColorValueU) &&+ qAbs(resultColorValueU - qMax(0.0f, resultColorValueF)) <= 0.001) {+ // noop, should be fine result+ } else if (isStraightUnitExtension) {+ // noop, should be fine result as well+ } else if (resultColorValueF < 0.0) {+ dumpChannelsState(it.opacity(), tolerance,+ numChannelsToTest,+ channelIndex,+ srcColorF, dstColorF, resultColorF,+ srcColorU, dstColorU, resultColorU);+ QFAIL("resulting value in SDR range is negative!");+ } else {+ dumpChannelsState(it.opacity(), tolerance,+ numChannelsToTest,+ channelIndex,+ srcColorF, dstColorF, resultColorF,+ srcColorU, dstColorU, resultColorU);+ QFAIL("inconsistent result in SDR range!");+ }}}@@ -853,8 +1045,7 @@ void TestCompositeOpInversion::testPreservesSdrRangeImpl(bool useStrictRange)const KoCompositeOp *opF = createOp(csF, id, flags.testFlag(HDR));KisColorPairSampler sampler;- sampler.alphaValues = generateOpacityValues();- sampler.colorValues = generateWideColorValues();+ const int numChannelsToTest = initSampler(sampler, flags);auto checkInSdrRangeImpl = [=] (qreal value, bool useStrictRange) {return useStrictRange ?@@ -867,6 +1058,10 @@ void TestCompositeOpInversion::testPreservesSdrRangeImpl(bool useStrictRange)return checkInSdrRangeImpl(value, useStrictRange);};+ QVector<float> srcColorsF(4);+ QVector<float> dstColorsF(4);+ QVector<float> resultColorsF(4);+for (auto it = sampler.begin(); it != sampler.end(); ++it) {KoColor srcColorF = it.srcColor(csF);KoColor dstColorF = it.dstColor(csF);@@ -877,83 +1072,86 @@ void TestCompositeOpInversion::testPreservesSdrRangeImpl(bool useStrictRange)1, 1,it.opacity());- float resultColorValueF = getColorValue(resultColorF);-- if ((checkInSdrRange(it.srcColor())) &&- checkInSdrRange(it.dstColor()) &&- !checkInSdrRange(resultColorValueF)) {+ csF->normalisedChannelsValue(srcColorF.data(), srcColorsF);+ csF->normalisedChannelsValue(dstColorF.data(), dstColorsF);+ csF->normalisedChannelsValue(resultColorF.data(), resultColorsF);- bool resultConvergedToAPoint = false;+ for (int channelIndex = 0; channelIndex < numChannelsToTest; channelIndex++) {+ const float srcColorValueF = srcColorsF[channelIndex];+ const float dstColorValueF = dstColorsF[channelIndex];+ float resultColorValueF = resultColorsF[channelIndex];- std::vector<float> transitionalValues;- transitionalValues.reserve(20 + 1);+ if ((checkInSdrRange(srcColorValueF)) &&+ checkInSdrRange(dstColorValueF) &&+ !checkInSdrRangeImpl(resultColorValueF, !flags.testFlag(SdrRangeCanGenerateSmallErrors) && useStrictRange)) {- for (int i = 0; i < 20; i++) {- transitionalValues.push_back(resultColorValueF);+ bool resultConvergedToAPoint = false;- opF->composite(resultColorF.data(), 0, srcColorF.data(), 0,- 0, 0,- 1, 1,- it.opacity());- resultColorValueF = getColorValue(resultColorF);+ std::vector<float> transitionalValues;+ transitionalValues.reserve(20 + 1);- QVERIFY(!std::isnan(resultColorValueF));- QVERIFY(!std::isinf(resultColorValueF));+ for (int i = 0; i < 20; i++) {- /**- * We are using strict comparison here explicitly, not- * qFuzzyCompare(), because we need the algorithm to converge- * strictly to a single value.- */- if (resultColorValueF == transitionalValues.back()) {- resultConvergedToAPoint = true;transitionalValues.push_back(resultColorValueF);- break;++ opF->composite(resultColorF.data(), 0, srcColorF.data(), 0,+ 0, 0,+ 1, 1,+ it.opacity());+ resultColorValueF = getColorValue(resultColorF, channelIndex);++ QVERIFY(!std::isnan(resultColorValueF));+ QVERIFY(!std::isinf(resultColorValueF));++ /**+ * We are using strict comparison here explicitly, not+ * qFuzzyCompare(), because we need the algorithm to converge+ * strictly to a single value.+ */+ if (resultColorValueF == transitionalValues.back()) {+ resultConvergedToAPoint = true;+ transitionalValues.push_back(resultColorValueF);+ break;+ }}- }- // const float originalError = qAbs(transitionalValues.front() - resultColorValueU);- // const float finalError = qAbs(transitionalValues.back() - resultColorValueU);+ // const float originalError = qAbs(transitionalValues.front() - resultColorValueU);+ // const float finalError = qAbs(transitionalValues.back() - resultColorValueU);- bool skipConvergencyCheck = false;+ bool skipConvergencyCheck = false;- if ((id == COMPOSITE_DARKEN ||- id == COMPOSITE_LIGHTEN ||- id == COMPOSITE_ALLANON) &&- qFuzzyCompare(float(it.srcColor()), 1.0f) &&- qFuzzyCompare(float(it.srcColor()), 1.0f)) {+ if ((id == COMPOSITE_DARKEN ||+ id == COMPOSITE_LIGHTEN ||+ id == COMPOSITE_ALLANON) &&+ qFuzzyCompare(float(srcColorValueF), 1.0f) &&+ qFuzzyCompare(float(srcColorValueF), 1.0f)) {- skipConvergencyCheck = true;- }+ skipConvergencyCheck = true;+ }- if (id == COMPOSITE_GREATER) {- skipConvergencyCheck = true;- }+ if (id == COMPOSITE_GREATER) {+ skipConvergencyCheck = true;+ }- if (checkInSdrRangeImpl(transitionalValues.back(), true) ||- ((resultConvergedToAPoint ||-// finalError < originalError ||- skipConvergencyCheck) &&+ if (checkInSdrRangeImpl(transitionalValues.back(), true) ||+ ((resultConvergedToAPoint ||+ // finalError < originalError ||+ skipConvergencyCheck) &&qAbs(transitionalValues.back() - transitionalValues.front())- < 64 * std::numeric_limits<float>::epsilon())) {-- // noop, everything is fine- } else {- qDebug() << "--- op does not preserve SDR range! ---";- qDebug() << fixed << qSetRealNumberPrecision(8)- << ppVar(it.opacity()) << ppVar(it.srcColor()) << ppVar(it.dstColor()) << ppVar(resultColorValueF)- << fixed << qSetRealNumberPrecision(14);-- qDebug() << "stabilization track:";- for (size_t i = 0; i < transitionalValues.size(); i++) {- qDebug() << fixed << qSetRealNumberPrecision(14)- << " " << i << ":" << transitionalValues[i];- }+ < 64 * std::numeric_limits<float>::epsilon())) {- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);+ // noop, everything is fine+ } else {+ for (size_t i = 0; i < transitionalValues.size(); i++) {+ qDebug() << fixed << qSetRealNumberPrecision(14)+ << " " << i << ":" << transitionalValues[i];+ }- QFAIL("op does not preserve SDR range!");+ dumpChannelsState(it.opacity(), useStrictRange ? 0.0f : std::numeric_limits<float>::epsilon(),+ numChannelsToTest, channelIndex,+ srcColorF, dstColorF, resultColorF);+ QFAIL("op does not preserve SDR range!");+ }}}}@@ -1000,7 +1198,9 @@ void TestCompositeOpInversion::testSrcCannotMakeNegative_data()KritaUtils::filterContainer(ids,[&] (const std::pair<QString, TestFlags> &op) {- return op.second.testFlag(SrcCannotMakeNegative);+ return op.second.testFlag(SrcCannotMakeNegative) &&+ // we don't test RGB blendmodes for this+ !op.second.testFlag(SampleWholeRGBRange);});addAllOps(ids);@@ -1016,7 +1216,7 @@ void TestCompositeOpInversion::testSrcCannotMakeNegative()KisColorPairSampler sampler;sampler.alphaValues = generateOpacityValues();- sampler.colorValues = generateWideColorValues();+ sampler.redColorValues = generateWideColorValues();for (auto it = sampler.begin(); it != sampler.end(); ++it) {KoColor srcColorF = it.srcColor(csF);@@ -1089,8 +1289,11 @@ void TestCompositeOpInversion::testNegativeImpl(bool useStrictZeroCheck)const KoCompositeOp *opF = createOp(csF, id, flags.testFlag(HDR));KisColorPairSampler sampler;- sampler.alphaValues = generateOpacityValues();- sampler.colorValues = generateWideColorValues();+ const int numChannelsToTest = initSampler(sampler, flags);++ QVector<float> srcColorsF(4);+ QVector<float> dstColorsF(4);+ QVector<float> resultColorsF(4);for (auto it = sampler.begin(); it != sampler.end(); ++it) {KoColor srcColorF = it.srcColor(csF);@@ -1102,28 +1305,37 @@ void TestCompositeOpInversion::testNegativeImpl(bool useStrictZeroCheck)1, 1,it.opacity());- const float resultColorValueF = getColorValue(resultColorF);+ csF->normalisedChannelsValue(srcColorF.data(), srcColorsF);+ csF->normalisedChannelsValue(dstColorF.data(), dstColorsF);+ csF->normalisedChannelsValue(resultColorF.data(), resultColorsF);- const bool srcCheckValid = useStrictZeroCheck ?- it.srcColor() > 0.0 : float(it.srcColor()) >= -std::numeric_limits<float>::epsilon();+ for (int channelIndex = 0; channelIndex < numChannelsToTest; channelIndex++) {+ const float srcColorValueF = srcColorsF[channelIndex];+ const float dstColorValueF = dstColorsF[channelIndex];- const bool dstCheckValid = useStrictZeroCheck ?- it.dstColor() > 0.0 : float(it.dstColor()) >= -std::numeric_limits<float>::epsilon();+ const float resultColorValueF = resultColorsF[channelIndex];- const bool resultCheckValid = useStrictZeroCheck ?- resultColorValueF > -1.0f * std::numeric_limits<float>::epsilon() :- resultColorValueF >= -2.0f * std::numeric_limits<float>::epsilon();+ const bool srcCheckValid = useStrictZeroCheck ?+ srcColorValueF > 0.0 : float(srcColorValueF) >= -std::numeric_limits<float>::epsilon();- if (srcCheckValid &&- dstCheckValid &&- !resultCheckValid) {+ const bool dstCheckValid = useStrictZeroCheck ?+ dstColorValueF > 0.0 : float(dstColorValueF) >= -std::numeric_limits<float>::epsilon();- qDebug() << "--- resulting value in SDR range generates negative result! ---";- qDebug() << ppVar(useStrictZeroCheck);- qDebug() << ppVar(it.opacity());- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);- QFAIL("resulting value in SDR range generates negative result!");+ const bool resultCheckValid = useStrictZeroCheck ?+ resultColorValueF > -1.0f * std::numeric_limits<float>::epsilon() :+ resultColorValueF >= -2.0f * std::numeric_limits<float>::epsilon();++ if (srcCheckValid &&+ dstCheckValid &&+ !resultCheckValid) {++ dumpChannelsState(it.opacity(), 0.0f,+ numChannelsToTest,+ channelIndex,+ srcColorF, dstColorF, resultColorF);++ QFAIL("resulting value in SDR range generates negative result!");+ }}}}@@ -1181,11 +1393,11 @@ void TestCompositeOpInversion::testF16Modes()KisColorPairSampler samplerF16;samplerF16.alphaValues = generateOpacityValues<half>();- samplerF16.colorValues = generateWideColorValues<half>();+ samplerF16.redColorValues = generateWideColorValues<half>();KisColorPairSampler samplerF32;samplerF32.alphaValues = generateOpacityValues<float>();- samplerF32.colorValues = generateWideColorValues<float>();+ samplerF32.redColorValues = generateWideColorValues<float>();for (auto itF16 = samplerF16.begin(), itF32 = samplerF32.begin(); itF16 != samplerF16.end(); ++itF16, ++itF32) {@@ -1241,8 +1453,7 @@ QString csShortName(const KoID &depthId)return "error";}--void TestCompositeOpInversion::generateSampleSheets_data()+void TestCompositeOpInversion::generateSampleSheetsLong_data(){auto ids = generateCompositeOpIdSet();@@ -1255,14 +1466,22 @@ void TestCompositeOpInversion::generateSampleSheets_data()return id;};- std::vector<KoID> depthIds = {Integer16BitsColorDepthID, Float32BitsColorDepthID, Float16BitsColorDepthID};+ for (auto it = ids.begin(); it != ids.end(); ++it) {+ const QString id = it->first;+ const TestFlags flags = it->second;+ const bool isHDR = flags.testFlag(HDR);+ std::vector<KoID> depthIds;++ if (flags.testFlag(GenerateF32SampleSheetOnly)) {+ depthIds.push_back(Float32BitsColorDepthID);+ } else {+ depthIds.push_back(Integer16BitsColorDepthID);+ depthIds.push_back(Float32BitsColorDepthID);+ depthIds.push_back(Float16BitsColorDepthID);+ }- for (auto it = ids.begin(); it != ids.end(); ++it) {for (auto depthIt = depthIds.begin(); depthIt != depthIds.end(); ++depthIt) {- const QString id = it->first;- const TestFlags flags = it->second;- const bool isHDR = flags.testFlag(HDR);if (id == COMPOSITE_DISSOLVE) continue;@@ -1281,172 +1500,6 @@ void TestCompositeOpInversion::generateSampleSheets_data()}}-#include <QPainter>-void TestCompositeOpInversion::generateSampleSheets()-{- QFETCH(QString, id);- QFETCH(TestFlags, flags);- QFETCH(KoID, depthId);-- const KoColorSpace* csF32 = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), depthId.id(), 0);- const KoCompositeOp *opF32 = createOp(csF32, id, flags.testFlag(HDR));--- QImage image(QSize(768, 1024), QImage::Format_ARGB32);---- auto createColor = [] (const KoColorSpace *cs, QRgb value) {- KoColor c(cs);-- if (cs->colorDepthId() == Float32BitsColorDepthID) {- float *ptr = reinterpret_cast<float*>(c.data());- ptr[0] = KoColorSpaceMaths<quint8, float>::scaleToA(qRed(value));- ptr[1] = KoColorSpaceMaths<quint8, float>::scaleToA(qGreen(value));- ptr[2] = KoColorSpaceMaths<quint8, float>::scaleToA(qBlue(value));- ptr[3] = KoColorSpaceMaths<quint8, float>::scaleToA(qAlpha(value));- } else if (cs->colorDepthId() == Float16BitsColorDepthID) {- half *ptr = reinterpret_cast<half*>(c.data());- ptr[0] = KoColorSpaceMaths<quint8, half>::scaleToA(qRed(value));- ptr[1] = KoColorSpaceMaths<quint8, half>::scaleToA(qGreen(value));- ptr[2] = KoColorSpaceMaths<quint8, half>::scaleToA(qBlue(value));- ptr[3] = KoColorSpaceMaths<quint8, half>::scaleToA(qAlpha(value));- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- quint16 *ptr = reinterpret_cast<quint16*>(c.data());- ptr[2] = KoColorSpaceMaths<quint8, quint16>::scaleToA(qRed(value));- ptr[1] = KoColorSpaceMaths<quint8, quint16>::scaleToA(qGreen(value));- ptr[0] = KoColorSpaceMaths<quint8, quint16>::scaleToA(qBlue(value));- ptr[3] = KoColorSpaceMaths<quint8, quint16>::scaleToA(qAlpha(value));- } else {- qFatal("bit depth is not implemented");- }-- return c;- };-- auto createQRgb = [] (const KoColorSpace *cs, const KoColor &c) {- QRgb result = 0;-- if (cs->colorDepthId() == Float32BitsColorDepthID) {- const float *ptr = reinterpret_cast<const float*>(c.data());- result = qRgba(- KoColorSpaceMaths<float, quint8>::scaleToA(ptr[0]),- KoColorSpaceMaths<float, quint8>::scaleToA(ptr[1]),- KoColorSpaceMaths<float, quint8>::scaleToA(ptr[2]),- KoColorSpaceMaths<float, quint8>::scaleToA(ptr[3]));- } else if (cs->colorDepthId() == Float16BitsColorDepthID) {- const half *ptr = reinterpret_cast<const half*>(c.data());- result = qRgba(- KoColorSpaceMaths<half, quint8>::scaleToA(ptr[0]),- KoColorSpaceMaths<half, quint8>::scaleToA(ptr[1]),- KoColorSpaceMaths<half, quint8>::scaleToA(ptr[2]),- KoColorSpaceMaths<half, quint8>::scaleToA(ptr[3]));- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- const quint16 *ptr = reinterpret_cast<const quint16*>(c.data());- result = qRgba(- KoColorSpaceMaths<quint16, quint8>::scaleToA(ptr[2]),- KoColorSpaceMaths<quint16, quint8>::scaleToA(ptr[1]),- KoColorSpaceMaths<quint16, quint8>::scaleToA(ptr[0]),- KoColorSpaceMaths<quint16, quint8>::scaleToA(ptr[3]));- } else {- qFatal("bit depth is not implemented");- }-- return result;- };--- auto drawVerticalGradient =- [&image, createColor, createQRgb, opF32, csF32] (const QPoint &offset,- auto dstGradient,- auto srcGradient,- const QString &dstText,- const QString &srcText) {- for (int y = 0; y < 256; y++) {- for (int x = 0; x < 256; x++) {- KoColor dst = createColor(csF32, dstGradient(x));- KoColor src = createColor(csF32, srcGradient(y));-- opF32->composite(dst.data(), 0, src.data(), 0,- 0, 0,- 1, 1,- OPACITY_OPAQUE_F);-- image.setPixel(x + offset.x(), y + offset.y(), createQRgb(csF32, dst));- }- }-- QPainter gc(&image);-- QFont font;- font.setPointSize(10);- gc.setFont(font);- gc.setRenderHints(QPainter::TextAntialiasing);- gc.setPen(QPen(Qt::black, 1));- gc.drawText(offset + QPoint(100,100) + QPoint(1,1), QString("s: %1").arg(srcText));- gc.drawText(offset + QPoint(100,115) + QPoint(1,1), QString("d: %1").arg(dstText));- };-- auto r2w = [] (int i) { return qRgba(255, i, i, 255);};- auto g2w = [] (int i) { return qRgba(i, 255, i, 255);};- auto b2w = [] (int i) { return qRgba(i, i, 255, 255);};-- auto r2k = [] (int i) { return qRgba(255 - i, 0, 0, 255);};- auto g2k = [] (int i) { return qRgba(0, 255 - i, 0, 255);};- auto b2k = [] (int i) { return qRgba(0, 0, 255 - i, 255);};-- auto r2a = [] (int i) { return qRgba(255, 0, 0, 255 - i);};- auto g2a = [] (int i) { return qRgba(0, 255, 0, 255 - i);};- auto b2a = [] (int i) { return qRgba(0, 0, 255, 255 - i);};-- auto w2k = [] (int i) { return qRgba(255 - i, 255 - i, 255 - i, 255);};- auto w2a = [] (int i) { return qRgba(255, 255, 255, 255 - i);};- auto k2a = [] (int i) { return qRgba(0, 0, 0, 255 - i);};-- auto generateSheet = [&] (const QString &baseName, auto dstGradient) {- drawVerticalGradient(QPoint(0 * 256, 0 * 256), dstGradient, r2w, baseName, "r2w");- drawVerticalGradient(QPoint(1 * 256, 0 * 256), dstGradient, r2k, baseName, "r2k");- drawVerticalGradient(QPoint(2 * 256, 0 * 256), dstGradient, r2a, baseName, "r2a");-- drawVerticalGradient(QPoint(0 * 256, 1 * 256), dstGradient, g2w, baseName, "g2w");- drawVerticalGradient(QPoint(1 * 256, 1 * 256), dstGradient, g2k, baseName, "g2k");- drawVerticalGradient(QPoint(2 * 256, 1 * 256), dstGradient, g2a, baseName, "g2a");-- drawVerticalGradient(QPoint(0 * 256, 2 * 256), dstGradient, b2w, baseName, "b2w");- drawVerticalGradient(QPoint(1 * 256, 2 * 256), dstGradient, b2k, baseName, "b2k");- drawVerticalGradient(QPoint(2 * 256, 2 * 256), dstGradient, b2a, baseName, "b2a");-- drawVerticalGradient(QPoint(0 * 256, 3 * 256), dstGradient, w2k, baseName, "w2k");- drawVerticalGradient(QPoint(1 * 256, 3 * 256), dstGradient, w2a, baseName, "w2a");- drawVerticalGradient(QPoint(2 * 256, 3 * 256), dstGradient, k2a, baseName, "k2a");--- QString hdrString = flags.testFlag(HDR) ? "_hdr" : "_sdr";-- if (id == COMPOSITE_BURN || id == COMPOSITE_LINEAR_BURN || id == COMPOSITE_PIN_LIGHT) {- hdrString = "";- }-- image.save(QString("sample_sheet_%1%2_%3_%4.png")- .arg(id,- hdrString,- baseName,- csShortName(csF32->colorDepthId())));- };-- generateSheet("r2w", r2w);- generateSheet("r2k", r2k);- generateSheet("w2k", w2k);- generateSheet("w2a", w2a);- generateSheet("k2a", k2a);--}--void TestCompositeOpInversion::generateSampleSheetsLong_data()-{- generateSampleSheets_data();-}-void TestCompositeOpInversion::generateSampleSheetsLong(){QFETCH(QString, id);@@ -1564,15 +1617,15 @@ void TestCompositeOpInversion::generateSampleSheetsLong()};auto r2w = [&] (qreal i) { return makeQRgba64F(1.0, i, i, 1.0);};- auto g2w = [&] (qreal i) { return makeQRgba64F(i, 1.0, i, 1.0);};+ //auto g2w = [&] (qreal i) { return makeQRgba64F(i, 1.0, i, 1.0);};auto b2w = [&] (qreal i) { return makeQRgba64F(i, i, 1.0, 1.0);};auto r2k = [&] (qreal i) { return makeQRgba64F(1.0 - i, 0, 0, 1.0);};- auto g2k = [&] (qreal i) { return makeQRgba64F(0, 1.0 - i, 0, 1.0);};+ //auto g2k = [&] (qreal i) { return makeQRgba64F(0, 1.0 - i, 0, 1.0);};auto b2k = [&] (qreal i) { return makeQRgba64F(0, 0, 1.0 - i, 1.0);};auto r2a = [&] (qreal i) { return makeQRgba64F(1.0, 0, 0, 1.0 - i);};- auto g2a = [&] (qreal i) { return makeQRgba64F(0, 1.0, 0, 1.0 - i);};+ //auto g2a = [&] (qreal i) { return makeQRgba64F(0, 1.0, 0, 1.0 - i);};auto b2a = [&] (qreal i) { return makeQRgba64F(0, 0, 1.0, 1.0 - i);};auto w2k = [&] (qreal i) { return makeQRgba64F(1.0 - i, 1.0 - i, 1.0 - i, 1.0);};@@ -1646,8 +1699,56 @@ void TestCompositeOpInversion::testColor()OPACITY_OPAQUE_F);qDebug() << ppVar(dst);+}++void TestCompositeOpInversion::testToneMappingPositive()+{+ auto testToneMapping = [&] (const QLatin1String &name, auto HSXType) {+ float r = 0.92727380990982;+ float g = 0.95727380990982;+ float b = 1.15454604625702;++ qDebug();+ qDebug() << "src:" << ppVar(r) << ppVar(g) << ppVar(b);++ ToneMapping<decltype(HSXType), float>(r, g, b);++ QVERIFY(r <= g);+ QVERIFY(g <= b);++ qDebug() << name << ppVar(r) << ppVar(g) << ppVar(b);+ };+++ testToneMapping(QLatin1String("HSV"), HSVType{});+ testToneMapping(QLatin1String("HSL"), HSLType{});+ testToneMapping(QLatin1String("HSI"), HSIType{});+ testToneMapping(QLatin1String("HSY"), HSYType{});+}++void TestCompositeOpInversion::testToneMappingNegative()+{+ auto testToneMapping = [&] (const QLatin1String &name, auto HSXType) {+ float r = 0.12727380990982;+ float g = 0.12727380990982;+ float b = -0.15454604625702;++ qDebug();+ qDebug() << "src:" << ppVar(r) << ppVar(g) << ppVar(b);++ ToneMapping<decltype(HSXType), float>(r, g, b);++ QVERIFY(r >= g);+ QVERIFY(g >= b);++ qDebug() << name << ppVar(r) << ppVar(g) << ppVar(b);+ };+ testToneMapping(QLatin1String("HSV"), HSVType{});+ testToneMapping(QLatin1String("HSL"), HSLType{});+ testToneMapping(QLatin1String("HSI"), HSIType{});+ testToneMapping(QLatin1String("HSY"), HSYType{});}SIMPLE_TEST_MAIN(TestCompositeOpInversion)diff --git a/libs/pigment/tests/TestCompositeOpInversion.h b/libs/pigment/tests/TestCompositeOpInversion.hindex 4c2ff7f66a..278d18253b 100644--- a/libs/pigment/tests/TestCompositeOpInversion.h+++ b/libs/pigment/tests/TestCompositeOpInversion.h@@ -17,12 +17,15 @@ private Q_SLOTS:void test_data();void testColorPairSampler();+ void testColorPairSamplerRGB();void testF32ModesNaN();void testF32ModesNaN_data();+#if 0void testU16ModesConsistent();void testU16ModesConsistent_data();+#endifvoid testF32vsU16ConsistencyInSDR_data();void testF32vsU16ConsistencyInSDR();@@ -42,21 +45,27 @@ private Q_SLOTS:void testPreservesLooseNegative();void testPreservesLooseNegative_data();- void dumpOpCategories();+ void testToneMappingPositive();+ void testToneMappingNegative();+- void generateSampleSheets();- void generateSampleSheets_data();+ void dumpOpCategories();+private:+ /// Uncomment if you want to generate the sample+ /// sheets of every blendmode to verify their contiguityvoid generateSampleSheetsLong_data();void generateSampleSheetsLong();- void testColor();-private:// TODO: disabled for nowvoid testF16Modes();void testF16Modes_data();+ /// just a simple test case to test exactly one color+ /// during debugging+ void testColor();+private:void testNegativeImpl(bool useStrictZeroCheck);void testPreservesSdrRangeImpl(bool useStrictRange);diff --git a/libs/pigment/tests/TestCompositeOpInversion_p.cpp b/libs/pigment/tests/TestCompositeOpInversion_p.cppindex 7d28575360..b9114bf45e 100644--- a/libs/pigment/tests/TestCompositeOpInversion_p.cpp+++ b/libs/pigment/tests/TestCompositeOpInversion_p.cpp@@ -204,64 +204,72 @@ private:template<class Traits>struct RgbOpsStorage {- typedef float Arg;+ typedef typename Traits::channels_type channels_type;static const qint32 red_pos = Traits::red_pos;static const qint32 green_pos = Traits::green_pos;static const qint32 blue_pos = Traits::blue_pos;- template<void compositeFunc(Arg, Arg, Arg, Arg&, Arg&, Arg&)>-+ template<void compositeFunc(float, float, float, float&, float&, float&)>void add(const KoColorSpace* cs, const QString& id, const QString& category) {m_ops.insert(id, new KoCompositeOpGenericHSL<Traits, compositeFunc>(cs, id, category));}+ template<typename Functor>+ void add(const KoColorSpace* cs, const QString& id, const QString& category) {+ m_ops.insert(id, new KoCompositeOpGenericHSLFunctor<Traits, Functor>(cs, id, category));+ }++void add(const KoColorSpace* cs) {- add<&cfTangentNormalmap <HSYType,Arg> >(cs, COMPOSITE_TANGENT_NORMALMAP , KoCompositeOp::categoryMisc());- add<&cfReorientedNormalMapCombine <HSYType, Arg> >(cs, COMPOSITE_COMBINE_NORMAL, KoCompositeOp::categoryMisc());-- add<&cfColor <HSYType,Arg> >(cs, COMPOSITE_COLOR , KoCompositeOp::categoryHSY());- add<&cfHue <HSYType,Arg> >(cs, COMPOSITE_HUE , KoCompositeOp::categoryHSY());- add<&cfSaturation <HSYType,Arg> >(cs, COMPOSITE_SATURATION , KoCompositeOp::categoryHSY());- add<&cfIncreaseSaturation<HSYType,Arg> >(cs, COMPOSITE_INC_SATURATION, KoCompositeOp::categoryHSY());- add<&cfDecreaseSaturation<HSYType,Arg> >(cs, COMPOSITE_DEC_SATURATION, KoCompositeOp::categoryHSY());- add<&cfLightness <HSYType,Arg> >(cs, COMPOSITE_LUMINIZE , KoCompositeOp::categoryHSY());- add<&cfIncreaseLightness <HSYType,Arg> >(cs, COMPOSITE_INC_LUMINOSITY, KoCompositeOp::categoryHSY());- add<&cfDecreaseLightness <HSYType,Arg> >(cs, COMPOSITE_DEC_LUMINOSITY, KoCompositeOp::categoryHSY());- add<&cfDarkerColor <HSYType,Arg> >(cs, COMPOSITE_DARKER_COLOR , KoCompositeOp::categoryDark());//darker color as PSD does it//- add<&cfLighterColor <HSYType,Arg> >(cs, COMPOSITE_LIGHTER_COLOR , KoCompositeOp::categoryLight());//lighter color as PSD does it//-- add<&cfLambertLighting <HSIType,Arg> >(cs, COMPOSITE_LAMBERT_LIGHTING, KoCompositeOp::categoryMix());- add<&cfLambertLightingGamma2_2 <HSIType, Arg> >(cs, COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, KoCompositeOp::categoryMix());-- add<&cfColor <HSIType,Arg> >(cs, COMPOSITE_COLOR_HSI , KoCompositeOp::categoryHSI());- add<&cfHue <HSIType,Arg> >(cs, COMPOSITE_HUE_HSI , KoCompositeOp::categoryHSI());- add<&cfSaturation <HSIType,Arg> >(cs, COMPOSITE_SATURATION_HSI , KoCompositeOp::categoryHSI());- add<&cfIncreaseSaturation<HSIType,Arg> >(cs, COMPOSITE_INC_SATURATION_HSI, KoCompositeOp::categoryHSI());- add<&cfDecreaseSaturation<HSIType,Arg> >(cs, COMPOSITE_DEC_SATURATION_HSI, KoCompositeOp::categoryHSI());- add<&cfLightness <HSIType,Arg> >(cs, COMPOSITE_INTENSITY , KoCompositeOp::categoryHSI());- add<&cfIncreaseLightness <HSIType,Arg> >(cs, COMPOSITE_INC_INTENSITY , KoCompositeOp::categoryHSI());- add<&cfDecreaseLightness <HSIType,Arg> >(cs, COMPOSITE_DEC_INTENSITY , KoCompositeOp::categoryHSI());-- add<&cfColor <HSLType,Arg> >(cs, COMPOSITE_COLOR_HSL , KoCompositeOp::categoryHSL());- add<&cfHue <HSLType,Arg> >(cs, COMPOSITE_HUE_HSL , KoCompositeOp::categoryHSL());- add<&cfSaturation <HSLType,Arg> >(cs, COMPOSITE_SATURATION_HSL , KoCompositeOp::categoryHSL());- add<&cfIncreaseSaturation<HSLType,Arg> >(cs, COMPOSITE_INC_SATURATION_HSL, KoCompositeOp::categoryHSL());- add<&cfDecreaseSaturation<HSLType,Arg> >(cs, COMPOSITE_DEC_SATURATION_HSL, KoCompositeOp::categoryHSL());- add<&cfLightness <HSLType,Arg> >(cs, COMPOSITE_LIGHTNESS , KoCompositeOp::categoryHSL());- add<&cfIncreaseLightness <HSLType,Arg> >(cs, COMPOSITE_INC_LIGHTNESS , KoCompositeOp::categoryHSL());- add<&cfDecreaseLightness <HSLType,Arg> >(cs, COMPOSITE_DEC_LIGHTNESS , KoCompositeOp::categoryHSL());-- add<&cfColor <HSVType,Arg> >(cs, COMPOSITE_COLOR_HSV , KoCompositeOp::categoryHSV());- add<&cfHue <HSVType,Arg> >(cs, COMPOSITE_HUE_HSV , KoCompositeOp::categoryHSV());- add<&cfSaturation <HSVType,Arg> >(cs, COMPOSITE_SATURATION_HSV , KoCompositeOp::categoryHSV());- add<&cfIncreaseSaturation<HSVType,Arg> >(cs, COMPOSITE_INC_SATURATION_HSV, KoCompositeOp::categoryHSV());- add<&cfDecreaseSaturation<HSVType,Arg> >(cs, COMPOSITE_DEC_SATURATION_HSV, KoCompositeOp::categoryHSV());- add<&cfLightness <HSVType,Arg> >(cs, COMPOSITE_VALUE , KoCompositeOp::categoryHSV());- add<&cfIncreaseLightness <HSVType,Arg> >(cs, COMPOSITE_INC_VALUE , KoCompositeOp::categoryHSV());- add<&cfDecreaseLightness <HSVType,Arg> >(cs, COMPOSITE_DEC_VALUE , KoCompositeOp::categoryHSV());- }+ add<CFTangentNormalmap <HSYType,channels_type> >(cs, COMPOSITE_TANGENT_NORMALMAP , KoCompositeOp::categoryMisc());+ add<CFReorientedNormalMapCombine<HSYType, channels_type>>(cs, COMPOSITE_COMBINE_NORMAL, KoCompositeOp::categoryMisc());+ add<CFColor<HSYType, channels_type>>(cs, COMPOSITE_COLOR, KoCompositeOp::categoryHSY());+ add<CFHue<HSYType, channels_type>>(cs, COMPOSITE_HUE, KoCompositeOp::categoryHSY());+ add<CFSaturation<HSYType, channels_type>>(cs, COMPOSITE_SATURATION, KoCompositeOp::categoryHSY());+ add<CFIncreaseSaturation<HSYType, channels_type>>(cs, COMPOSITE_INC_SATURATION, KoCompositeOp::categoryHSY());+ add<CFDecreaseSaturation<HSYType, channels_type>>(cs, COMPOSITE_DEC_SATURATION, KoCompositeOp::categoryHSY());++ add<CFLightness<HSYType,channels_type>>(cs, COMPOSITE_LUMINIZE, KoCompositeOp::categoryHSY());+ add<CFIncreaseLightness<HSYType,channels_type>>(cs, COMPOSITE_INC_LUMINOSITY, KoCompositeOp::categoryHSY());+ add<CFDecreaseLightness<HSYType,channels_type>>(cs, COMPOSITE_DEC_LUMINOSITY, KoCompositeOp::categoryHSY());+++ add<CFDarkerColor<HSYType, channels_type>>(cs, COMPOSITE_DARKER_COLOR, KoCompositeOp::categoryDark()); //darker color as PSD does it//+ add<CFLighterColor<HSYType, channels_type>>(cs, COMPOSITE_LIGHTER_COLOR, KoCompositeOp::categoryLight()); //lighter color as PSD does it//++ add<CFLambertLighting<HSIType,channels_type>>(cs, COMPOSITE_LAMBERT_LIGHTING, KoCompositeOp::categoryMix());+ add<CFLambertLightingGamma2_2<HSIType, channels_type>>(cs, COMPOSITE_LAMBERT_LIGHTING_GAMMA_2_2, KoCompositeOp::categoryMix());++ add<CFColor <HSIType, channels_type> >(cs, COMPOSITE_COLOR_HSI , KoCompositeOp::categoryHSI());+ add<CFHue <HSIType, channels_type> >(cs, COMPOSITE_HUE_HSI , KoCompositeOp::categoryHSI());+ add<CFSaturation <HSIType, channels_type> >(cs, COMPOSITE_SATURATION_HSI , KoCompositeOp::categoryHSI());+ add<CFIncreaseSaturation<HSIType, channels_type> >(cs, COMPOSITE_INC_SATURATION_HSI, KoCompositeOp::categoryHSI());+ add<CFDecreaseSaturation<HSIType, channels_type> >(cs, COMPOSITE_DEC_SATURATION_HSI, KoCompositeOp::categoryHSI());+ add<CFLightness <HSIType, channels_type> >(cs, COMPOSITE_INTENSITY , KoCompositeOp::categoryHSI());+ add<CFIncreaseLightness <HSIType, channels_type> >(cs, COMPOSITE_INC_INTENSITY , KoCompositeOp::categoryHSI());+ add<CFDecreaseLightness <HSIType, channels_type> >(cs, COMPOSITE_DEC_INTENSITY , KoCompositeOp::categoryHSI());++ add<CFColor <HSLType, channels_type> >(cs, COMPOSITE_COLOR_HSL , KoCompositeOp::categoryHSL());+ add<CFHue <HSLType, channels_type> >(cs, COMPOSITE_HUE_HSL , KoCompositeOp::categoryHSL());+ add<CFSaturation <HSLType, channels_type> >(cs, COMPOSITE_SATURATION_HSL , KoCompositeOp::categoryHSL());+ add<CFIncreaseSaturation<HSLType, channels_type> >(cs, COMPOSITE_INC_SATURATION_HSL, KoCompositeOp::categoryHSL());+ add<CFDecreaseSaturation<HSLType, channels_type> >(cs, COMPOSITE_DEC_SATURATION_HSL, KoCompositeOp::categoryHSL());+ add<CFLightness <HSLType, channels_type> >(cs, COMPOSITE_LIGHTNESS , KoCompositeOp::categoryHSL());+ add<CFIncreaseLightness <HSLType, channels_type> >(cs, COMPOSITE_INC_LIGHTNESS , KoCompositeOp::categoryHSL());+ add<CFDecreaseLightness <HSLType, channels_type> >(cs, COMPOSITE_DEC_LIGHTNESS , KoCompositeOp::categoryHSL());++ add<CFColor <HSVType, channels_type> >(cs, COMPOSITE_COLOR_HSV , KoCompositeOp::categoryHSV());+ add<CFHue <HSVType, channels_type> >(cs, COMPOSITE_HUE_HSV , KoCompositeOp::categoryHSV());+ add<CFSaturation <HSVType, channels_type> >(cs, COMPOSITE_SATURATION_HSV , KoCompositeOp::categoryHSV());+ add<CFIncreaseSaturation<HSVType, channels_type> >(cs, COMPOSITE_INC_SATURATION_HSV, KoCompositeOp::categoryHSV());+ add<CFDecreaseSaturation<HSVType, channels_type> >(cs, COMPOSITE_DEC_SATURATION_HSV, KoCompositeOp::categoryHSV());+ add<CFLightness <HSVType, channels_type> >(cs, COMPOSITE_VALUE , KoCompositeOp::categoryHSV());+ add<CFIncreaseLightness <HSVType, channels_type> >(cs, COMPOSITE_INC_VALUE , KoCompositeOp::categoryHSV());+ add<CFDecreaseLightness <HSVType, channels_type> >(cs, COMPOSITE_DEC_VALUE , KoCompositeOp::categoryHSV());++}bool isInitialized() const {return !m_ops.isEmpty();@@ -276,11 +284,11 @@ private:QMap<QString, KoCompositeOp*> m_ops;};-OpsStorage<KoRgbU16Traits> sU16Ops;+OpsStorage<KoBgrU16Traits> sU16Ops;OpsStorage<KoRgbF16Traits> sF16Ops;OpsStorage<KoRgbF32Traits> sF32Ops;-RgbOpsStorage<KoRgbU16Traits> sU16RgbOps;+RgbOpsStorage<KoBgrU16Traits> sU16RgbOps;RgbOpsStorage<KoRgbF16Traits> sF16RgbOps;RgbOpsStorage<KoRgbF32Traits> sF32RgbOps;