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++
Switch blendmodes to the mainstream implementation
Dmitry Kazakovaa44ee75dec2
diff --git a/libs/pigment/tests/KoCompositeOpFunctions2.h b/libs/pigment/tests/KoCompositeOpFunctions2.hdeleted file mode 100644index bc9d68bfb3..0000000000--- a/libs/pigment/tests/KoCompositeOpFunctions2.h+++ /dev/null@@ -1,1179 +0,0 @@-/*- * 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<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>-struct CFColorBurn : ClampedSourceCompositeFunctorBase<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)- )- )- );- }-};---template<class T,- template <typename> typename ClampPolicy>-struct CFLinearBurn : ClampedSourceCompositeFunctorBase<T> {- static inline T composeChannel(T src, T dst) {- using namespace Arithmetic;- using clamp_policy = ClampPolicy<T>;- using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;-- return clamp_policy::clampResult(composite_type(src) + dst - unitValue<T>());- }-};--template<typename T,- template <typename> typename ClampPolicy>-struct CFColorDodge : ClampedSourceCompositeFunctorBase<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) {- 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>-struct CFInverseSubtract : ClampedSourceCompositeFunctorBase<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>-struct CFExclusion : ClampedSourceAndDestinationCompositeFunctorBase<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 (isZeroValue(src))- return isZeroValue(dst) ? zeroValue<T>() : unitValue<T>();-- return clamp<T>(div(dst, src));-}--template<class T>-struct CFHardLight : ClampedSourceCompositeFunctorBase<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;-- 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>-struct CFSoftLightSvg : ClampedSourceCompositeFunctorBase<T> {- static inline T composeChannel(T src, T dst) {- using namespace Arithmetic;-- // TODO: check if dst-clamping should happen at higher level-- /**- * 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) {- 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>-struct CFSoftLight : ClampedSourceCompositeFunctorBase<T> {- static inline T composeChannel(T src, T dst) {- using namespace Arithmetic;-- // TODO: check if dst-clamping should happen at higher level-- /**- * 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 : ClampedSourceCompositeFunctorBase<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 : ClampedSourceCompositeFunctorBase<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 a = qMin<composite_type>(dst, src2);- composite_type b = qMax<composite_type>(src2-Arithmetic::unitValue<T>(), a);- return clamp_policy::clampResult(b);- }-};--template<class T>-inline T cfArcTangent(T src, T dst) {- using namespace Arithmetic;-- if (isZeroValue(dst))- return isZeroValue(src) ? 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>-struct CFParallel : ClampedSourceAndDestinationCompositeFunctorBase<T> {- static inline T composeChannel(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>-struct CFEquivalence : ClampedSourceAndDestinationBottomCompositeFunctorBase<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>-struct CFGrainMerge : ClampedSourceAndDestinationCompositeFunctorBase<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>-struct CFGrainExtract : ClampedSourceAndDestinationCompositeFunctorBase<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 : ClampedSourceCompositeFunctorBase<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>-struct CFHardMixPhotoshop : ClampedSourceAndDestinationCompositeFunctorBase<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;-- 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>-struct CFHardMixSofterPhotoshop : ClampedSourceAndDestinationCompositeFunctorBase<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);-- return clampToSDR<T>(dstScaleFactor * dst - srcScaleFactor * inv(src));- }-};--template<class T>-struct CFAdditiveSubtractive : ClampedSourceAndDestinationBottomCompositeFunctorBase<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>-struct CFGammaDark : ClampedSourceAndDestinationBottomCompositeFunctorBase<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>-struct CFGammaLight : ClampedSourceAndDestinationBottomCompositeFunctorBase<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>-struct CFGammaIllumination : ClampedSourceAndDestinationCompositeFunctorBase<T> {- static inline T composeChannel(T src, T dst) {- using namespace Arithmetic;- return inv(CFGammaDark<T>::composeChannel(inv(src),inv(dst)));- }-};--template<class T>-struct CFGeometricMean : ClampedSourceAndDestinationBottomCompositeFunctorBase<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); }--template<class T>-inline T cfMultiply(T src, T dst) { return Arithmetic::mul(src, dst); }--template<class T,- template <typename> typename ClampPolicy>-struct CFHardOverlay : ClampedSourceCompositeFunctorBase<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))- );- }-};--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>-struct CFNegation : ClampedSourceAndDestinationCompositeFunctorBase<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;-- 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.hdeleted file mode 100644index 5ff0fae6b2..0000000000--- a/libs/pigment/tests/KoCompositeOpGeneric2.h+++ /dev/null@@ -1,398 +0,0 @@-/*- * 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"--template <class Traits,- typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type)>-struct CompositeFunctionWrapper-{- using channels_type = typename Traits::channels_type;-- static inline channels_type composeChannel(channels_type src, channels_type dst) {- return compositeFunc(src, dst);- }-- static inline channels_type clampSourceChannelValue(channels_type value) {- return value;- }-- static inline channels_type clampDestinationChannelValue(channels_type value) {- return value;- }-};--template <typename T>-struct ClampedSourceCompositeFunctorBase-{- static inline T clampSourceChannelValue(T value) {- using namespace Arithmetic;- return clampChannelToSDR(value);- }-- static inline T clampDestinationChannelValue(T value) {- return value;- }-};--template <typename T>-struct ClampedSourceAndDestinationBottomCompositeFunctorBase-{- static inline T clampSourceChannelValue(T value) {- using namespace Arithmetic;- return clampChannelToSDRBottom(value);- }-- static inline T clampDestinationChannelValue(T value) {- using namespace Arithmetic;- return clampChannelToSDRBottom(value);- }-};--template <typename T>-struct ClampedSourceAndDestinationCompositeFunctorBase-{- static inline T clampSourceChannelValue(T value) {- using namespace Arithmetic;- return clampChannelToSDR(value);- }-- static inline T clampDestinationChannelValue(T value) {- using namespace Arithmetic;- return clampChannelToSDR(value);- }-};--/**- * 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 CompositeOpFunctor,- typename BlendingPolicy->-class KoCompositeOpGenericSCFunctor: public KoCompositeOpBase< Traits, KoCompositeOpGenericSCFunctor<Traits,CompositeOpFunctor,BlendingPolicy> >-{- 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:- KoCompositeOpGenericSCFunctor(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 (isZeroValue(srcAlpha)) {- return dstAlpha;- }-- if(alphaLocked) {- if(!isZeroValue(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 dstAlpha;- } 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 (!isZeroValue(newDstAlpha)) {-- 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]));-- channels_type result =- blend(srcInBlendSpace, srcAlpha,- dstInBlendSpace, dstAlpha,- CompositeOpFunctor::composeChannel(srcInBlendSpace, dstInBlendSpace));-- dst[i] = BlendingPolicy::fromAdditiveSpace(div(result, newDstAlpha));--// qDebug() << i-// << fixed << qSetRealNumberPrecision(10)-// << ppVar(src[i])-// << ppVar(dst[i])-// << ppVar(CompositeOpFunctor::composeChannel(srcInBlendSpace, dstInBlendSpace))-// << ppVar(result)-// << div(result, newDstAlpha)-// << reset-// << ppVar(newDstAlpha)-// << ppVar(srcAlpha)-// << ppVar(dstAlpha)-// << ppVar(isUnitValue(result))-// << ppVar(isUnitValue(newDstAlpha));- }- }- }-- return newDstAlpha;- }- }-};---template<- class Traits,- typename Traits::channels_type compositeFunc(typename Traits::channels_type, typename Traits::channels_type),- typename BlendingPolicy->-class KoCompositeOpGenericSC : public KoCompositeOpGenericSCFunctor<Traits, CompositeFunctionWrapper<Traits, compositeFunc>, BlendingPolicy>-{-protected:- using base_class = KoCompositeOpGenericSCFunctor<Traits, CompositeFunctionWrapper<Traits, compositeFunc>, BlendingPolicy>;-public:- using base_class::base_class;-};--/**- * 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_p.cpp b/libs/pigment/tests/TestCompositeOpInversion_p.cppindex c0a373cc72..2883768634 100644--- a/libs/pigment/tests/TestCompositeOpInversion_p.cpp+++ b/libs/pigment/tests/TestCompositeOpInversion_p.cpp@@ -11,8 +11,8 @@#include <KoCompositeOpRegistry.h>#include <KoColorModelStandardIds.h>-#include <KoCompositeOpGeneric2.h>-#include <KoCompositeOpFunctions2.h>+#include <KoCompositeOpGeneric.h>+#include <KoCompositeOpFunctions.h>#include "compositeops/KoColorSpaceBlendingPolicy.h"#include "compositeops/KoCompositeOpClampPolicy.h"@@ -23,404 +23,60 @@ const KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isconst KoCompositeOp *op = nullptr;- if (id == COMPOSITE_DODGE) {+ /**+ * Some of the blendmodes exist only "in theory". We test them only to make sure+ * they are not actually needed in real life (exactly the same in SDR range and+ * SDR/negative-preserving).+ */+ if (id == COMPOSITE_BURN && !isHDR) { // SDR-only, HDR is the defaultif (cs->colorDepthId() == Float32BitsColorDepthID) {using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFColorDodge<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryLight());- } else {- using func = CFColorDodge<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryLight());- }- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFColorDodge<quint16, ClampAsInteger>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryLight());- }- } else if (id == COMPOSITE_BURN) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFColorBurn<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func,- KoAdditiveBlendingPolicy<Traits>>- (cs, id, KoCompositeOp::categoryDark());- } else {- using func = CFColorBurn<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func,- KoAdditiveBlendingPolicy<Traits>>- (cs, id, KoCompositeOp::categoryDark());- }+ using func = CFColorBurn<float, ClampAsFloatSDR>;+ op = new KoCompositeOpGenericSCFunctor<Traits, func,+ KoAdditiveBlendingPolicy<Traits>>+ (cs, id, KoCompositeOp::categoryDark());} else if (cs->colorDepthId() == Integer16BitsColorDepthID) {using Traits = KoRgbU16Traits;using func = CFColorBurn<quint16, ClampAsInteger>;op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());}- } else if (id == COMPOSITE_LINEAR_BURN) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFLinearBurn<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else {- using func = CFLinearBurn<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- }- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFLinearBurn<quint16, ClampAsInteger>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- }-- } else if (id == COMPOSITE_HARD_LIGHT) {+ } else if (id == COMPOSITE_LINEAR_BURN && !isHDR) { // SDR-only, HDR is the defaultif (cs->colorDepthId() == Float32BitsColorDepthID) {using Traits = KoRgbF32Traits;- using func = CFHardLight<float>;+ using func = CFLinearBurn<float, ClampAsFloatSDR>;op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());} else if (cs->colorDepthId() == Integer16BitsColorDepthID) {using Traits = KoRgbU16Traits;- using func = CFHardLight<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_SOFT_LIGHT_PHOTOSHOP) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFSoftLight<float>;+ using func = CFLinearBurn<quint16, ClampAsInteger>;op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFSoftLight<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_SOFT_LIGHT_SVG) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFSoftLightSvg<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFSoftLightSvg<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());}+ } else if (id == COMPOSITE_DODGE) {+ const bool isFloat = cs->colorDepthId() == Float32BitsColorDepthID || cs->colorDepthId() == Float16BitsColorDepthID;+ const QString newId = isHDR && isFloat ? COMPOSITE_DODGE_HDR : COMPOSITE_DODGE;+ op = cs->compositeOp(newId);} else if (id == COMPOSITE_VIVID_LIGHT) {+ const bool isFloat = cs->colorDepthId() == Float32BitsColorDepthID || cs->colorDepthId() == Float16BitsColorDepthID;+ const QString newId = isHDR && isFloat ? COMPOSITE_VIVID_LIGHT_HDR : COMPOSITE_VIVID_LIGHT;+ op = cs->compositeOp(newId);+ } else if (id == COMPOSITE_PIN_LIGHT && !isHDR) { // SDR-only, HDR is the defaultif (cs->colorDepthId() == Float32BitsColorDepthID) {using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFVividLight<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else {- using func = CFVividLight<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- }- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFVividLight<quint16, ClampAsInteger>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_HARD_OVERLAY) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFHardOverlay<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else {- using func = CFHardOverlay<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- }- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFHardOverlay<quint16, ClampAsInteger>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_PIN_LIGHT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFPinLight<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else {- using func = CFPinLight<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- }+ using func = CFPinLight<float, ClampAsFloatSDR>;+ op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());} else if (cs->colorDepthId() == Integer16BitsColorDepthID) {using Traits = KoRgbU16Traits;using func = CFPinLight<quint16, ClampAsInteger>;op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());}- } 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::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfAddition<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_SUBTRACT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfSubtract<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfSubtract<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_INVERSE_SUBTRACT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFInverseSubtract<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFInverseSubtract<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_MULT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfMultiply<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfMultiply<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_DIVIDE) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfDivide<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfDivide<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_EXCLUSION) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFExclusion<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFExclusion<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_DIFF) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfDifference<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfDifference<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_SCREEN) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfScreen<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfScreen<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_DARKEN) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfDarkenOnly<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfDarkenOnly<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_LIGHTEN) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfLightenOnly<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfLightenOnly<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_NEGATION) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFNegation<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFNegation<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }} else if (id == COMPOSITE_HARD_MIX) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- if (isHDR) {- using func = CFHardMix<float, ClampAsFloatHDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- } else {- using func = CFHardMix<float, ClampAsFloatSDR>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());- }- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFHardMix<quint16, ClampAsInteger>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_HARD_MIX_PHOTOSHOP) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFHardMixPhotoshop<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFHardMixPhotoshop<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFHardMixSofterPhotoshop<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFHardMixSofterPhotoshop<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_LUMINOSITY_SAI) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfAdditionSAI<HSVType, float>;- op = new KoCompositeOpGenericSCAlpha<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfAdditionSAI<HSVType, float>;- op = new KoCompositeOpGenericSCAlpha<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_ARC_TANGENT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfArcTangent<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfArcTangent<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_ALLANON) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- constexpr auto func = &cfAllanon<float>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- constexpr auto func = &cfAllanon<quint16>;- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_PARALLEL) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFParallel<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFParallel<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_EQUIVALENCE) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFEquivalence<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFEquivalence<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_GRAIN_MERGE) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFGrainMerge<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFGrainMerge<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_GRAIN_EXTRACT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFGrainExtract<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFGrainExtract<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_GEOMETRIC_MEAN) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFGeometricMean<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFGeometricMean<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_ADDITIVE_SUBTRACTIVE) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFAdditiveSubtractive<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFAdditiveSubtractive<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_GAMMA_DARK) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFGammaDark<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFGammaDark<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_GAMMA_LIGHT) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFGammaLight<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFGammaLight<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_GAMMA_ILLUMINATION) {- if (cs->colorDepthId() == Float32BitsColorDepthID) {- using Traits = KoRgbF32Traits;- using func = CFGammaIllumination<float>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {- using Traits = KoRgbU16Traits;- using func = CFGammaIllumination<quint16>;- op = new KoCompositeOpGenericSCFunctor<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());- }- } else if (id == COMPOSITE_DISSOLVE ||- id == COMPOSITE_GREATER ||- id == COMPOSITE_OVER ||- id == COMPOSITE_ALPHA_DARKEN ||- id == COMPOSITE_DESTINATION_ATOP ||- id == COMPOSITE_DESTINATION_IN ||- id == COMPOSITE_ERASE ||- id == COMPOSITE_COPY) {+ const bool isFloat = cs->colorDepthId() == Float32BitsColorDepthID || cs->colorDepthId() == Float16BitsColorDepthID;+ const QString newId = isHDR && isFloat ? COMPOSITE_HARD_MIX_HDR : COMPOSITE_HARD_MIX;+ op = cs->compositeOp(newId);+ } else if (id == COMPOSITE_HARD_OVERLAY) {+ const bool isFloat = cs->colorDepthId() == Float32BitsColorDepthID || cs->colorDepthId() == Float16BitsColorDepthID;+ const QString newId = isHDR && isFloat? COMPOSITE_HARD_OVERLAY_HDR : COMPOSITE_HARD_OVERLAY;+ op = cs->compositeOp(newId);+ } else {op = cs->compositeOp(id);}