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++
Integrate HDR-capable blendmodes back to Krita
Dmitry Kazakov0fc34a883551
diff --git a/libs/pigment/KoCompositeOpRegistry.cpp b/libs/pigment/KoCompositeOpRegistry.cppindex f3e60adbba..ae45ae5cff 100644--- a/libs/pigment/KoCompositeOpRegistry.cpp+++ b/libs/pigment/KoCompositeOpRegistry.cpp@@ -69,12 +69,14 @@ KoCompositeOpRegistry::KoCompositeOpRegistry()m_map.insert(m_categories[2], KoID(COMPOSITE_EASY_BURN , i18nc("Blending mode - Easy Burn", "Easy Burn")));m_map.insert(m_categories[3], KoID(COMPOSITE_DODGE , i18nc("Blending mode - Color Dodge", "Color Dodge")));+ m_map.insert(m_categories[3], KoID(COMPOSITE_DODGE_HDR , i18nc("Blending mode - Color Dodge HDR", "Color Dodge HDR")));m_map.insert(m_categories[3], KoID(COMPOSITE_LINEAR_DODGE, i18nc("Blending mode - Linear Dodge", "Linear Dodge")));m_map.insert(m_categories[3], KoID(COMPOSITE_LIGHTEN , i18nc("Blending mode - Lighten", "Lighten")));m_map.insert(m_categories[3], KoID(COMPOSITE_LINEAR_LIGHT, i18nc("Blending mode - Linear Light", "Linear Light")));m_map.insert(m_categories[3], KoID(COMPOSITE_SCREEN , i18nc("Blending mode - Screen", "Screen")));m_map.insert(m_categories[3], KoID(COMPOSITE_PIN_LIGHT , i18nc("Blending mode - Pin Light", "Pin Light")));m_map.insert(m_categories[3], KoID(COMPOSITE_VIVID_LIGHT , i18nc("Blending mode - Vivid Light", "Vivid Light")));+ m_map.insert(m_categories[3], KoID(COMPOSITE_VIVID_LIGHT_HDR , i18nc("Blending mode - Vivid Light HDR", "Vivid Light HDR")));m_map.insert(m_categories[3], KoID(COMPOSITE_FLAT_LIGHT , i18nc("Blending mode - Flat Light", "Flat Light")));m_map.insert(m_categories[3], KoID(COMPOSITE_HARD_LIGHT , i18nc("Blending mode - Hard Light", "Hard Light")));m_map.insert(m_categories[3], KoID(COMPOSITE_SOFT_LIGHT_IFS_ILLUSIONS, i18nc("Blending mode - Soft Light (IFS Illusions)", "Soft Light (IFS Illusions)")));@@ -115,6 +117,7 @@ KoCompositeOpRegistry::KoCompositeOpRegistry()m_map.insert(m_categories[6], KoID(COMPOSITE_ERASE , i18nc("Blending mode - Erase", "Erase")));m_map.insert(m_categories[6], KoID(COMPOSITE_ALPHA_DARKEN , i18nc("Blending mode - Alpha Darken", "Alpha Darken")));m_map.insert(m_categories[6], KoID(COMPOSITE_HARD_MIX , i18nc("Blending mode - Hard Mix", "Hard Mix")));+ m_map.insert(m_categories[6], KoID(COMPOSITE_HARD_MIX_HDR , i18nc("Blending mode - Hard Mix HDR", "Hard Mix HDR")));m_map.insert(m_categories[6], KoID(COMPOSITE_HARD_MIX_PHOTOSHOP, i18nc("Blending mode - Hard Mix (Photoshop)", "Hard Mix (Photoshop)")));m_map.insert(m_categories[6], KoID(COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP, i18nc("Blending mode - Hard Mix Softer (Photoshop)", "Hard Mix Softer (Photoshop)")));m_map.insert(m_categories[6], KoID(COMPOSITE_GRAIN_MERGE , i18nc("Blending mode - Grain Merge", "Grain Merge")));@@ -125,6 +128,7 @@ KoCompositeOpRegistry::KoCompositeOpRegistry()m_map.insert(m_categories[6], KoID(COMPOSITE_DESTINATION_ATOP, i18nc("Blending mode - Destination Atop", "Destination Atop")));m_map.insert(m_categories[6], KoID(COMPOSITE_DESTINATION_IN , i18nc("Blending mode - Destination In", "Destination In")));m_map.insert(m_categories[6], KoID(COMPOSITE_HARD_OVERLAY , i18nc("Blending mode - Hard Overlay", "Hard Overlay")));+ m_map.insert(m_categories[6], KoID(COMPOSITE_HARD_OVERLAY_HDR, i18nc("Blending mode - Hard Overlay HDR", "Hard Overlay HDR")));m_map.insert(m_categories[6], KoID(COMPOSITE_INTERPOLATION , i18nc("Blending mode - Interpolation", "Interpolation")));m_map.insert(m_categories[6], KoID(COMPOSITE_INTERPOLATIONB , i18nc("Blending mode - Interpolation - 2X", "Interpolation - 2X")));m_map.insert(m_categories[6], KoID(COMPOSITE_PENUMBRAA , i18nc("Blending mode - Penumbra A", "Penumbra A")));diff --git a/libs/pigment/KoCompositeOpRegistry.h b/libs/pigment/KoCompositeOpRegistry.hindex 0af7fedfcd..a307bf347f 100644--- a/libs/pigment/KoCompositeOpRegistry.h+++ b/libs/pigment/KoCompositeOpRegistry.h@@ -66,12 +66,14 @@ const QString COMPOSITE_GRAIN_MERGE = "grain_merge";const QString COMPOSITE_GRAIN_EXTRACT = "grain_extract";const QString COMPOSITE_EXCLUSION = "exclusion";const QString COMPOSITE_HARD_MIX = "hard mix";+const QString COMPOSITE_HARD_MIX_HDR = "hard_mix_hdr";const QString COMPOSITE_HARD_MIX_PHOTOSHOP = "hard_mix_photoshop";const QString COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP = "hard_mix_softer_photoshop";const QString COMPOSITE_OVERLAY = "overlay";const QString COMPOSITE_BEHIND = "behind";const QString COMPOSITE_GREATER = "greater";const QString COMPOSITE_HARD_OVERLAY = "hard overlay";+const QString COMPOSITE_HARD_OVERLAY_HDR = "hard_overlay_hdr";const QString COMPOSITE_INTERPOLATION = "interpolation";const QString COMPOSITE_INTERPOLATIONB = "interpolation 2x";const QString COMPOSITE_PENUMBRAA = "penumbra a";@@ -89,6 +91,7 @@ const QString COMPOSITE_EASY_BURN = "easy burn";const QString COMPOSITE_LIGHTEN = "lighten";const QString COMPOSITE_DODGE = "dodge";+const QString COMPOSITE_DODGE_HDR = "dodge_hdr";const QString COMPOSITE_LINEAR_DODGE = "linear_dodge";const QString COMPOSITE_SCREEN = "screen";const QString COMPOSITE_HARD_LIGHT = "hard_light";@@ -99,6 +102,7 @@ const QString COMPOSITE_SOFT_LIGHT_SVG = "soft_light_svg";const QString COMPOSITE_GAMMA_LIGHT = "gamma_light";const QString COMPOSITE_GAMMA_ILLUMINATION = "gamma_illumination";const QString COMPOSITE_VIVID_LIGHT = "vivid_light";+const QString COMPOSITE_VIVID_LIGHT_HDR = "vivid_light_hdr";const QString COMPOSITE_FLAT_LIGHT = "flat_light";const QString COMPOSITE_LINEAR_LIGHT = "linear light";const QString COMPOSITE_PIN_LIGHT = "pin_light";diff --git a/libs/pigment/compositeops/KoCompositeOpClampPolicy.h b/libs/pigment/compositeops/KoCompositeOpClampPolicy.hindex 43e36f95d5..163720e3ae 100644--- a/libs/pigment/compositeops/KoCompositeOpClampPolicy.h+++ b/libs/pigment/compositeops/KoCompositeOpClampPolicy.h@@ -58,7 +58,7 @@ struct ClampAsFloatSDR {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;+ return std::isfinite(value) ? value : compositetype(KoColorSpaceMathsTraits<T>::unitValue);}};@@ -84,9 +84,21 @@ struct ClampAsFloatHDR {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;+ return std::isfinite(value) ? value : compositetype(KoColorSpaceMathsTraits<T>::max);}};+++template <template <typename U,+ template <typename V> typename Policy> typename Functor,+ typename T>+struct FunctorWithSDRClampPolicy :+ std::conditional_t<std::numeric_limits<T>::is_integer,+ Functor<T, ClampAsInteger>,+ Functor<T, ClampAsFloatSDR>>+{+};+}#endif // KOCOMPOSITEOPCLAMPPOLICY_Hdiff --git a/libs/pigment/compositeops/KoCompositeOpFunctions.h b/libs/pigment/compositeops/KoCompositeOpFunctions.hindex 2245901118..dd5c910c58 100644--- a/libs/pigment/compositeops/KoCompositeOpFunctions.h+++ b/libs/pigment/compositeops/KoCompositeOpFunctions.h@@ -8,6 +8,8 @@#define KOCOMPOSITEOP_FUNCTIONS_H_#include <KoColorSpaceMaths.h>+#include <KoCompositeOpGenericFunctorBase.h>+#include <KoCompositeOpClampPolicy.h>#include <type_traits>#include <cmath>@@ -207,79 +209,71 @@ inline void cfLighterColor(TReal sr, TReal sg, TReal sb, TReal& dr, TReal& dg, T}}-template<class T>-inline T colorBurnHelper(T src, T dst) {- using namespace Arithmetic;- // Handle the case where the denominator is 0. See color dodge for a- // detailed explanation- if(src == zeroValue<T>()) {- return dst == unitValue<T>() ? inv(dst) : unitValue<T>();+template<class T,+ template <typename> typename ClampPolicy>+struct CFColorBurn : KoClampedSourceCompositeOpGenericFunctorBase<T>+{+ using clamp_policy = ClampPolicy<T>;++ static T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ // Handle the case where the denominator is 0. See color dodge for a+ // detailed explanation+ if (isZeroValue(src)) {+ return !isUnitValueClamped(dst) ? zeroValue<T>() : clamp_policy::clampResultAllowNegative(dst);+ }+ return inv<T>(+ clamp_policy::clampInvertedResult(+ clamp_policy::fixInfiniteAfterDivision(+ div(inv(dst), src)+ )+ )+ );}+};- return clampToSDR<T>(div(inv(dst), src));-}-// Integer version of color burn-template<class T>-inline typename std::enable_if<std::numeric_limits<T>::is_integer, T>::type-cfColorBurn(T src, T dst) {- using namespace Arithmetic;- return inv(colorBurnHelper(src, dst));-}--// Floating point version of color burn-template<class T>-inline typename std::enable_if<!std::numeric_limits<T>::is_integer, T>::type-cfColorBurn(T src, T dst) {- using namespace Arithmetic;- 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>::unitValue);-}--template<class T>-inline T cfLinearBurn(T src, T dst) {- using namespace Arithmetic;- typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;- return clampToSDR<T>(composite_type(src) + dst - unitValue<T>());-}+template<class T,+ template <typename> typename ClampPolicy>+struct CFLinearBurn : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;+ using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;-template<class T>-inline T colorDodgeHelper(T src, T dst) {- using namespace Arithmetic;- // 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 KoColorSpaceMaths<T>::isZeroValue(dst) ? zeroValue<T>() : KoColorSpaceMathsTraits<T>::unitValue;+ return clamp_policy::clampResult(composite_type(src) + dst - unitValue<T>());}- return Arithmetic::clampToSDR<T>(div(dst, inv(src)));-}--// Integer version of color dodge-template<class T>-inline typename std::enable_if<std::numeric_limits<T>::is_integer, T>::type-cfColorDodge(T src, T dst) {- return colorDodgeHelper(src, dst);-}--// Floating point version of color dodge-template<class T>-inline typename std::enable_if<!std::numeric_limits<T>::is_integer, T>::type-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>::unitValue;-}+};++template<typename T,+ template <typename> typename ClampPolicy>+struct CFColorDodge : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;++ // 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 isZeroValueClamped(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) {@@ -295,122 +289,175 @@ inline T cfSubtract(T src, T dst) {}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));-}+struct CFInverseSubtract : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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));-}+struct CFExclusion : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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>();+ if (isZeroValue(src))+ return isZeroValue(dst) ? 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>();+struct CFHardLight : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;++ if (isHalfValue(src)) {+ return dst;+ }++ composite_type src2 = composite_type(src) + src;- // src2 is guaranteed to be smaller than unitValue<T>() now- return Arithmetic::unionShapeOpacity(T(src2), dst);+ 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);}-- // 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;+struct CFSoftLightSvg : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;- qreal fsrc = scale<qreal>(src);- qreal fdst = scale<qreal>(dst);+ // TODO: check if dst-clamping should happen at higher level- 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));- }+ /**+ * soft-light scales the color using sqrt and pow2+ * functions, hence we cannot support HDR values+ */+ dst = clampChannelToSDR<T>(dst);- return scale<T>(fdst - (1.0 - 2.0 * fsrc) * fdst * (1.0 - fdst));-}+ 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));+ }-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));}-- 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>();+struct CFSoftLight : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ // TODO: check if dst-clamping should happen at higher level- // min(1,max(0,1-(1-dst) / (2*src)))+ /**+ * soft-light scales the color using sqrt and pow2+ * functions, hence we cannot support HDR values+ */+ dst = clampChannelToSDR<T>(dst);++ qreal fsrc = scale<qreal>(src);+ qreal fdst = scale<qreal>(dst);++ if(fsrc > 0.5) {+ // lerp(dst, sqrt(dst), (2.0 * fsrc - 1.0))+ return scale<T>(fdst + (2.0 * fsrc - 1.0) * (sqrt(fdst) - fdst));+ }++ // lerp(dst, dst^2, (1.0 - 2.0 * fsrc))+ return scale<T>(fdst - (1.0 - 2.0*fsrc) * fdst * (1.0 - fdst));+ }+};++template<class T,+ template <typename> typename ClampPolicy>+struct CFVividLight : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;+ using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;++ if (src < halfValue<T>()) {+ if (isZeroValue(src)) {+ return isUnitValueClamped(dst) ? clamp_policy::clampResultAllowNegative(dst) : 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_policy::clampResult(+ unitValue<T>() -+ clamp_policy::fixInfiniteAfterDivision(+ divideInCompositeSpace<T>(dsti, src2)+ )+ );+ }++ if (isUnitValue(src)) {+ return isZeroValueClamped(dst) ? zeroValue<T>() : unitValue<T>();+ }++ // min(1,max(0, dst / (2*(1-src)))+ composite_type srci2 = inv(src);+ srci2 += srci2;+ return clamp_policy::clampResultAllowNegative(+ clamp_policy::fixInfiniteAfterDivision(+ divideInCompositeSpace<T>(composite_type(dst), srci2)+ )+ );+ }+};++template<class T,+ template <typename> typename ClampPolicy>+struct CFPinLight : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;+ using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;++ // 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 dsti = inv(dst);- return clamp<T>(unitValue<T>() - (dsti * unitValue<T>() / src2));+ composite_type a = qMin<composite_type>(dst, src2);+ composite_type b = qMax<composite_type>(src2-Arithmetic::unitValue<T>(), a);+ return clamp_policy::clampResult(b);}-- 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>();+ if (isZeroValue(dst))+ return isZeroValue(src) ? zeroValue<T>() : unitValue<T>();return scale<T>(2.0 * atan(scale<qreal>(src) / scale<qreal>(dst)) / Arithmetic::pi);}@@ -433,137 +480,206 @@ inline T cfLinearLight(T src, T dst) {}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);+struct CFParallel : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;- if (!srcIsSafe || !dstIsSafe) {- return zeroValue<T>();- }+ const bool srcIsSafe = !isUnsafeAsDivisor(src);+ const bool dstIsSafe = !isUnsafeAsDivisor(dst);- // 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);+ if (!srcIsSafe || !dstIsSafe) {+ return zeroValue<T>();+ }- return clamp<T>((unit+unit) * unit / (d+s));-}+ // 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);-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);-}+ return clamp<T>((unit+unit) * unit / (d+s));+ }+};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>());-}+struct CFEquivalence : KoClampedSourceAndDestinationBottomCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ // TODO: is the formula correct?+ // 1 - abs(dst - src)+ composite_type x = qAbs(composite_type(dst) - src);+ return clamp<T>(x);+ }+};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>());-}+struct CFGrainMerge : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return clampToSDR<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);-}+struct CFGrainExtract : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+ return clampToSDR<T>(composite_type(dst) - src + halfValue<T>());+ }+};++template<class T,+ template <typename> typename ClampPolicy>+struct CFHardMix : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ /**+ * We do not clamp dst here, because it is supposed to be modified by+ * cfColorDodge if it is too bright. The result will be clamped in the+ * subordinate function.+ */+ return dst > halfValue<T>() ?+ CFColorDodge<T, ClampPolicy>::composeChannel(src,dst) :+ CFColorBurn<T, ClampPolicy>::composeChannel(src,dst);+ }+};template<class T>-inline T cfHardMixPhotoshop(T src, T dst) {- using namespace Arithmetic;- typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;+struct CFHardMixPhotoshop : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;- const composite_type sum = composite_type(src) + dst;+ const composite_type sum = composite_type(src) + dst;- return sum > unitValue<T>() ? unitValue<T>() : zeroValue<T>();-}+ 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;+struct CFHardMixSofterPhotoshop : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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);+ 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));-}+ return clampToSDR<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);-}+struct CFAdditiveSubtractive : KoClampedSourceAndDestinationBottomCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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>(qAbs(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)));-}+struct CFGammaDark : KoClampedSourceAndDestinationBottomCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ if (isZeroValue(src)) {+ return zeroValue<T>();+ }++ if (isUnitValue(dst)) {+ return unitValue<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)));-}+struct CFGammaLight : KoClampedSourceAndDestinationBottomCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ if (isZeroValue(dst)) {+ return isZeroValue(src) ? unitValue<T>() : zeroValue<T>();+ }++ if (isUnitValue(dst)) {+ return unitValue<T>();+ }++ 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)));-}+struct CFGammaIllumination : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ return inv(CFGammaDark<T>::composeChannel(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)));-}+struct CFGeometricMean : KoClampedSourceAndDestinationBottomCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ if (isUnitValue(src) && isUnitValue(dst)) {+ return unitValue<T>();+ }++ 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); }+struct CFOverlay : CFHardLight<T> {};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));+template<class T,+ template <typename> typename ClampPolicy>+struct CFHardOverlay : KoClampedSourceCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using clamp_policy = ClampPolicy<T>;+ using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;++ if (isUnitValue(src)) {+ return unitValue<T>();+ }++ if(src >= halfValue<T>()) {+ return clamp_policy::clampResultAllowNegative(+ clamp_policy::fixInfiniteAfterDivision(+ divideInCompositeSpace<T>(composite_type(dst),+ 2 * composite_type(inv(src)))+ )+ );+ }++ return clamp_policy::clampResultAllowNegative(+ multiplyInCompositeSpace<T>(composite_type(dst),+ 2 * composite_type(src))+ );}- 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); }@@ -619,64 +735,73 @@ inline T cfFreeze(T src, T dst) {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>();- }+template<typename T>+struct CFHelow : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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- return (cfGlow(src,dst));-}+ if (isUnitValue<T>(CFHardMixPhotoshop<T>::composeChannel(src,dst))) {+ return cfHeat(src,dst);+ }-template<class T>-inline T cfFrect(T src, T dst) {- using namespace Arithmetic;+ if (isZeroValue<T>(src)) {+ return zeroValue<T>();+ }- if (cfHardMixPhotoshop(src,dst) == unitValue<T>()) {- return cfFreeze(src,dst);+ return (cfGlow(src,dst));}+};- if (dst == zeroValue<T>()) {- return zeroValue<T>();- }+template<typename T>+struct CFFrect : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;- return (cfReflect(src,dst));-}+ if (isUnitValue<T>(CFHardMixPhotoshop<T>::composeChannel(src,dst))) {+ return cfFreeze(src,dst);+ }-template<class T>-inline T cfGleat(T src, T dst) {- using namespace Arithmetic;+ if (isZeroValue<T>(dst)) {+ return zeroValue<T>();+ }++ return (cfReflect(src,dst));+ }+};++template<typename T>+struct CFGleat : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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);++ if(isUnitValue<T>(dst)) {+ return unitValue<T>();+ }++ if(isUnitValue<T>(CFHardMixPhotoshop<T>::composeChannel(src, dst))) {+ return cfGlow(src,dst);+ }++ return (cfHeat(src,dst));}-- return (cfHeat(src,dst));-}+};template<class T>-inline T cfReeze(T src, T dst) {- using namespace Arithmetic;-- return (cfGleat(dst,src));-}+struct CFReeze : CFGleat<T>+{+ static inline T composeChannel(T src, T dst) {+ return CFGleat<T>::composeChannel(dst,src);+ }+};+template<class T>inline T cfFhyrd(T src, T dst) {using namespace Arithmetic;- return (cfAllanon(cfFrect(src,dst),cfHelow(src,dst)));+ return (cfAllanon(CFFrect<T>::composeChannel(src,dst),+ CFHelow<T>::composeChannel(src,dst)));}template<class T>@@ -701,22 +826,25 @@ inline T cfInterpolationB(T src, T dst) {}-template<class T>-inline T cfPenumbraB(T src, T dst) {- using namespace Arithmetic;+template<typename T>+struct CFPenumbraB : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;+ using namespace KoCompositeOpClampPolicy;- if (dst == unitValue<T>()) {- return unitValue<T>();- }- if (dst + src < unitValue<T>()) {- return (cfColorDodge(dst,src)/2);- }- if (src == zeroValue<T>()) {- return zeroValue<T>();- }+ if (dst == unitValue<T>()) {+ return unitValue<T>();+ }+ if (dst + src < unitValue<T>()) {+ return FunctorWithSDRClampPolicy<CFColorDodge, T>::composeChannel(dst,src) / 2;+ }+ if (src == zeroValue<T>()) {+ return zeroValue<T>();+ }- return inv(clamp<T>(div(inv(dst),src)/2));-}+ return inv(clamp<T>(div(inv(dst),src)/2));+ }+};template<class T>inline T cfPenumbraD(T src, T dst) {@@ -736,12 +864,13 @@ inline T cfPenumbraC(T src, T dst) {return cfPenumbraD(dst,src);}-template<class T>-inline T cfPenumbraA(T src, T dst) {- using namespace Arithmetic;- return (cfPenumbraB(dst,src));-}+template<typename T>+struct CFPenumbraA : CFPenumbraB<T> {+ static inline T composeChannel(T src, T dst) {+ return CFPenumbraB<T>::composeChannel(dst, src);+ }+};template<class T>inline T cfSoftLightIFSIllusions(T src, T dst) {@@ -760,18 +889,21 @@ inline T cfSoftLightPegtopDelphi(T src, T dst) {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;+struct CFNegation : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(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;+ 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);-}+ return T(d);+ }+};template<class T>inline T cfNor(T src, T dst) {@@ -1029,16 +1161,20 @@ inline T cfEasyBurn(T src, T 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<typename T>+struct CFFlatLight : KoClampedSourceAndDestinationCompositeOpGenericFunctorBase<T> {+ static inline T composeChannel(T src, T dst) {+ using namespace Arithmetic;++ if (isZeroValue<T>(src)) {+ return zeroValue<T>();+ }++ return clamp<T>(isUnitValue<T>(CFHardMixPhotoshop<T>::composeChannel(inv(src),dst)) ?+ CFPenumbraB<T>::composeChannel(src,dst) :+ CFPenumbraA<T>::composeChannel(src,dst));+ }+};template<class HSXType, class TReal>diff --git a/libs/pigment/compositeops/KoCompositeOpGeneric.h b/libs/pigment/compositeops/KoCompositeOpGeneric.hindex 00fcd5aec8..c8ae9cb3a5 100644--- a/libs/pigment/compositeops/KoCompositeOpGeneric.h+++ b/libs/pigment/compositeops/KoCompositeOpGeneric.h@@ -3,12 +3,31 @@** SPDX-License-Identifier: LGPL-2.1-or-later*/-#ifndef _KOCOMPOSITEOP_GENERIC_H_#define _KOCOMPOSITEOP_GENERIC_H_-//#include "KoCompositeOpFunctions.h"#include "KoCompositeOpBase.h"+#include "KoCompositeOpGenericFunctorBase.h"++namespace detail {++/**+ * A special class to convert old-style composite function into a functor+ * with clamping properties+ */++template <class Traits,+ typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type)>+struct CompositeFunctionWrapper : KoCompositeOpGenericFunctorBase<typename Traits::channels_type>+{+ using channels_type = typename Traits::channels_type;++ static inline channels_type composeChannel(channels_type src, channels_type dst) {+ return compositeFunc(src, dst);+ }+};++}/*** Generic CompositeOp for separable channel compositing functions@@ -19,19 +38,19 @@*/template<class Traits,- typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type),+ typename CompositeOpFunctor,typename BlendingPolicy>-class KoCompositeOpGenericSC: public KoCompositeOpBase< Traits, KoCompositeOpGenericSC<Traits,compositeFunc,BlendingPolicy> >+class KoCompositeOpGenericSCFunctor: public KoCompositeOpBase< Traits, KoCompositeOpGenericSCFunctor<Traits,CompositeOpFunctor,BlendingPolicy> >{- typedef KoCompositeOpBase< Traits, KoCompositeOpGenericSC<Traits,compositeFunc,BlendingPolicy> > base_class;+ typedef KoCompositeOpBase< Traits, KoCompositeOpGenericSCFunctor<Traits,CompositeOpFunctor,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)+ KoCompositeOpGenericSCFunctor(const KoColorSpace* cs, const QString& id, const QString& category): base_class(cs, id, category) { }public:@@ -43,43 +62,101 @@ public:srcAlpha = mul(srcAlpha, maskAlpha, opacity);+ if (isZeroValue(srcAlpha)) {+ return dstAlpha;+ }+if(alphaLocked) {- if(dstAlpha != zeroValue<channels_type>()) {+ if(!isZeroValue(dstAlpha)) {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]);+ const channels_type srcInBlendSpace =+ CompositeOpFunctor::clampSourceChannelValue(+ BlendingPolicy::toAdditiveSpace(+ src[i]));+ const channels_type dstInBlendSpace =+ CompositeOpFunctor::clampDestinationChannelValue(+ BlendingPolicy::toAdditiveSpace(+ dst[i]));dst[i] = BlendingPolicy::fromAdditiveSpace(lerp(dstInBlendSpace,- compositeFunc(srcInBlendSpace, dstInBlendSpace),+ CompositeOpFunctor::composeChannel(srcInBlendSpace, dstInBlendSpace),srcAlpha));}}}return dstAlpha;- }- else {+ } else if (isZeroValue(dstAlpha)) {+ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ dst[i] = BlendingPolicy::fromAdditiveSpace(+ CompositeOpFunctor::clampSourceChannelValue(+ BlendingPolicy::toAdditiveSpace(src[i])));+ }+ }+ return srcAlpha;+ } else if (isUnitValue(dstAlpha)) {+ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ const channels_type srcInBlendSpace =+ CompositeOpFunctor::clampSourceChannelValue(+ BlendingPolicy::toAdditiveSpace(+ src[i]));+ const channels_type dstInBlendSpace =+ CompositeOpFunctor::clampDestinationChannelValue(+ BlendingPolicy::toAdditiveSpace(+ dst[i]));++ dst[i] = BlendingPolicy::fromAdditiveSpace(+ lerp(dstInBlendSpace,+ CompositeOpFunctor::composeChannel(srcInBlendSpace, dstInBlendSpace),+ srcAlpha));+ }+ }+ return unitValue<channels_type>();+ } else if (isUnitValue(srcAlpha)) {+ for(qint32 i=0; i <channels_nb; i++) {+ if(i != alpha_pos && (allChannelFlags || channelFlags.testBit(i))) {+ const channels_type srcInBlendSpace =+ CompositeOpFunctor::clampSourceChannelValue(+ BlendingPolicy::toAdditiveSpace(+ src[i]));+ const channels_type dstInBlendSpace =+ CompositeOpFunctor::clampDestinationChannelValue(+ BlendingPolicy::toAdditiveSpace(+ dst[i]));++ dst[i] = BlendingPolicy::fromAdditiveSpace(+ lerp(srcInBlendSpace,+ CompositeOpFunctor::composeChannel(srcInBlendSpace, dstInBlendSpace),+ dstAlpha));+ }+ }+ return unitValue<channels_type>();+ } else {channels_type newDstAlpha = unionShapeOpacity(srcAlpha, dstAlpha);-- if(newDstAlpha != zeroValue<channels_type>()) {++ if (!isZeroValue(newDstAlpha)) {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]);+ const channels_type srcInBlendSpace =+ CompositeOpFunctor::clampSourceChannelValue(+ BlendingPolicy::toAdditiveSpace(+ src[i]));+ const channels_type dstInBlendSpace =+ CompositeOpFunctor::clampDestinationChannelValue(+ BlendingPolicy::toAdditiveSpace(+ dst[i]));channels_type result =blend(srcInBlendSpace, srcAlpha,dstInBlendSpace, dstAlpha,- compositeFunc(srcInBlendSpace, dstInBlendSpace));--+ CompositeOpFunctor::composeChannel(srcInBlendSpace, dstInBlendSpace));dst[i] = BlendingPolicy::fromAdditiveSpace(div(result, newDstAlpha));-- //qDebug() << i << ppVar(result) << ppVar(compositeFunc(srcInBlendSpace, dstInBlendSpace)) << div(result, newDstAlpha);}}}@@ -90,6 +167,19 @@ public:};+template<+ class Traits,+ typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type),+ typename BlendingPolicy+>+class KoCompositeOpGenericSC : public KoCompositeOpGenericSCFunctor<Traits, detail::CompositeFunctionWrapper<Traits, compositeFunc>, BlendingPolicy>+{+protected:+ using base_class = KoCompositeOpGenericSCFunctor<Traits, detail::CompositeFunctionWrapper<Traits, compositeFunc>, BlendingPolicy>;+public:+ using base_class::base_class;+};+/*** Generic CompositeOp for nonseparable/HSL channel compositing functions*diff --git a/libs/pigment/compositeops/KoCompositeOpGenericFunctorBase.h b/libs/pigment/compositeops/KoCompositeOpGenericFunctorBase.hnew file mode 100644index 0000000000..4c51352029--- /dev/null+++ b/libs/pigment/compositeops/KoCompositeOpGenericFunctorBase.h@@ -0,0 +1,83 @@+/*+ * SPDX-FileCopyrightText: 2024 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KOCOMPOSITEOPGENERICFUNCTORBASE_H+#define KOCOMPOSITEOPGENERICFUNCTORBASE_H++#include <KoColorSpaceMaths.h>++/**+ * KoCompositeOpGenericFunctorBase is a set of policies for+ * KoCompositeOpGenericSCFunctor that defines clamping of+ * source and destination **channels** before passing them to+ * the composite function.+ *+ * We cannot clamp the data in the composite function itself,+ * because KoCompositeOpGenericSCFunctor also dose quite heavy+ * blending of the channels when alpha values are non-null+ *+ * IMPORTANT: these policies work with channels_type, not with+ * composite_type! Hence they do **nothing** for integer color+ * spaces!+ */++// no clamping at all+template <typename T>+struct KoCompositeOpGenericFunctorBase+{+ static inline T clampSourceChannelValue(T value) {+ return value;+ }++ static inline T clampDestinationChannelValue(T value) {+ return value;+ }+};++// clamp source channel to SDR, keep destination channel unbounded+template <typename T>+struct KoClampedSourceCompositeOpGenericFunctorBase+{+ static inline T clampSourceChannelValue(T value) {+ using namespace Arithmetic;+ return clampChannelToSDR(value);+ }++ static inline T clampDestinationChannelValue(T value) {+ return value;+ }+};++// make sure source and destination channels are non-negative+template <typename T>+struct KoClampedSourceAndDestinationBottomCompositeOpGenericFunctorBase+{+ static inline T clampSourceChannelValue(T value) {+ using namespace Arithmetic;+ return clampChannelToSDRBottom(value);+ }++ static inline T clampDestinationChannelValue(T value) {+ using namespace Arithmetic;+ return clampChannelToSDRBottom(value);+ }+};++// clamp both source and destination channels to SDR range+template <typename T>+struct KoClampedSourceAndDestinationCompositeOpGenericFunctorBase+{+ static inline T clampSourceChannelValue(T value) {+ using namespace Arithmetic;+ return clampChannelToSDR(value);+ }++ static inline T clampDestinationChannelValue(T value) {+ using namespace Arithmetic;+ return clampChannelToSDR(value);+ }+};++#endif // KOCOMPOSITEOPGENERICFUNCTORBASE_Hdiff --git a/libs/pigment/compositeops/KoCompositeOps.h b/libs/pigment/compositeops/KoCompositeOps.hindex 11bd934cab..0e575c0e6f 100644--- a/libs/pigment/compositeops/KoCompositeOps.h+++ b/libs/pigment/compositeops/KoCompositeOps.h@@ -28,6 +28,7 @@#include "compositeops/KoCompositeOpGreater.h"#include "compositeops/KoAlphaDarkenParamsWrapper.h"#include "compositeops/KoColorSpaceBlendingPolicy.h"+#include "compositeops/KoCompositeOpClampPolicy.h"#include "KoOptimizedCompositeOpFactory.h"namespace _Private {@@ -131,6 +132,7 @@ struct AddGeneralOps<Traits, true>typedef typename Traits::channels_type Arg;typedef Arg (*CompositeFunc)(Arg, Arg);static const qint32 alpha_pos = Traits::alpha_pos;+ static constexpr bool IsIntegerSpace = std::numeric_limits<Arg>::is_integer;template<CompositeFunc func>static void add(KoColorSpace* cs, const QString& id, const QString& category) {@@ -145,7 +147,22 @@ struct AddGeneralOps<Traits, true>}}+ template<typename Functor>+ static void add(KoColorSpace* cs, const QString& id, const QString& category) {+ if constexpr (std::is_base_of_v<KoCmykTraits<typename Traits::channels_type>, Traits>) {+ if (useSubtractiveBlendingForCmykColorSpaces()) {+ cs->addCompositeOp(new KoCompositeOpGenericSCFunctor<Traits, Functor, KoSubtractiveBlendingPolicy<Traits>>(cs, id, category));+ } else {+ cs->addCompositeOp(new KoCompositeOpGenericSCFunctor<Traits, Functor, KoAdditiveBlendingPolicy<Traits>>(cs, id, category));+ }+ } else {+ cs->addCompositeOp(new KoCompositeOpGenericSCFunctor<Traits, Functor, KoAdditiveBlendingPolicy<Traits>>(cs, id, category));+ }+ }+static void add(KoColorSpace* cs) {+ using namespace KoCompositeOpClampPolicy;+cs->addCompositeOp(OptimizedOpsSelector<Traits>::createOverOp(cs));cs->addCompositeOp(OptimizedOpsSelector<Traits>::createAlphaDarkenOp(cs));cs->addCompositeOp(OptimizedOpsSelector<Traits>::createCopyOp(cs));@@ -174,37 +191,54 @@ struct AddGeneralOps<Traits, true>cs->addCompositeOp(new KoCompositeOpGreater<Traits, KoAdditiveBlendingPolicy<Traits>>(cs));}- add<&cfOverlay<Arg> >(cs, COMPOSITE_OVERLAY , KoCompositeOp::categoryMix());- add<&cfGrainMerge<Arg> >(cs, COMPOSITE_GRAIN_MERGE , KoCompositeOp::categoryMix());- add<&cfGrainExtract<Arg> >(cs, COMPOSITE_GRAIN_EXTRACT , KoCompositeOp::categoryMix());- add<&cfHardMix<Arg> >(cs, COMPOSITE_HARD_MIX , KoCompositeOp::categoryMix());- add<&cfHardMixPhotoshop<Arg>>(cs, COMPOSITE_HARD_MIX_PHOTOSHOP, KoCompositeOp::categoryMix());- add<&cfHardMixSofterPhotoshop<Arg>>(cs, COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP, KoCompositeOp::categoryMix());- add<&cfGeometricMean<Arg> >(cs, COMPOSITE_GEOMETRIC_MEAN, KoCompositeOp::categoryMix());- add<&cfParallel<Arg> >(cs, COMPOSITE_PARALLEL , KoCompositeOp::categoryMix());+ add<CFOverlay<Arg> >(cs, COMPOSITE_OVERLAY , KoCompositeOp::categoryMix());+ add<CFGrainMerge<Arg> >(cs, COMPOSITE_GRAIN_MERGE , KoCompositeOp::categoryMix());+ add<CFGrainExtract<Arg> >(cs, COMPOSITE_GRAIN_EXTRACT , KoCompositeOp::categoryMix());+ add<FunctorWithSDRClampPolicy<CFHardMix, Arg>>(cs, COMPOSITE_HARD_MIX, KoCompositeOp::categoryMix());+ if constexpr (!IsIntegerSpace) {+ add<CFHardMix<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_HARD_MIX_HDR, KoCompositeOp::categoryMix());+ }++ add<CFHardMixPhotoshop<Arg>>(cs, COMPOSITE_HARD_MIX_PHOTOSHOP, KoCompositeOp::categoryMix());+ add<CFHardMixSofterPhotoshop<Arg>>(cs, COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP, KoCompositeOp::categoryMix());+ add<CFGeometricMean<Arg> >(cs, COMPOSITE_GEOMETRIC_MEAN, KoCompositeOp::categoryMix());+ add<CFParallel<Arg> >(cs, COMPOSITE_PARALLEL , KoCompositeOp::categoryMix());add<&cfAllanon<Arg> >(cs, COMPOSITE_ALLANON , KoCompositeOp::categoryMix());- add<&cfHardOverlay<Arg> >(cs, COMPOSITE_HARD_OVERLAY , KoCompositeOp::categoryMix());+ add<FunctorWithSDRClampPolicy<CFHardOverlay, Arg>>(cs, COMPOSITE_HARD_OVERLAY, KoCompositeOp::categoryMix());+ if constexpr (!IsIntegerSpace) {+ add<CFHardOverlay<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_HARD_OVERLAY_HDR, KoCompositeOp::categoryMix());+ }+add<&cfInterpolation<Arg> >(cs, COMPOSITE_INTERPOLATION , KoCompositeOp::categoryMix());add<&cfInterpolationB<Arg>>(cs, COMPOSITE_INTERPOLATIONB, KoCompositeOp::categoryMix());- add<&cfPenumbraA<Arg> >(cs, COMPOSITE_PENUMBRAA , KoCompositeOp::categoryMix());- add<&cfPenumbraB<Arg> >(cs, COMPOSITE_PENUMBRAB , KoCompositeOp::categoryMix());+ add<CFPenumbraA<Arg> >(cs, COMPOSITE_PENUMBRAA , KoCompositeOp::categoryMix());+ add<CFPenumbraB<Arg> >(cs, COMPOSITE_PENUMBRAB , KoCompositeOp::categoryMix());add<&cfPenumbraC<Arg> >(cs, COMPOSITE_PENUMBRAC , KoCompositeOp::categoryMix());add<&cfPenumbraD<Arg> >(cs, COMPOSITE_PENUMBRAD , KoCompositeOp::categoryMix());add<&cfScreen<Arg> >(cs, COMPOSITE_SCREEN , KoCompositeOp::categoryLight());- add<&cfColorDodge<Arg> >(cs, COMPOSITE_DODGE , KoCompositeOp::categoryLight());++ add<FunctorWithSDRClampPolicy<CFColorDodge, Arg>>(cs, COMPOSITE_DODGE, KoCompositeOp::categoryLight());+ if constexpr (!IsIntegerSpace) {+ add<CFColorDodge<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_DODGE_HDR, KoCompositeOp::categoryLight());+ }+add<&cfAddition<Arg> >(cs, COMPOSITE_LINEAR_DODGE, KoCompositeOp::categoryLight());add<&cfLightenOnly<Arg> >(cs, COMPOSITE_LIGHTEN , KoCompositeOp::categoryLight());- add<&cfHardLight<Arg> >(cs, COMPOSITE_HARD_LIGHT , KoCompositeOp::categoryLight());+ add<CFHardLight<Arg> >(cs, COMPOSITE_HARD_LIGHT , KoCompositeOp::categoryLight());add<&cfSoftLightIFSIllusions<Arg>>(cs, COMPOSITE_SOFT_LIGHT_IFS_ILLUSIONS, KoCompositeOp::categoryLight());add<&cfSoftLightPegtopDelphi<Arg>>(cs, COMPOSITE_SOFT_LIGHT_PEGTOP_DELPHI, KoCompositeOp::categoryLight());- add<&cfSoftLightSvg<Arg>>(cs, COMPOSITE_SOFT_LIGHT_SVG, KoCompositeOp::categoryLight());- add<&cfSoftLight<Arg> >(cs, COMPOSITE_SOFT_LIGHT_PHOTOSHOP, KoCompositeOp::categoryLight());- add<&cfGammaLight<Arg> >(cs, COMPOSITE_GAMMA_LIGHT , KoCompositeOp::categoryLight());- add<&cfGammaIllumination<Arg>>(cs, COMPOSITE_GAMMA_ILLUMINATION, KoCompositeOp::categoryLight());- add<&cfVividLight<Arg> >(cs, COMPOSITE_VIVID_LIGHT , KoCompositeOp::categoryLight());- add<&cfFlatLight<Arg> >(cs, COMPOSITE_FLAT_LIGHT , KoCompositeOp::categoryLight());- add<&cfPinLight<Arg> >(cs, COMPOSITE_PIN_LIGHT , KoCompositeOp::categoryLight());+ add<CFSoftLightSvg<Arg> >(cs, COMPOSITE_SOFT_LIGHT_SVG, KoCompositeOp::categoryLight());+ add<CFSoftLight<Arg> >(cs, COMPOSITE_SOFT_LIGHT_PHOTOSHOP, KoCompositeOp::categoryLight());+ add<CFGammaLight<Arg> >(cs, COMPOSITE_GAMMA_LIGHT , KoCompositeOp::categoryLight());+ add<CFGammaIllumination<Arg>>(cs, COMPOSITE_GAMMA_ILLUMINATION, KoCompositeOp::categoryLight());++ add<FunctorWithSDRClampPolicy<CFVividLight, Arg>>(cs, COMPOSITE_VIVID_LIGHT, KoCompositeOp::categoryLight());+ if constexpr (!IsIntegerSpace) {+ add<CFVividLight<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_VIVID_LIGHT_HDR, KoCompositeOp::categoryLight());+ }+ add<CFFlatLight<Arg> >(cs, COMPOSITE_FLAT_LIGHT , KoCompositeOp::categoryLight());+ add<CFPinLight<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_PIN_LIGHT, KoCompositeOp::categoryLight()); // using HDR mode as defaultadd<&cfLinearLight<Arg> >(cs, COMPOSITE_LINEAR_LIGHT, KoCompositeOp::categoryLight());add<&cfPNormA<Arg> >(cs, COMPOSITE_PNORM_A , KoCompositeOp::categoryLight());add<&cfPNormB<Arg> >(cs, COMPOSITE_PNORM_B , KoCompositeOp::categoryLight());@@ -213,17 +247,17 @@ struct AddGeneralOps<Traits, true>add<&cfFogLightenIFSIllusions<Arg>>(cs, COMPOSITE_FOG_LIGHTEN_IFS_ILLUSIONS, KoCompositeOp::categoryLight());add<&cfEasyDodge<Arg> >(cs, COMPOSITE_EASY_DODGE , KoCompositeOp::categoryLight());- add<&cfColorBurn<Arg> >(cs, COMPOSITE_BURN , KoCompositeOp::categoryDark());- add<&cfLinearBurn<Arg> >(cs, COMPOSITE_LINEAR_BURN , KoCompositeOp::categoryDark());+ add<CFColorBurn<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_BURN, KoCompositeOp::categoryDark()); // using HDR mode as default+ add<CFLinearBurn<Arg, ClampAsFloatHDR>>(cs, COMPOSITE_LINEAR_BURN , KoCompositeOp::categoryDark()); // using HDR mode as defaultadd<&cfDarkenOnly<Arg> >(cs, COMPOSITE_DARKEN , KoCompositeOp::categoryDark());- add<&cfGammaDark<Arg> >(cs, COMPOSITE_GAMMA_DARK , KoCompositeOp::categoryDark());+ add<CFGammaDark<Arg> >(cs, COMPOSITE_GAMMA_DARK , KoCompositeOp::categoryDark());add<&cfShadeIFSIllusions<Arg>>(cs, COMPOSITE_SHADE_IFS_ILLUSIONS, KoCompositeOp::categoryDark());add<&cfFogDarkenIFSIllusions<Arg>>(cs, COMPOSITE_FOG_DARKEN_IFS_ILLUSIONS, KoCompositeOp::categoryDark());add<&cfEasyBurn<Arg> >(cs, COMPOSITE_EASY_BURN , KoCompositeOp::categoryDark());add<&cfAddition<Arg> >(cs, COMPOSITE_ADD , KoCompositeOp::categoryArithmetic());add<&cfSubtract<Arg> >(cs, COMPOSITE_SUBTRACT , KoCompositeOp::categoryArithmetic());- add<&cfInverseSubtract<Arg> >(cs, COMPOSITE_INVERSE_SUBTRACT, KoCompositeOp::categoryArithmetic());+ add<CFInverseSubtract<Arg> >(cs, COMPOSITE_INVERSE_SUBTRACT, KoCompositeOp::categoryArithmetic());add<&cfMultiply<Arg> >(cs, COMPOSITE_MULT , KoCompositeOp::categoryArithmetic());add<&cfDivide<Arg> >(cs, COMPOSITE_DIVIDE , KoCompositeOp::categoryArithmetic());@@ -236,10 +270,10 @@ struct AddGeneralOps<Traits, true>add<&cfArcTangent<Arg> >(cs, COMPOSITE_ARC_TANGENT , KoCompositeOp::categoryNegative());add<&cfDifference<Arg> >(cs, COMPOSITE_DIFF , KoCompositeOp::categoryNegative());- add<&cfExclusion<Arg> >(cs, COMPOSITE_EXCLUSION , KoCompositeOp::categoryNegative());- add<&cfEquivalence<Arg> >(cs, COMPOSITE_EQUIVALENCE , KoCompositeOp::categoryNegative());- add<&cfAdditiveSubtractive<Arg>>(cs, COMPOSITE_ADDITIVE_SUBTRACTIVE, KoCompositeOp::categoryNegative());- add<&cfNegation<Arg> >(cs, COMPOSITE_NEGATION , KoCompositeOp::categoryNegative());+ add<CFExclusion<Arg> >(cs, COMPOSITE_EXCLUSION , KoCompositeOp::categoryNegative());+ add<CFEquivalence<Arg> >(cs, COMPOSITE_EQUIVALENCE , KoCompositeOp::categoryNegative());+ add<CFAdditiveSubtractive<Arg> >(cs, COMPOSITE_ADDITIVE_SUBTRACTIVE, KoCompositeOp::categoryNegative());+ add<CFNegation<Arg> >(cs, COMPOSITE_NEGATION , KoCompositeOp::categoryNegative());add<&cfXor<Arg> >(cs, COMPOSITE_XOR , KoCompositeOp::categoryBinary());add<&cfOr<Arg> >(cs, COMPOSITE_OR , KoCompositeOp::categoryBinary());@@ -256,10 +290,10 @@ struct AddGeneralOps<Traits, true>add<&cfGlow<Arg> >(cs, COMPOSITE_GLOW , KoCompositeOp::categoryQuadratic());add<&cfFreeze<Arg> >(cs, COMPOSITE_FREEZE , KoCompositeOp::categoryQuadratic());add<&cfHeat<Arg> >(cs, COMPOSITE_HEAT , KoCompositeOp::categoryQuadratic());- add<&cfGleat<Arg> >(cs, COMPOSITE_GLEAT , KoCompositeOp::categoryQuadratic());- add<&cfHelow<Arg> >(cs, COMPOSITE_HELOW , KoCompositeOp::categoryQuadratic());- add<&cfReeze<Arg> >(cs, COMPOSITE_REEZE , KoCompositeOp::categoryQuadratic());- add<&cfFrect<Arg> >(cs, COMPOSITE_FRECT , KoCompositeOp::categoryQuadratic());+ add<CFGleat<Arg> >(cs, COMPOSITE_GLEAT , KoCompositeOp::categoryQuadratic());+ add<CFHelow<Arg> >(cs, COMPOSITE_HELOW , KoCompositeOp::categoryQuadratic());+ add<CFReeze<Arg> >(cs, COMPOSITE_REEZE , KoCompositeOp::categoryQuadratic());+ add<CFFrect<Arg> >(cs, COMPOSITE_FRECT , KoCompositeOp::categoryQuadratic());add<&cfFhyrd<Arg> >(cs, COMPOSITE_FHYRD , KoCompositeOp::categoryQuadratic());cs->addCompositeOp(new KoCompositeOpDissolve<Traits>(cs, KoCompositeOp::categoryMisc()));diff --git a/libs/ui/tool/strokes/KisMaskingBrushCompositeOp.h b/libs/ui/tool/strokes/KisMaskingBrushCompositeOp.hindex 8a7d3b73ef..729900ca32 100644--- a/libs/ui/tool/strokes/KisMaskingBrushCompositeOp.h+++ b/libs/ui/tool/strokes/KisMaskingBrushCompositeOp.h@@ -136,7 +136,7 @@ struct CompositeFunction<channels_type, KIS_MASKING_BRUSH_COMPOSITE_OVERLAY, fal{channels_type apply(channels_type src, channels_type dst){- return cfOverlay(src, dst);+ return CFOverlay<channels_type>::composeChannel(src, dst);}};@@ -148,7 +148,7 @@ struct CompositeFunction<channels_type, KIS_MASKING_BRUSH_COMPOSITE_OVERLAY, truchannels_type apply(channels_type src, channels_type dst){- return cfOverlay(src, Arithmetic::mul(dst, StrengthCompositeFunctionBase<channels_type>::strength));+ return CFOverlay<channels_type>::composeChannel(src, Arithmetic::mul(dst, StrengthCompositeFunctionBase<channels_type>::strength));}};@@ -165,7 +165,7 @@ struct CompositeFunction<channels_type, KIS_MASKING_BRUSH_COMPOSITE_OVERLAY, truchannels_type apply(channels_type src, channels_type dst){- return cfOverlay(Arithmetic::unionShapeOpacity(src, invertedStrength), dst);+ return CFOverlay<channels_type>::composeChannel(Arithmetic::unionShapeOpacity(src, invertedStrength), dst);}};@@ -268,25 +268,12 @@ inline T colorBurnAlphaHelper(T src, T dst)composite_type(KoColorSpaceMathsTraits<T>::unitValue));}-// Integer version of color burn alphatemplate<class T>-inline typename std::enable_if<std::numeric_limits<T>::is_integer, T>::type-colorBurnAlpha(T src, T dst)+inline T colorBurnAlpha(T src, T dst){using namespace Arithmetic;- return inv(colorBurnHelper(src, dst));-}--// Floating point version of color burn alpha-template<class T>-inline typename std::enable_if<!std::numeric_limits<T>::is_integer, T>::type-colorBurnAlpha(T src, T dst)-{- using namespace Arithmetic;- const T result = colorBurnAlphaHelper(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>::unitValue);+ using namespace KoCompositeOpClampPolicy;+ return FunctorWithSDRClampPolicy<CFColorBurn, T>::composeChannel(src, dst);}template <typename channels_type>@@ -431,7 +418,7 @@ struct CompositeFunction<channels_type, KIS_MASKING_BRUSH_COMPOSITE_HARD_MIX_PHO{channels_type apply(channels_type src, channels_type dst){- return cfHardMixPhotoshop(src, dst);+ return CFHardMixPhotoshop<channels_type>::composeChannel(src, dst);}};@@ -443,7 +430,7 @@ struct CompositeFunction<channels_type, KIS_MASKING_BRUSH_COMPOSITE_HARD_MIX_PHOchannels_type apply(channels_type src, channels_type dst){- return cfHardMixPhotoshop(src, Arithmetic::mul(dst, StrengthCompositeFunctionBase<channels_type>::strength));+ return CFHardMixPhotoshop<channels_type>::composeChannel(src, Arithmetic::mul(dst, StrengthCompositeFunctionBase<channels_type>::strength));}};@@ -461,7 +448,7 @@ struct CompositeFunction<channels_type, KIS_MASKING_BRUSH_COMPOSITE_HARD_MIX_PHOchannels_type apply(channels_type src, channels_type dst){using namespace Arithmetic;- return mul(cfHardMixPhotoshop(unionShapeOpacity(src, invertedStrength), dst),+ return mul(CFHardMixPhotoshop<channels_type>::composeChannel(unionShapeOpacity(src, invertedStrength), dst),unionShapeOpacity(dst, StrengthCompositeFunctionBase<channels_type>::strength));}};