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++
temp
Dmitry Kazakovfb018a93e001
diff --git a/libs/pigment/KoColorSpaceMaths.h b/libs/pigment/KoColorSpaceMaths.hindex e78edde9dd..9891c22c94 100644--- a/libs/pigment/KoColorSpaceMaths.h+++ b/libs/pigment/KoColorSpaceMaths.h@@ -273,6 +273,23 @@ public:return qBound<dst_compositetype>(KoColorSpaceMathsTraits<_Tdst>::min, val, KoColorSpaceMathsTraits<_Tdst>::max);}+ inline static _T clampChannelToSDR(_T val) {+ // integer version, float versions are specialized separately+ return val;+ }++ inline static dst_compositetype clampToSDR(dst_compositetype val) {+ return qBound<dst_compositetype>(KoColorSpaceMathsTraits<_Tdst>::zeroValue, val, KoColorSpaceMathsTraits<_Tdst>::unitValue);+ }++ inline static dst_compositetype clampToSDRTop(dst_compositetype val) {+ return qMin<dst_compositetype>(val, KoColorSpaceMathsTraits<_Tdst>::unitValue);+ }++ inline static dst_compositetype clampToSDRBottom(dst_compositetype val) {+ return qMax<dst_compositetype>(KoColorSpaceMathsTraits<_Tdst>::zeroValue, val);+ }+/*** Clamps the composite type on higher border only. That is a fast path* for scale-only transformations@@ -284,6 +301,14 @@ public:inline static _T isUnsafeAsDivisor(_T value) {return value == KoColorSpaceMathsTraits<_T>::zeroValue;}++ inline static bool isUnitValue(_T value) {+ return value == KoColorSpaceMathsTraits<_T>::unitValue;+ }++ inline static bool isZeroValue(_T value) {+ return value == KoColorSpaceMathsTraits<_T>::zeroValue;+ }};//------------------------------ double specialization ------------------------------//@@ -381,6 +406,21 @@ inline float KoColorSpaceMaths<float>::isUnsafeAsDivisor(float value) {return value < 1e-6; // negative values are also unsafe!}+template<>+inline bool KoColorSpaceMaths<float>::isUnitValue(float value) {+ return qFuzzyCompare(value, KoColorSpaceMathsTraits<float>::unitValue);+}++template<>+inline bool KoColorSpaceMaths<float>::isZeroValue(float value) {+ return qFuzzyIsNull(value);+}++template<>+inline float KoColorSpaceMaths<float>::clampChannelToSDR(float val) {+ return qBound<float>(KoColorSpaceMathsTraits<float>::zeroValue, val, KoColorSpaceMathsTraits<float>::unitValue);+}+//------------------------------ half specialization ------------------------------//#ifdef HAVE_OPENEXR@@ -457,6 +497,12 @@ inline half KoColorSpaceMaths<half>::isUnsafeAsDivisor(half value) {return value < 1e-6; // negative values are also unsafe!}+template<>+inline half KoColorSpaceMaths<half>::clampChannelToSDR(half val) {+ return qBound<half>(KoColorSpaceMathsTraits<half>::zeroValue, val, KoColorSpaceMathsTraits<half>::unitValue);+}++#endif//------------------------------ quint8 specialization ------------------------------//@@ -604,6 +650,26 @@ namespace Arithmeticinline T clamp(typename KoColorSpaceMathsTraits<T>::compositetype a) {return KoColorSpaceMaths<T>::clamp(a);}++ template<class T>+ inline T clampToSDR(typename KoColorSpaceMathsTraits<T>::compositetype a) {+ return KoColorSpaceMaths<T>::clampToSDR(a);+ }++ template<class T>+ inline T clampChannelToSDR(T a) {+ return KoColorSpaceMaths<T>::clampChannelToSDR(a);+ }++ template<class T>+ inline T clampToSDRTop(typename KoColorSpaceMathsTraits<T>::compositetype a) {+ return KoColorSpaceMaths<T>::clampToSDRTop(a);+ }++ template<class T>+ inline T clampToSDRBottom(typename KoColorSpaceMathsTraits<T>::compositetype a) {+ return KoColorSpaceMaths<T>::clampToSDRBottom(a);+ }template<class T>inline T min(T a, T b, T c) {diff --git a/libs/pigment/compositeops/KoCompositeOpBase.h b/libs/pigment/compositeops/KoCompositeOpBase.hindex fb2a31237f..4e1f9061b9 100644--- a/libs/pigment/compositeops/KoCompositeOpBase.h+++ b/libs/pigment/compositeops/KoCompositeOpBase.h@@ -8,7 +8,7 @@#define KOCOMPOSITEOP_BASE_H_#include <KoCompositeOp.h>-#include "KoCompositeOpFunctions.h"+#include <KoColorSpaceMaths.h>/*** A template base class that can be used for most composite modes/opsdiff --git a/libs/pigment/compositeops/KoCompositeOpFunctions.h b/libs/pigment/compositeops/KoCompositeOpFunctions.hindex 56e67cbf34..2245901118 100644--- a/libs/pigment/compositeops/KoCompositeOpFunctions.h+++ b/libs/pigment/compositeops/KoCompositeOpFunctions.h@@ -213,9 +213,10 @@ inline T colorBurnHelper(T src, T dst) {// Handle the case where the denominator is 0. See color dodge for a// detailed explanationif(src == zeroValue<T>()) {- return dst == unitValue<T>() ? zeroValue<T>() : KoColorSpaceMathsTraits<T>::max;+ return dst == unitValue<T>() ? inv(dst) : unitValue<T>();}- return clamp<T>(div(inv(dst), src));++ return clampToSDR<T>(div(inv(dst), src));}// Integer version of color burn@@ -234,14 +235,14 @@ cfColorBurn(T src, T dst) {const T result = colorBurnHelper(src, dst);// Constantly dividing by small numbers can quickly make the result// become infinity or NaN, so we check that and correct (kind of clamping)- return inv(std::isfinite(result) ? result : KoColorSpaceMathsTraits<T>::max);+ return inv(std::isfinite(result) ? result : KoColorSpaceMathsTraits<T>::unitValue);}template<class T>inline T cfLinearBurn(T src, T dst) {using namespace Arithmetic;typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;- return clamp<T>(composite_type(src) + dst - unitValue<T>());+ return clampToSDR<T>(composite_type(src) + dst - unitValue<T>());}template<class T>@@ -257,10 +258,10 @@ inline T colorDodgeHelper(T src, T dst) {// this case we also treat the denominator as an infinitely small number,// and the numerator can remain as 0, so dividing 0 over a number (no matter// how small it is) gives 0.- if (src == unitValue<T>()) {- return dst == zeroValue<T>() ? zeroValue<T>() : KoColorSpaceMathsTraits<T>::max;+ if (KoColorSpaceMaths<T>::isUnitValue(src)) {+ return KoColorSpaceMaths<T>::isZeroValue(dst) ? zeroValue<T>() : KoColorSpaceMathsTraits<T>::unitValue;}- return Arithmetic::clamp<T>(div(dst, inv(src)));+ return Arithmetic::clampToSDR<T>(div(dst, inv(src)));}// Integer version of color dodge@@ -277,7 +278,7 @@ cfColorDodge(T src, T dst) {const T result = colorDodgeHelper(src, dst);// Constantly dividing by small numbers can quickly make the result// become infinity or NaN, so we check that and correct (kind of clamping)- return std::isfinite(result) ? result : KoColorSpaceMathsTraits<T>::max;+ return std::isfinite(result) ? result : KoColorSpaceMathsTraits<T>::unitValue;}template<class T>diff --git a/libs/pigment/compositeops/KoCompositeOpGeneric.h b/libs/pigment/compositeops/KoCompositeOpGeneric.hindex 0dbb10cf9c..00fcd5aec8 100644--- a/libs/pigment/compositeops/KoCompositeOpGeneric.h+++ b/libs/pigment/compositeops/KoCompositeOpGeneric.h@@ -7,7 +7,7 @@#ifndef _KOCOMPOSITEOP_GENERIC_H_#define _KOCOMPOSITEOP_GENERIC_H_-#include "KoCompositeOpFunctions.h"+//#include "KoCompositeOpFunctions.h"#include "KoCompositeOpBase.h"/**@@ -74,7 +74,12 @@ public:blend(srcInBlendSpace, srcAlpha,dstInBlendSpace, dstAlpha,compositeFunc(srcInBlendSpace, dstInBlendSpace));+++dst[i] = BlendingPolicy::fromAdditiveSpace(div(result, newDstAlpha));++ //qDebug() << i << ppVar(result) << ppVar(compositeFunc(srcInBlendSpace, dstInBlendSpace)) << div(result, newDstAlpha);}}}diff --git a/libs/pigment/compositeops/KoCompositeOps.h b/libs/pigment/compositeops/KoCompositeOps.hindex 5204fe2104..11bd934cab 100644--- a/libs/pigment/compositeops/KoCompositeOps.h+++ b/libs/pigment/compositeops/KoCompositeOps.h@@ -13,6 +13,7 @@#include <KoColorSpace.h>#include <KoColorSpaceTraits.h>#include <KoColorSpaceMaths.h>+#include <KoCompositeOpFunctions.h>#include "compositeops/KoCompositeOpGeneric.h"#include "compositeops/KoCompositeOpOver.h"diff --git a/libs/pigment/tests/KoCompositeOpFunctions2.h b/libs/pigment/tests/KoCompositeOpFunctions2.hnew file mode 100644index 0000000000..dd8bbd0e68--- /dev/null+++ b/libs/pigment/tests/KoCompositeOpFunctions2.h@@ -0,0 +1,1209 @@+/*+ * SPDX-FileCopyrightText: 2011 Silvio Heinrich <[email protected]>+ *+ * SPDX-License-Identifier: LGPL-2.1-or-later+*/++#ifdef KOCOMPOSITEOP_FUNCTIONS_H_+#error "ssksjdkjs"+#endif++#ifndef KOCOMPOSITEOP_FUNCTIONS_H_+#define KOCOMPOSITEOP_FUNCTIONS_H_++#include <KoColorSpaceMaths.h>++#include <type_traits>+#include <cmath>++#ifdef HAVE_OPENEXR+#include "half.h"+#endif++template <typename T>+struct ClampPolicyInteger {+ using channels_type = T;+ using compositetype = typename KoColorSpaceMathsTraits<T>::compositetype;++ static inline channels_type clampInputSrc(channels_type value) {+ return value;+ }++ static inline channels_type clampResultAllowNegative(compositetype value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static inline channels_type clampResult(compositetype value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static inline channels_type clampInvertedResult(compositetype value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static inline compositetype fixInfiniteAfterDivision(compositetype value) {+ return value;+ }+};++template <typename T>+struct ClampPolicyFloatSDR {+ using channels_type = T;+ using compositetype = typename KoColorSpaceMathsTraits<T>::compositetype;++ static channels_type clampInputSrc(channels_type value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static channels_type clampResultAllowNegative(compositetype value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static inline channels_type clampResult(compositetype value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static channels_type clampInvertedResult(compositetype value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static compositetype fixInfiniteAfterDivision(compositetype value) {+ // Constantly dividing by small numbers can quickly make the result+ // become infinity or NaN, so we check that and correct (kind of clamping)+ return std::isfinite(value) ? value : KoColorSpaceMathsTraits<T>::unitValue;+ }+};++template <typename T>+struct ClampPolicyFloatHDR {+ using channels_type = T;+ using compositetype = typename KoColorSpaceMathsTraits<T>::compositetype;++ static channels_type clampInputSrc(channels_type value) {+ using namespace Arithmetic;+ return clampToSDR<channels_type>(value);+ }++ static channels_type clampResultAllowNegative(compositetype value) {+ return value;+ }++ static inline channels_type clampResult(compositetype value) {+ using namespace Arithmetic;+ return clampToSDRBottom<channels_type>(value);+ }++ static channels_type clampInvertedResult(compositetype value) {+ using namespace Arithmetic;+ return clampToSDRTop<channels_type>(value);+ }++ static compositetype fixInfiniteAfterDivision(compositetype value) {+ // Constantly dividing by small numbers can quickly make the result+ // become infinity or NaN, so we check that and correct (kind of clamping)+ return std::isfinite(value) ? value : KoColorSpaceMathsTraits<T>::max;+ }+};++namespace tmp {+Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool isNullValueClamped(double d)+{+ return d <= 0.000000000001;+}++Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool isNullValueClamped(float f)+{+ return f <= 0.00001f;+}++#ifdef HAVE_OPENEXR++Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool isNullValueClamped(half h)+{+ return h.isZero() || h.isNegative();+}++#endif /* HAVE_OPENEXR */++template <typename T>+Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool isNullValueClamped(T v)+{+ return v <= 0;+}++Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool isUnitValueClamped(double d)+{+ return d > 1.0 - 0.000000000001;+}++Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool isUnitValueClamped(float f)+{+ return f > 1.0 - 0.00001f;+}++#ifdef HAVE_OPENEXR++Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool isUnitValueClamped(half h)+{+ return h > 1.0f - 0.0001f;+}++#endif /* HAVE_OPENEXR */++template <typename T>+Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool isUnitValueClamped(T v)+{+ return v >= KoColorSpaceMathsTraits<T>::unitValue;+}+++template <typename T>+Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool isZeroValue(T v)+{+ return KoColorSpaceMaths<T>::isZeroValue(v);+}++template <typename T>+Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool isUnitValue(T v)+{+ return KoColorSpaceMaths<T>::isUnitValue(v);+}++}++template<class HSXType, class TReal>+inline void cfReorientedNormalMapCombine(TReal srcR, TReal srcG, TReal srcB, TReal& dstR, TReal& dstG, TReal& 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;+}++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<class HSXType, class TReal>+inline void cfLambertLighting(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, TReal& db)+{+ 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);+}++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);+}++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));+}++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));+}++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));+}++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);+}++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);+}++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);+}++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;+ }+ else {+ dr = sr;+ dg = sg;+ db = sb;+ }++}++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;+ }+ else {+ dr = sr;+ dg = sg;+ db = sb;+ }+}++template<class T,+ template <typename> typename ClampPolicy>+T cfColorBurn(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;++ src = clamp_policy::clampInputSrc(src);++ // Handle the case where the denominator is 0. See color dodge for a+ // detailed explanation+ if(tmp::isZeroValue(src)) {+ return !tmp::isUnitValueClamped(dst) ? zeroValue<T>() : clamp_policy::clampResultAllowNegative(dst);+ }++ return inv<T>(+ clamp_policy::clampInvertedResult(+ clamp_policy::fixInfiniteAfterDivision(+ div(inv(dst), src)+ )+ )+ );+}++template<class T,+ template <typename> typename ClampPolicy>+inline T cfLinearBurn(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;+ using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;++ src = clamp_policy::clampInputSrc(src);+ return clamp_policy::clampResult(composite_type(src) + dst - unitValue<T>());+}++template<typename T,+ template <typename> typename ClampPolicy>+inline T cfColorDodge(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;++ src = clamp_policy::clampInputSrc(src);++ // Handle the case where the denominator is 0.+ // When src is 1 then the denominator (1 - src) becomes 0, and to avoid+ // dividing by 0 we treat the denominator as an infinitely small number,+ // so the result of the formula would approach infinity. As in the generic+ // case, that result is clamped to the maximum value (which for integer+ // types is the same as the unit value).+ // Another special case is when both numerator and denominator are 0. In+ // this case we also treat the denominator as an infinitely small number,+ // and the numerator can remain as 0, so dividing 0 over a number (no matter+ // how small it is) gives 0.+ if (KoColorSpaceMaths<T>::isUnitValue(src)) {+ return tmp::isNullValueClamped(dst) ? zeroValue<T>() : KoColorSpaceMathsTraits<T>::unitValue;+ }++ return clamp_policy::clampResultAllowNegative(+ clamp_policy::fixInfiniteAfterDivision(+ div(dst, inv(src))+ )+ );+}++template<class T>+inline T cfAddition(T src, T dst) {+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return Arithmetic::clamp<T>(composite_type(src) + dst);+}++template<class T>+inline T cfSubtract(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return clamp<T>(composite_type(dst) - src);+}++template<class T>+inline T cfInverseSubtract(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return clamp<T>(composite_type(dst) - inv(src));+}++template<class T>+inline T cfExclusion(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ composite_type x = mul(src, dst);+ return clamp<T>(composite_type(dst) + src - (x + x));+}++template<class T>+inline T cfDivide(T src, T dst) {+ using namespace Arithmetic;+ //typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ if(isUnsafeAsDivisor(src))+ return (dst == zeroValue<T>()) ? zeroValue<T>() : unitValue<T>();++ return clamp<T>(div(dst, src));+}++template<class T>+inline T cfHardLight(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ composite_type src2 = composite_type(src) + src;++ if(src > halfValue<T>()) {+ // screen(src*2.0 - 1.0, dst)+ src2 -= unitValue<T>();++ // src2 is guaranteed to be smaller than unitValue<T>() now+ return Arithmetic::unionShapeOpacity(T(src2), dst);+ }++ // src2 is guaranteed to be smaller than unitValue<T>() due to 'if'+ return Arithmetic::mul(T(src2), dst);+}++template<class T>+inline T cfSoftLightSvg(T src, T dst) {+ using namespace Arithmetic;++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if(fsrc > 0.5) {+ qreal D = (fdst > 0.25) ? sqrt(fdst) : ((16.0*fdst - 12.0)*fdst + 4.0)*fdst;+ return scale<T>(fdst + (2.0*fsrc - 1.0) * (D - fdst));+ }++ return scale<T>(fdst - (1.0 - 2.0 * fsrc) * fdst * (1.0 - fdst));+}+++template<class T>+inline T cfSoftLight(T src, T dst) {+ using namespace Arithmetic;++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if(fsrc > 0.5) {+ return scale<T>(fdst + (2.0 * fsrc - 1.0) * (sqrt(fdst) - fdst));+ }++ return scale<T>(fdst - (1.0 - 2.0*fsrc) * fdst * (1.0 - fdst));+}++template<class T>+inline T cfVividLight(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ if(src < halfValue<T>()) {+ if(isUnsafeAsDivisor(src))+ return (dst == unitValue<T>()) ? unitValue<T>() : zeroValue<T>();++ // min(1,max(0,1-(1-dst) / (2*src)))+ composite_type src2 = composite_type(src) + src;+ composite_type dsti = inv(dst);+ return clamp<T>(unitValue<T>() - (dsti * unitValue<T>() / src2));+ }++ if(src == unitValue<T>())+ return (dst == zeroValue<T>()) ? zeroValue<T>() : unitValue<T>();++ // min(1,max(0, dst / (2*(1-src)))+ composite_type srci2 = inv(src);+ srci2 += srci2;+ return clamp<T>(composite_type(dst) * unitValue<T>() / srci2);+}++template<class T>+inline T cfPinLight(T src, T dst) {+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ // TODO: verify that the formula is correct (the first max would be useless here)+ // max(0, max(2*src-1, min(dst, 2*src)))+ composite_type src2 = composite_type(src) + src;+ composite_type a = qMin<composite_type>(dst, src2);+ composite_type b = qMax<composite_type>(src2-Arithmetic::unitValue<T>(), a);+ return T(b);+}++template<class T>+inline T cfArcTangent(T src, T dst) {+ using namespace Arithmetic;++ if(dst == zeroValue<T>())+ return (src == zeroValue<T>()) ? zeroValue<T>() : unitValue<T>();++ return scale<T>(2.0 * atan(scale<qreal>(src) / scale<qreal>(dst)) / Arithmetic::pi);+}++template<class T>+inline T cfAllanon(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ // (dst + src) / 2 [or (dst + src) * 0.5]+ return T((composite_type(src) + dst) * halfValue<T>() / unitValue<T>());+}++template<class T>+inline T cfLinearLight(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ // min(1,max(0,(dst + 2*src)-1))+ return clamp<T>((composite_type(src) + src + dst) - unitValue<T>());+}++template<class T>+inline T cfParallel(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ const bool srcIsSafe = !isUnsafeAsDivisor(src);+ const bool dstIsSafe = !isUnsafeAsDivisor(dst);++ if (!srcIsSafe || !dstIsSafe) {+ return zeroValue<T>();+ }++ // min(max(2 / (1/dst + 1/src), 0), 1)+ composite_type unit = unitValue<T>();+ composite_type s = div<T>(unit, src);+ composite_type d = div<T>(unit, dst);++ return clamp<T>((unit+unit) * unit / (d+s));+}++template<class T>+inline T cfEquivalence(T src, T dst) {+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ // 1 - abs(dst - src)+ composite_type x = composite_type(dst) - src;+ return (x < Arithmetic::zeroValue<T>()) ? T(-x) : T(x);+}++template<class T>+inline T cfGrainMerge(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return clamp<T>(composite_type(dst) + src - halfValue<T>());+}++template<class T>+inline T cfGrainExtract(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return clamp<T>(composite_type(dst) - src + halfValue<T>());+}++template<class T>+inline T cfHardMix(T src, T dst) {+ return (dst > Arithmetic::halfValue<T>()) ? cfColorDodge(src,dst) : cfColorBurn(src,dst);+}++template<class T>+inline T cfHardMixPhotoshop(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ const composite_type sum = composite_type(src) + dst;++ return sum > unitValue<T>() ? unitValue<T>() : zeroValue<T>();+}++// Approximation of the hard mix mode used by photoshop in the brush texturing+// In contrast to the normal hard mix, this produces antialiased edges, better+// for texturing the brush dab, at least visually+template<class T>+inline T cfHardMixSofterPhotoshop(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ const composite_type srcScaleFactor = static_cast<composite_type>(2);+ const composite_type dstScaleFactor = static_cast<composite_type>(3);++ return clamp<T>(dstScaleFactor * dst - srcScaleFactor * inv(src));+}++template<class T>+inline T cfAdditiveSubtractive(T src, T dst) {+ using namespace Arithmetic;+ // min(1,max(0,abs(sqr(CB)-sqr(CT))))+ qreal x = sqrt(scale<qreal>(dst)) - sqrt(scale<qreal>(src));+ return scale<T>((x < 0.0) ? -x : x);+}++template<class T>+inline T cfGammaDark(T src, T dst) {+ using namespace Arithmetic;++ if(src == zeroValue<T>())+ return zeroValue<T>();++ // power(dst, 1/src)+ return scale<T>(pow(scale<qreal>(dst), 1.0/scale<qreal>(src)));+}++template<class T>+inline T cfGammaLight(T src, T dst) {+ using namespace Arithmetic;+ return scale<T>(pow(scale<qreal>(dst), scale<qreal>(src)));+}++template<class T>+inline T cfGammaIllumination(T src, T dst) {+ using namespace Arithmetic;+ return inv(cfGammaDark(inv(src),inv(dst)));+}++template<class T>+inline T cfGeometricMean(T src, T dst) {+ using namespace Arithmetic;+ return scale<T>(sqrt(scale<qreal>(dst) * scale<qreal>(src)));+}++template<class T>+inline T cfOver(T src, T dst) { Q_UNUSED(dst); return src; }++template<class T>+inline T cfOverlay(T src, T dst) { return cfHardLight(dst, src); }++template<class T>+inline T cfMultiply(T src, T dst) { return Arithmetic::mul(src, dst); }++template<class T>+inline T cfHardOverlay(T src, T dst) {+ using namespace Arithmetic;++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc == 1.0) {+ return scale<T>(1.0);}++ if(fsrc > 0.5) {+ return scale<T>(cfDivide(inv(2.0 * fsrc - 1.0), fdst));+ }+ return scale<T>(mul(2.0 * fsrc, fdst));+}++template<class T>+inline T cfDifference(T src, T dst) { return qMax(src,dst) - qMin(src,dst); }++template<class T>+inline T cfScreen(T src, T dst) { return Arithmetic::unionShapeOpacity(src, dst); }++template<class T>+inline T cfDarkenOnly(T src, T dst) { return qMin(src, dst); }++template<class T>+inline T cfLightenOnly(T src, T dst) { return qMax(src, dst); }++template<class T>+inline T cfGlow(T src, T dst) {+ using namespace Arithmetic;+ // see http://www.pegtop.net/delphi/articles/blendmodes/quadratic.htm for formulas of Quadratic Blending Modes like Glow, Reflect, Freeze, and Heat++ if (dst == unitValue<T>()) {+ return unitValue<T>();+ }++ return clamp<T>(div(mul(src, src), inv(dst)));+}++template<class T>+inline T cfReflect(T src, T dst) {+ using namespace Arithmetic;+++ return clamp<T>(cfGlow(dst,src));+}++template<class T>+inline T cfHeat(T src, T dst) {+ using namespace Arithmetic;++ if(src == unitValue<T>()) {+ return unitValue<T>();+ }++ if(dst == zeroValue<T>()) {+ return zeroValue<T>();+ }++ return inv(clamp<T>(div(mul(inv(src), inv(src)),dst)));+}++template<class T>+inline T cfFreeze(T src, T dst) {+ using namespace Arithmetic;++ return (cfHeat(dst,src));+}++template<class T>+inline T cfHelow(T src, T dst) {+ using namespace Arithmetic;+ // see http://www.pegtop.net/delphi/articles/blendmodes/quadratic.htm for formulas of Quadratic Blending Modes like Glow, Reflect, Freeze, and Heat++ if (cfHardMixPhotoshop(src,dst) == unitValue<T>()) {+ return cfHeat(src,dst);+ }++ if (src == zeroValue<T>()) {+ return zeroValue<T>();+ }++ return (cfGlow(src,dst));+}++template<class T>+inline T cfFrect(T src, T dst) {+ using namespace Arithmetic;++ if (cfHardMixPhotoshop(src,dst) == unitValue<T>()) {+ return cfFreeze(src,dst);+ }++ if (dst == zeroValue<T>()) {+ return zeroValue<T>();+ }++ return (cfReflect(src,dst));+}++template<class T>+inline T cfGleat(T src, T dst) {+ using namespace Arithmetic;+ // see http://www.pegtop.net/delphi/articles/blendmodes/quadratic.htm for formulas of Quadratic Blending Modes like Glow, Reflect, Freeze, and Heat++ if(dst == unitValue<T>()) {+ return unitValue<T>();+ }++ if(cfHardMixPhotoshop(src,dst) == unitValue<T>()) {+ return cfGlow(src,dst);+ }++ return (cfHeat(src,dst));+}++template<class T>+inline T cfReeze(T src, T dst) {+ using namespace Arithmetic;++ return (cfGleat(dst,src));+}+template<class T>+inline T cfFhyrd(T src, T dst) {+ using namespace Arithmetic;++ return (cfAllanon(cfFrect(src,dst),cfHelow(src,dst)));+}++template<class T>+inline T cfInterpolation(T src, T dst) {+ using namespace Arithmetic;++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if(dst == zeroValue<T>() && src == zeroValue<T>()) {+ return zeroValue<T>();+ }++ return scale<T>(.5f-.25f*cos(pi*(fsrc))-.25f*cos(pi*(fdst)));+}++template<class T>+inline T cfInterpolationB(T src, T dst) {+ using namespace Arithmetic;++ return cfInterpolation(cfInterpolation(src,dst),cfInterpolation(src,dst));+}+++template<class T>+inline T cfPenumbraB(T src, T dst) {+ using namespace Arithmetic;++ if (dst == unitValue<T>()) {+ return unitValue<T>();+ }+ if (dst + src < unitValue<T>()) {+ return (cfColorDodge(dst,src)/2);+ }+ if (src == zeroValue<T>()) {+ return zeroValue<T>();+ }++ return inv(clamp<T>(div(inv(dst),src)/2));+}++template<class T>+inline T cfPenumbraD(T src, T dst) {+ using namespace Arithmetic;++ if (dst == unitValue<T>()) {+ return unitValue<T>();+ }++ return cfArcTangent(src,inv(dst));+}++template<class T>+inline T cfPenumbraC(T src, T dst) {+ using namespace Arithmetic;++ return cfPenumbraD(dst,src);+}++template<class T>+inline T cfPenumbraA(T src, T dst) {+ using namespace Arithmetic;++ return (cfPenumbraB(dst,src));+}++template<class T>+inline T cfSoftLightIFSIllusions(T src, T dst) {+ using namespace Arithmetic;++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ return scale<T>(pow(fdst,pow(2.0,(mul(2.0,.5f-fsrc)))));+}++template<class T>+inline T cfSoftLightPegtopDelphi(T src, T dst) {+ using namespace Arithmetic;++ return clamp<T>(cfAddition(mul(dst,cfScreen(src,dst)),mul(mul(src,dst),inv(dst))));+}++template<class T>+inline T cfNegation(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;++ composite_type unit = unitValue<T>();+ composite_type a = unit - src - dst;+ composite_type s = std::abs(a);+ composite_type d = unit - s;++ return T(d);+}++template<class T>+inline T cfNor(T src, T dst) {+ using namespace Arithmetic;++ return and(src,dst);+}++template<class T>+inline T cfNand(T src, T dst) {+ using namespace Arithmetic;++ return or(src,dst);+}++template<class T>+inline T cfXor(T src, T dst) {+ using namespace Arithmetic;++ return xor(src,dst);+}++template<class T>+inline T cfXnor(T src, T dst) {+ using namespace Arithmetic;++ return cfXor(src,inv(dst));+}++template<class T>+inline T cfAnd(T src, T dst) {+ using namespace Arithmetic;++ return cfNor(inv(src),inv(dst));+}++template<class T>+inline T cfOr(T src, T dst) {+ using namespace Arithmetic;++ return cfNand(inv(src),inv(dst));+}++template<class T>+inline T cfConverse(T src, T dst) {+ using namespace Arithmetic;++ return cfOr(inv(src),dst);+}++template<class T>+inline T cfNotConverse(T src, T dst) {+ using namespace Arithmetic;++ return cfAnd(src,inv(dst));+}++template<class T>+inline T cfImplies(T src, T dst) {+ using namespace Arithmetic;++ return cfOr(src,inv(dst));+}++template<class T>+inline T cfNotImplies(T src, T dst) {+ using namespace Arithmetic;++ return cfAnd(inv(src),dst);+}++template<class T>+inline T cfPNormA(T src, T dst) {+ using namespace Arithmetic;+ //This is also known as P-Norm mode with factor of 2.3333 See IMBLEND image blending mode samples, and please see imblend.m file found on Additional Blending Mode thread at Phabricator. 1/2.3333 is .42875...++ return clamp<T>(pow(pow((float)dst, 2.3333333333333333) + pow((float)src, 2.3333333333333333), 0.428571428571434));+}++template<class T>+inline T cfPNormB(T src, T dst) {+ using namespace Arithmetic;+ //This is also known as P-Norm mode with factor of 2.3333 See IMBLEND image blending mode samples, and please see imblend.m file found on Additional Blending Mode thread at Phabricator. 1/2.3333 is .42875...++ return clamp<T>(pow(pow(dst,4)+pow(src,4),0.25));+}++template<class T>+inline T cfSuperLight(T src, T dst) {+ using namespace Arithmetic;+ //4.0 can be adjusted to taste. 4.0 is picked for being the best in terms of contrast and details. See imblend.m file.++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc < .5) {+ return scale<T>(inv(pow(pow(inv(fdst),2.875)+pow(inv(2.0*fsrc),2.875),1.0/2.875)));+ }++ return scale<T>(pow(pow(fdst,2.875)+pow(2.0*fsrc-1.0,2.875),1.0/2.875));+}++template<class T>+inline T cfTintIFSIllusions(T src, T dst) {+ using namespace Arithmetic;+ //Known as Light Blending mode found in IFS Illusions. Picked this name because it results into a very strong tint, and has better naming convention.++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ return scale<T>(fsrc*inv(fdst)+sqrt(fdst));+}++template<class T>+inline T cfShadeIFSIllusions(T src, T dst) {+ using namespace Arithmetic;+ //Known as Shadow Blending mode found in IFS Illusions. Picked this name because it is the opposite of Tint (IFS Illusion Blending mode).++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ return scale<T>(inv((inv(fdst)*fsrc)+sqrt(inv(fsrc))));+}++template<class T>+inline T cfFogLightenIFSIllusions(T src, T dst) {+ using namespace Arithmetic;+ //Known as Bright Blending mode found in IFS Illusions. Picked this name because the shading reminds me of fog when overlaying with a gradient.++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc < .5) {+ return scale<T>(inv(inv(fsrc)*fsrc)-inv(fdst)*inv(fsrc));+ }++ return scale<T>(fsrc-inv(fdst)*inv(fsrc)+pow(inv(fsrc),2));+}++template<class T>+inline T cfFogDarkenIFSIllusions(T src, T dst) {+ using namespace Arithmetic;+ //Known as Dark Blending mode found in IFS Illusions. Picked this name because the shading reminds me of fog when overlaying with a gradient.++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc < .5) {+ return scale<T>(inv(fsrc)*fsrc+fsrc*fdst);+ }++ return scale<T>(fsrc*fdst+fsrc-pow(fsrc,2));+}++template<class T>+inline T cfModulo(T src, T dst) {+ using namespace Arithmetic;++ return mod(dst,src);+}++template<class T>+inline T cfModuloShift(T src, T dst) {+ using namespace Arithmetic;+ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc == 1.0 && fdst == 0.0) {+ return scale<T>(0.0);+ }+++ return scale<T>(mod((fdst+fsrc),1.0000000000));+}++template<class T>+inline T cfModuloShiftContinuous(T src, T dst) {+ using namespace Arithmetic;+ //This blending mode do not behave like difference/equivalent with destination layer inverted if you use group layer on addition while the content of group layer contains several addition-mode layers, it works as expected on float images. So, no need to change this.+ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc == 1.0 && fdst == 0.0) {+ return scale<T>(1.0);+ }++ return scale<T>((int(ceil(fdst+fsrc)) % 2 != 0) || (fdst == zeroValue<T>()) ? cfModuloShift(fsrc,fdst) : inv(cfModuloShift(fsrc,fdst)));+}++template<class T>+inline T cfDivisiveModulo(T src, T dst) {+ using namespace Arithmetic;+ //I have to use 1.00000 as unitValue failed to work for those area.++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc == zeroValue<T>()) {+ return scale<T>(mod(((1.0000000000/epsilon<T>()) * fdst),1.0000000000));+ }++ return scale<T>(mod(((1.0000000000/fsrc) * fdst),1.0000000000));+}++template<class T>+inline T cfDivisiveModuloContinuous(T src, T dst) {+ using namespace Arithmetic;++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fdst == zeroValue<T>()) {+ return zeroValue<T>();+ }++ if (fsrc == zeroValue<T>()) {+ return cfDivisiveModulo(fsrc,fdst);+ }+++ return scale<T>( int(ceil(fdst/fsrc)) % 2 != 0 ? cfDivisiveModulo(fsrc,fdst) : inv(cfDivisiveModulo(fsrc,fdst)));+}++template<class T>+inline T cfModuloContinuous(T src, T dst) {+ using namespace Arithmetic;++ return cfMultiply(cfDivisiveModuloContinuous(src,dst),src);+}++template<class T>+inline T cfEasyDodge(T src, T dst) {+ using namespace Arithmetic;+ // The 13 divided by 15 can be adjusted to taste. See imgblend.m++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if (fsrc == 1.0) {+ return scale<T>(1.0);}+++ return scale<T>(pow(fdst,mul(inv(fsrc != 1.0 ? fsrc : .999999999999),1.039999999)));+}++template<class T>+inline T cfEasyBurn(T src, T dst) {+ using namespace Arithmetic;+ // The 13 divided by 15 can be adjusted to taste. See imgblend.m++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);+++ return scale<T>(inv(pow(inv(fsrc != 1.0 ? fsrc : .999999999999),mul(fdst,1.039999999))));+}++template<class T>+inline T cfFlatLight(T src, T dst) {+ using namespace Arithmetic;++ if (src == zeroValue<T>()) {+ return zeroValue<T>();+ }++ return clamp<T>(cfHardMixPhotoshop(inv(src),dst)==unitValue<T>() ? cfPenumbraB(src,dst) : cfPenumbraA(src,dst));+}+++template<class HSXType, class TReal>+inline void cfAdditionSAI(TReal src, TReal sa, TReal& dst, TReal& da)+{+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<TReal>::compositetype composite_type;++ Q_UNUSED(da);+ composite_type newsrc;+ newsrc = mul(src, sa);+ dst = clamp<TReal>(newsrc + dst);+}++++#endif // KOCOMPOSITEOP_FUNCTIONS_H_diff --git a/libs/pigment/tests/KoCompositeOpGeneric2.h b/libs/pigment/tests/KoCompositeOpGeneric2.hnew file mode 100644index 0000000000..29cb4fdc1c--- /dev/null+++ b/libs/pigment/tests/KoCompositeOpGeneric2.h@@ -0,0 +1,256 @@+/*+ * SPDX-FileCopyrightText: 2011 Silvio Heinrich <[email protected]>+ *+ * SPDX-License-Identifier: LGPL-2.1-or-later+*/++#ifdef _KOCOMPOSITEOP_GENERIC_H_+#error "ssksjdkjs"+#endif+++#ifndef _KOCOMPOSITEOP_GENERIC_H_+#define _KOCOMPOSITEOP_GENERIC_H_++#include "KoCompositeOpBase.h"++/**+ * Generic CompositeOp for separable channel compositing functions+ *+ * A template to generate a KoCompositeOp class by just specifying a+ * blending/compositing function. This template works with compositing functions+ * for separable channels (means each channel of a pixel can be processed separately)+ */+template<+ class Traits,+ typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type),+ typename BlendingPolicy+>+class KoCompositeOpGenericSC: public KoCompositeOpBase< Traits, KoCompositeOpGenericSC<Traits,compositeFunc,BlendingPolicy> >+{+ typedef KoCompositeOpBase< Traits, KoCompositeOpGenericSC<Traits,compositeFunc,BlendingPolicy> > base_class;+ typedef typename Traits::channels_type channels_type;++ static const qint32 channels_nb = Traits::channels_nb;+ static const qint32 alpha_pos = Traits::alpha_pos;++public:+ KoCompositeOpGenericSC(const KoColorSpace* cs, const QString& id, const QString& category)+ : base_class(cs, id, category) { }++public:+ template<bool alphaLocked, bool allChannelFlags>+ inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,+ channels_type* dst, channels_type dstAlpha, channels_type maskAlpha,+ channels_type opacity, const QBitArray& channelFlags) {+ using namespace Arithmetic;++ srcAlpha = mul(srcAlpha, maskAlpha, opacity);++ if(alphaLocked) {+ if(dstAlpha != zeroValue<channels_type>()) {+ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ const channels_type srcInBlendSpace = BlendingPolicy::toAdditiveSpace(src[i]);+ const channels_type dstInBlendSpace = BlendingPolicy::toAdditiveSpace(dst[i]);++ dst[i] = BlendingPolicy::fromAdditiveSpace(+ lerp(dstInBlendSpace,+ compositeFunc(srcInBlendSpace, dstInBlendSpace),+ srcAlpha));+ }+ }+ }++ return dstAlpha;+ }+ else {+ channels_type newDstAlpha = unionShapeOpacity(srcAlpha, dstAlpha);++ if(newDstAlpha != zeroValue<channels_type>()) {++ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ const channels_type srcInBlendSpace = BlendingPolicy::toAdditiveSpace(src[i]);+ const channels_type dstInBlendSpace = BlendingPolicy::toAdditiveSpace(dst[i]);++ channels_type result =+ blend(srcInBlendSpace, srcAlpha,+ dstInBlendSpace, dstAlpha,+ compositeFunc(srcInBlendSpace, dstInBlendSpace));++++ dst[i] = BlendingPolicy::fromAdditiveSpace(div(result, newDstAlpha));++// qDebug() << i << ppVar(result)+// << ppVar(srcInBlendSpace)+// << ppVar(dstInBlendSpace)+// << ppVar(compositeFunc(srcInBlendSpace, dstInBlendSpace)) << div(result, newDstAlpha);+ }+ }+ }++ return newDstAlpha;+ }+ }+};+++/**+ * Generic CompositeOp for nonseparable/HSL channel compositing functions+ *+ * A template to generate a KoCompositeOp class by just specifying a+ * 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> >+{+ typedef KoCompositeOpBase< Traits, KoCompositeOpGenericHSL<Traits,compositeFunc> > 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)+ : base_class(cs, id, category) { }++public:+ template<bool alphaLocked, bool allChannelFlags>+ inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,+ channels_type* dst, channels_type dstAlpha, channels_type maskAlpha,+ channels_type opacity, const QBitArray& channelFlags) {+ using namespace Arithmetic;++ srcAlpha = mul(srcAlpha, maskAlpha, opacity);++ 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 dstR = scale<float>(dst[red_pos]);+ float dstG = scale<float>(dst[green_pos]);+ float dstB = scale<float>(dst[blue_pos]);++ compositeFunc(srcR, srcG, srcB, dstR, dstG, dstB);++ if(allChannelFlags || channelFlags.testBit(red_pos))+ dst[red_pos] = lerp(dst[red_pos], scale<channels_type>(dstR), srcAlpha);++ if(allChannelFlags || channelFlags.testBit(green_pos))+ dst[green_pos] = lerp(dst[green_pos], scale<channels_type>(dstG), srcAlpha);++ if(allChannelFlags || channelFlags.testBit(blue_pos))+ dst[blue_pos] = lerp(dst[blue_pos], scale<channels_type>(dstB), srcAlpha);+ }++ return dstAlpha;+ }+ else {+ 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 dstR = scale<float>(dst[red_pos]);+ float dstG = scale<float>(dst[green_pos]);+ float dstB = scale<float>(dst[blue_pos]);++ compositeFunc(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);++ if(allChannelFlags || channelFlags.testBit(green_pos))+ dst[green_pos] = div(blend(src[green_pos], srcAlpha, dst[green_pos], dstAlpha, scale<channels_type>(dstG)), newDstAlpha);++ if(allChannelFlags || channelFlags.testBit(blue_pos))+ dst[blue_pos] = div(blend(src[blue_pos], srcAlpha, dst[blue_pos], dstAlpha, scale<channels_type>(dstB)), newDstAlpha);+ }++ return newDstAlpha;+ }+ }+};++++/**+ * Generic CompositeOp for separable channel + alpha compositing functions+ *+ * A template to generate a KoCompositeOp class by just specifying a+ * blending/compositing function. This template works with compositing functions+ * for separable channels (means each channel of a pixel can be processed separately)+ * with taking alpha into consideration.+ * Note that because of special treating of alpha, any composite op function+ * needs to make alpha blending itself - the value of color that is written onto the projection+ * is the same that the composite function gives (compare with KoCompositeOpGenericHSL and KoCompositeOpGenericSC).+ */+template<class Traits, void compositeFunc(float, float, float&, float&), typename BlendingPolicy>+class KoCompositeOpGenericSCAlpha: public KoCompositeOpBase< Traits, KoCompositeOpGenericSCAlpha<Traits,compositeFunc,BlendingPolicy> >+{+ typedef KoCompositeOpBase< Traits, KoCompositeOpGenericSCAlpha<Traits,compositeFunc,BlendingPolicy> > base_class;+ typedef typename Traits::channels_type channels_type;++ static const qint32 channels_nb = Traits::channels_nb;+ static const qint32 alpha_pos = Traits::alpha_pos;++public:+ KoCompositeOpGenericSCAlpha(const KoColorSpace* cs, const QString& id, const QString& category)+ : base_class(cs, id, category) { }++public:+ template<bool alphaLocked, bool allChannelFlags>+ inline static channels_type composeColorChannels(const channels_type* src, channels_type srcAlpha,+ channels_type* dst, channels_type dstAlpha, channels_type maskAlpha,+ channels_type opacity, const QBitArray& channelFlags)+ {+ using namespace Arithmetic;++ srcAlpha = mul(srcAlpha, maskAlpha, opacity);++ if(alphaLocked) {+ channels_type oldAlpha = dstAlpha;+ if(dstAlpha != zeroValue<channels_type>()) {+ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ float dstValueFloat = scale<float>(BlendingPolicy::toAdditiveSpace(dst[i]));+ float dstAlphaFloat = scale<float>(oldAlpha);+ compositeFunc(scale<float>(BlendingPolicy::toAdditiveSpace(src[i])), scale<float>(srcAlpha), dstValueFloat, dstAlphaFloat);+ dst[i] = BlendingPolicy::fromAdditiveSpace(scale<channels_type>(dstValueFloat));+ }+ }+ }++ return dstAlpha;+ }+ else {+ channels_type oldAlpha = dstAlpha;+ channels_type newDstAlpha = unionShapeOpacity(srcAlpha, dstAlpha);++ if(newDstAlpha != zeroValue<channels_type>()) {+ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ float dstFloat = scale<float>(BlendingPolicy::toAdditiveSpace(dst[i]));+ float dstAlphaFloat = scale<float>(oldAlpha);+ compositeFunc(scale<float>(BlendingPolicy::toAdditiveSpace(src[i])), scale<float>(srcAlpha), dstFloat, dstAlphaFloat);+ dst[i] = BlendingPolicy::fromAdditiveSpace(scale<channels_type>(dstFloat));+ }+ }+ }++ return newDstAlpha;+ }+ }+};++++#endif // _KOCOMPOSITEOP_GENERIC_H_diff --git a/libs/pigment/tests/TestCompositeOpInversion.cpp b/libs/pigment/tests/TestCompositeOpInversion.cppindex b6d7fbee15..aa1d3b1eca 100644--- a/libs/pigment/tests/TestCompositeOpInversion.cpp+++ b/libs/pigment/tests/TestCompositeOpInversion.cpp@@ -208,4 +208,434 @@ void TestCompositeOpInversion::test_data()}}+#include <KoCompositeOpGeneric2.h>+#include <KoCompositeOpFunctions2.h>+#include "compositeops/KoColorSpaceBlendingPolicy.h"++#include <KoColorModelStandardIds.h>+void TestCompositeOpInversion::testBurnInF32Mode()+{+ const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);+ const KoCompositeOp *op = cs->compositeOp(COMPOSITE_BURN);++ const qreal opacity = 0.25;+ KoColor srcColor(QColor(10,0,20,255), cs);+ KoColor dstColor(QColor(0,1,2,10), cs);++ op->composite(dstColor.data(), 0, srcColor.data(), 0,+ 0, 0,+ 1, 1,+ opacity);++ ENTER_FUNCTION() << ppVar(srcColor) << ppVar(dstColor);++}++namespace {+struct Wrapper {+ KoColor color;+ int index = 0;+};++QDebug operator<<(QDebug debug, const Wrapper &w) {+ const KoColor &c = w.color;++ if (c.colorSpace()->colorDepthId() == Float32BitsColorDepthID) {+ const float *ptr = reinterpret_cast<const float*>(c.data());+ debug.nospace() << "(" << ptr[w.index] << ", " << ptr[3] << ")";+ } else if (c.colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {+ using namespace Arithmetic;+ const quint16 *ptr = reinterpret_cast<const quint16*>(c.data());+ debug.nospace() << "(" << qreal(ptr[2 - w.index]) / unitValue<quint16>() << ", " << qreal(ptr[3]) / unitValue<quint16>() << ")";+ }++ return debug.space();+}++Wrapper dumpPixel(const KoColor &color) {+ return {color, 0};+}++float getColorValue(const KoColor &c) {+ float result = 777.0;++ if (c.colorSpace()->colorDepthId() == Float32BitsColorDepthID) {+ const float *ptr = reinterpret_cast<const float*>(c.data());+ result = ptr[0];+ } else if (c.colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {+ using namespace Arithmetic;+ const quint16 *ptr = reinterpret_cast<const quint16*>(c.data());+ result = qreal(ptr[2]) / unitValue<quint16>();+ }++ return result;+}++quint16 getColorValueU(const KoColor &c) {+ KIS_ASSERT(c.colorSpace()->colorDepthId() == Integer16BitsColorDepthID);++ using namespace Arithmetic;+ const quint16 *ptr = reinterpret_cast<const quint16*>(c.data());+ return ptr[2];+}+++KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isHDR)+{+ KoCompositeOp *op = nullptr;++ if (id == COMPOSITE_DODGE) {+ if (cs->colorDepthId() == Float32BitsColorDepthID) {+ using Traits = KoRgbF32Traits;+ if (isHDR) {+ constexpr auto func = &cfColorDodge<float, ClampPolicyFloatHDR>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryLight());+ } else {+ constexpr auto func = &cfColorDodge<float, ClampPolicyFloatSDR>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryLight());+ }+ } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {+ using Traits = KoRgbU16Traits;+ constexpr auto func = &cfColorDodge<quint16, ClampPolicyInteger>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryLight());+ }+ } else if (id == COMPOSITE_BURN) {+ if (cs->colorDepthId() == Float32BitsColorDepthID) {+ using Traits = KoRgbF32Traits;+ if (isHDR) {+ constexpr auto func = &cfColorBurn<float, ClampPolicyFloatHDR>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ } else {+ constexpr auto func = &cfColorBurn<float, ClampPolicyFloatSDR>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ }+ } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {+ using Traits = KoRgbU16Traits;+ constexpr auto func = &cfColorBurn<quint16, ClampPolicyInteger>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ }+ } else if (id == COMPOSITE_LINEAR_BURN) {+ if (cs->colorDepthId() == Float32BitsColorDepthID) {+ using Traits = KoRgbF32Traits;+ if (isHDR) {+ constexpr auto func = &cfLinearBurn<float, ClampPolicyFloatHDR>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ } else {+ constexpr auto func = &cfLinearBurn<float, ClampPolicyFloatSDR>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ }+ } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {+ using Traits = KoRgbU16Traits;+ constexpr auto func = &cfLinearBurn<quint16, ClampPolicyInteger>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ }+ } else if (id == COMPOSITE_ADD) {+ if (cs->colorDepthId() == Float32BitsColorDepthID) {+ using Traits = KoRgbF32Traits;+ constexpr auto func = &cfAddition<float>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {+ using Traits = KoRgbU16Traits;+ constexpr auto func = &cfLinearBurn<quint16, ClampPolicyInteger>;+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());+ }+ }++ KIS_ASSERT(op);++ return op;+}+++}++void TestCompositeOpInversion::testFloatModes()+{+ QFETCH(QString, id);+ QFETCH(bool, isHDR);++ const KoColorSpace* csU = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Integer16BitsColorDepthID.id(), 0);+ const KoCompositeOp *opU = createOp(csU, id, isHDR);+ const KoCompositeOp *opU2 = csU->compositeOp(id);++ const KoColorSpace* csF = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);+ const KoCompositeOp *opF = createOp(csF, id, isHDR);++ auto createColorU = [&] (qreal colorF, qreal alphaF) {+ using namespace Arithmetic;+ const quint16 color = qRound(qBound(0.0, colorF, 1.0) * unitValue<quint16>());+ const quint16 alpha = qRound(qBound(0.0, alphaF, 1.0) * unitValue<quint16>());++ KoColor c(csU);+ quint16 *ptr = reinterpret_cast<quint16*>(c.data());+ ptr[2] = color;+ ptr[3] = alpha;+ return c;+ };++ auto createColorF = [&] (qreal color, qreal alpha) {+ KoColor c(csF);+ float *ptr = reinterpret_cast<float*>(c.data());+ ptr[0] = color;+ ptr[3] = alpha;+ return c;+ };++ using namespace boost::accumulators;+ accumulator_set<qreal, stats<tag::max, tag::mean> > error;++ //std::vector<qreal> opacityValues({0.0, 0.1, 0.2, 0.5, 0.8, 0.9, 1.0});+ std::vector<qreal> opacityValues({1.0});+ std::vector<qreal> alphaValues({1.0});+ std::vector<qreal> values({-0.1,+ 0 - std::numeric_limits<float>::epsilon(),+ 0,+ 0 + std::numeric_limits<float>::epsilon(),+ 0.1, 0.2, 0.5, 0.8, 0.9,+ 1.0 - std::numeric_limits<float>::epsilon(),+ 1.0,+ 1.0 + std::numeric_limits<float>::epsilon(),+ 1.1,+ 1.5});+ std::vector<qreal> valuesSrc = values;+ std::vector<qreal> valuesDst = values;++// std::vector<qreal> valuesSrc({0.0});+// std::vector<qreal> valuesDst({-0.1});++ Q_FOREACH (qreal opacity, opacityValues) {+ Q_FOREACH (qreal srcAlphaValue, alphaValues) {+ Q_FOREACH (qreal dstAlphaValue, alphaValues) {+ Q_FOREACH (qreal srcColorValue, valuesSrc) {+ Q_FOREACH (qreal dstColorValue, valuesDst) {++// {+// {+// {+// {+// {+// qreal srcColorValue = 1.0 - std::numeric_limits<float>::epsilon();+// qreal dstColorValue = 0.2;++// qreal opacity = 0.5;+// qreal srcAlphaValue = 0.5;+// qreal dstAlphaValue = 0.5;++ KoColor srcColorF = createColorF(srcColorValue,srcAlphaValue);+ KoColor dstColorF = createColorF(dstColorValue,dstAlphaValue);+ KoColor resultColorF = dstColorF;++ opF->composite(resultColorF.data(), 0, srcColorF.data(), 0,+ 0, 0,+ 1, 1,+ opacity);++ KoColor srcColorU = createColorU(srcColorValue,srcAlphaValue);+ KoColor dstColorU = createColorU(dstColorValue,dstAlphaValue);+ KoColor resultColorU = dstColorU;++ opU->composite(resultColorU.data(), 0, srcColorU.data(), 0,+ 0, 0,+ 1, 1,+ opacity);++ float resultColorValueU = getColorValue(resultColorU);+ float resultColorValueF = getColorValue(resultColorF);+++ if (!isHDR) {+ KoColor resultColorU2 = dstColorU;++ opU2->composite(resultColorU2.data(), 0, srcColorU.data(), 0,+ 0, 0,+ 1, 1,+ opacity);++ const quint16 referenceColor = getColorValueU(resultColorU2);+ const quint16 resultColor = getColorValueU(resultColorU);++ if (resultColor != referenceColor) {+ qDebug() << "--- integer implementation is inconsistent to the original mode! ---";+ qDebug() << "U16 result: " << fixed << qSetRealNumberPrecision(8)+ << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);+ qDebug() << "U16 reference:" << fixed << qSetRealNumberPrecision(8)+ << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU2);+ QFAIL("integer implementation is inconsistent to the original mode!");+ }+ }++ if (isHDR) {+ // just verify sanity of the result++ if (dstColorValue >= 0.0 && resultColorValueF < 0.0) {++ qDebug() << "--- resulting value is negative! ---";+ 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("result color value is negative!");+ }++ if (qFuzzyIsNull(resultColorValueU) &&+ dstColorValue > std::numeric_limits<float>::epsilon() &&+ dstColorValue < 1.0 - std::numeric_limits<float>::epsilon()) {++ if (!qFuzzyIsNull(resultColorValueF)) {++ qDebug() << "--- null point position is inconsistent! ---";+ 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("result null point position is inconsistent!");+ }+ }++ } else if (dstColorValue >= -std::numeric_limits<float>::epsilon() &&+ dstColorValue <= 1.0 + std::numeric_limits<float>::epsilon() &&+ qAbs(resultColorValueF - resultColorValueU) > 0.001) {+ // in non-HDR mode both blending modes should behave in+ // exactly the same way (including zero and unit values)++ qDebug() << "--- inconsistent result between int and float_sdr modes ---";+ 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 between int and float_sdr modes!");+ }++ }+ }+ }+ }+ }++// {+// using namespace Arithmetic;+// quint16 x = 52428;+// qDebug() << ppVar(x) << ppVar(inv(x)) << ppVar(unitValue<quint16>() - x);++// float y = 0.8;+// qDebug() << ppVar(y) << ppVar(inv(y)) << ppVar(unitValue<float>() - y);+// qDebug() << ppVar(div(y, inv(y)));+// qDebug() << ppVar(div(x, inv(x)));+// qDebug() << ppVar(clampToSDR<float>(div(y, inv(y))));+// qDebug() << ppVar(clampToSDR<quint16>(div(x, inv(x))));++// }+}++void TestCompositeOpInversion::testFloatModes_data()+{+ QStringList ids;+// ids << COMPOSITE_OVER;+// ids << COMPOSITE_ALPHA_DARKEN;+// ids << COMPOSITE_COPY;+// ids << COMPOSITE_ERASE;+// ids << COMPOSITE_BEHIND;+// ids << COMPOSITE_DESTINATION_IN;+// ids << COMPOSITE_DESTINATION_ATOP;+// ids << COMPOSITE_GREATER;++// ids << COMPOSITE_OVERLAY;+// ids << COMPOSITE_GRAIN_MERGE;+// ids << COMPOSITE_GRAIN_EXTRACT;+// ids << COMPOSITE_HARD_MIX;+// ids << COMPOSITE_HARD_MIX_PHOTOSHOP;+// ids << COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP;+// ids << COMPOSITE_GEOMETRIC_MEAN;+// ids << COMPOSITE_PARALLEL;+// ids << COMPOSITE_ALLANON;+// ids << COMPOSITE_HARD_OVERLAY;+// ids << COMPOSITE_INTERPOLATION;+// ids << COMPOSITE_INTERPOLATIONB;+// ids << COMPOSITE_PENUMBRAA;+// ids << COMPOSITE_PENUMBRAB;+// ids << COMPOSITE_PENUMBRAC;+// ids << COMPOSITE_PENUMBRAD;+// ids << COMPOSITE_SCREEN;+ ids << COMPOSITE_DODGE;+// ids << COMPOSITE_LINEAR_DODGE;+// ids << COMPOSITE_LIGHTEN;+// ids << COMPOSITE_HARD_LIGHT;+// ids << COMPOSITE_SOFT_LIGHT_IFS_ILLUSIONS;+// ids << COMPOSITE_SOFT_LIGHT_PEGTOP_DELPHI;+// ids << COMPOSITE_SOFT_LIGHT_SVG;+// ids << COMPOSITE_SOFT_LIGHT_PHOTOSHOP;+// ids << COMPOSITE_GAMMA_LIGHT;+// ids << COMPOSITE_GAMMA_ILLUMINATION;+// ids << COMPOSITE_VIVID_LIGHT;+// ids << COMPOSITE_FLAT_LIGHT;+// ids << COMPOSITE_PIN_LIGHT;+// ids << COMPOSITE_LINEAR_LIGHT;+// ids << COMPOSITE_PNORM_A;+// ids << COMPOSITE_PNORM_B;+// ids << COMPOSITE_SUPER_LIGHT;+// ids << COMPOSITE_TINT_IFS_ILLUSIONS;+// ids << COMPOSITE_FOG_LIGHTEN_IFS_ILLUSIONS;+// ids << COMPOSITE_EASY_DODGE;+ ids << COMPOSITE_BURN;+ ids << COMPOSITE_LINEAR_BURN;+// ids << COMPOSITE_DARKEN;+// ids << COMPOSITE_GAMMA_DARK;+// ids << COMPOSITE_SHADE_IFS_ILLUSIONS;+// ids << COMPOSITE_FOG_DARKEN_IFS_ILLUSIONS;+// ids << COMPOSITE_EASY_BURN;+ ids << COMPOSITE_ADD;+// ids << COMPOSITE_SUBTRACT;+// ids << COMPOSITE_INVERSE_SUBTRACT;+// ids << COMPOSITE_MULT;+// ids << COMPOSITE_DIVIDE;+// ids << COMPOSITE_MOD;+// ids << COMPOSITE_MOD_CON;+// ids << COMPOSITE_DIVISIVE_MOD;+// ids << COMPOSITE_DIVISIVE_MOD_CON;+// ids << COMPOSITE_MODULO_SHIFT;+// ids << COMPOSITE_MODULO_SHIFT_CON;+// ids << COMPOSITE_ARC_TANGENT;+// ids << COMPOSITE_DIFF;+// ids << COMPOSITE_EXCLUSION;+// ids << COMPOSITE_EQUIVALENCE;+// ids << COMPOSITE_ADDITIVE_SUBTRACTIVE;+// ids << COMPOSITE_NEGATION;++// ids << COMPOSITE_XOR;+// ids << COMPOSITE_OR;+// ids << COMPOSITE_AND;+// ids << COMPOSITE_NAND;+// ids << COMPOSITE_NOR;+// ids << COMPOSITE_XNOR;+// ids << COMPOSITE_IMPLICATION;+// ids << COMPOSITE_NOT_IMPLICATION;+// ids << COMPOSITE_CONVERSE;+// ids << COMPOSITE_NOT_CONVERSE;++// ids << COMPOSITE_REFLECT;+// ids << COMPOSITE_GLOW;+// ids << COMPOSITE_FREEZE;+// ids << COMPOSITE_HEAT;+// ids << COMPOSITE_GLEAT;+// ids << COMPOSITE_HELOW;+// ids << COMPOSITE_REEZE;+// ids << COMPOSITE_FRECT;+// ids << COMPOSITE_FHYRD;++// ids << COMPOSITE_DISSOLVE;++// ids << COMPOSITE_LUMINOSITY_SAI;++ QTest::addColumn<QString>("id");+ QTest::addColumn<bool>("isHDR");++ std::vector<bool> isHDRValues({false, true});++ Q_FOREACH (const QString &id, ids) {+ Q_FOREACH (const bool isHDR, isHDRValues) {+ QTest::addRow("%s_%s", id.toLatin1().data(), isHDR ? "hdr" : "sdr") << id << isHDR;+ }+ }+}+SIMPLE_TEST_MAIN(TestCompositeOpInversion)diff --git a/libs/pigment/tests/TestCompositeOpInversion.h b/libs/pigment/tests/TestCompositeOpInversion.hindex 162212cbd9..9e4bfffd5c 100644--- a/libs/pigment/tests/TestCompositeOpInversion.h+++ b/libs/pigment/tests/TestCompositeOpInversion.h@@ -15,6 +15,11 @@ public:private Q_SLOTS:void test();void test_data();++ void testBurnInF32Mode();++ void testFloatModes();+ void testFloatModes_data();};#endif // TESTCOMPOSITEOPINVERSION_Hdiff --git a/libs/ui/opengl/KisOpenGLUpdateInfoBuilder.cpp b/libs/ui/opengl/KisOpenGLUpdateInfoBuilder.cppindex f7fc03f6f5..d48a6b4255 100644--- a/libs/ui/opengl/KisOpenGLUpdateInfoBuilder.cpp+++ b/libs/ui/opengl/KisOpenGLUpdateInfoBuilder.cpp@@ -79,8 +79,8 @@ KisOpenGLUpdateInfoSP KisOpenGLUpdateInfoBuilder::buildUpdateInfo(const QRect &rprojection->colorSpace(),m_d->conversionOptions.m_destinationColorSpace,proofingSpace,- m_d->conversionOptions.m_renderingIntent,m_d->proofingConfig->intent,+ m_d->conversionOptions.m_renderingIntent,m_d->proofingConfig->conversionFlags,m_d->proofingConfig->warningColor,m_d->proofingConfig->adaptationState));diff --git a/libs/ui/tool/strokes/KisMaskingBrushCompositeOpFactory.cpp b/libs/ui/tool/strokes/KisMaskingBrushCompositeOpFactory.cppindex 255b350db7..90bfb25bb3 100644--- a/libs/ui/tool/strokes/KisMaskingBrushCompositeOpFactory.cpp+++ b/libs/ui/tool/strokes/KisMaskingBrushCompositeOpFactory.cpp@@ -10,7 +10,7 @@#include "kis_assert.h"#include <KoCompositeOpRegistry.h>-#include <KoCompositeOpFunctions.h>+//#include <KoCompositeOpFunctions.h>#include "KisMaskingBrushCompositeOp.h"diff --git a/plugins/color/lcms2engine/IccColorSpaceEngine.cpp b/plugins/color/lcms2engine/IccColorSpaceEngine.cppindex 9d7fc15535..a2619f55ad 100644--- a/plugins/color/lcms2engine/IccColorSpaceEngine.cpp+++ b/plugins/color/lcms2engine/IccColorSpaceEngine.cpp@@ -99,6 +99,7 @@ public:alarm[0] = (cmsUInt16Number)gamutWarning[2]*256;alarm[1] = (cmsUInt16Number)gamutWarning[1]*256;alarm[2] = (cmsUInt16Number)gamutWarning[0]*256;+ alarm[3] = (cmsUInt16Number)65535;cmsSetAlarmCodes(alarm);cmsSetAdaptationState(adaptationState);