Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Revert "temp4"

Dmitry Kazakov096c85215677
diff --git a/libs/pigment/tests/KoCompositeOpFunctions2.h b/libs/pigment/tests/KoCompositeOpFunctions2.h
index 8e5668c6d8..ee59f114ff 100644
--- a/libs/pigment/tests/KoCompositeOpFunctions2.h
+++ b/libs/pigment/tests/KoCompositeOpFunctions2.h
@@ -176,46 +176,6 @@ Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool isUnitValue(T v)
return KoColorSpaceMaths<T>::isUnitValue(v);
}
-template <typename T>
-Q_REQUIRED_RESULT static inline Q_DECL_UNUSED T clampChannelToSDRBottom(T v)
-{
- return v;
-}
-
-template <>
-Q_REQUIRED_RESULT inline Q_DECL_UNUSED float clampChannelToSDRBottom<float>(float v)
-{
- return qMax<float>(KoColorSpaceMathsTraits<float>::zeroValue, v);
-}
-
-template <typename T, typename composite_type = typename KoColorSpaceMathsTraits<T>::compositetype>
-Q_REQUIRED_RESULT static inline Q_DECL_UNUSED composite_type divideInCompositeSpace(composite_type a, composite_type b)
-{
- return a / b;
-}
-
-template <>
-Q_REQUIRED_RESULT inline Q_DECL_UNUSED
- KoColorSpaceMathsTraits<quint8>::compositetype
- divideInCompositeSpace<quint8>(KoColorSpaceMathsTraits<quint8>::compositetype a,
- KoColorSpaceMathsTraits<quint8>::compositetype b)
-
-{
- return a * KoColorSpaceMathsTraits<quint8>::unitValue / b;
-}
-
-template <>
-Q_REQUIRED_RESULT inline Q_DECL_UNUSED
- KoColorSpaceMathsTraits<quint16>::compositetype
- divideInCompositeSpace<quint16>(KoColorSpaceMathsTraits<quint16>::compositetype a,
- KoColorSpaceMathsTraits<quint16>::compositetype b)
-
-{
- return a * KoColorSpaceMathsTraits<quint16>::unitValue / b;
-}
-
-
-
}
template<class HSXType, class TReal>
@@ -465,12 +425,6 @@ inline T cfColorDodge(T src, T dst) {
return tmp::isNullValueClamped(dst) ? zeroValue<T>() : KoColorSpaceMathsTraits<T>::unitValue;
}
- // qDebug() << ppVar(src) << ppVar(dst) << (clamp_policy::clampResultAllowNegative(
- // clamp_policy::fixInfiniteAfterDivision(
- // div(dst, inv(src))
- // )
- // ));
-
return clamp_policy::clampResultAllowNegative(
clamp_policy::fixInfiniteAfterDivision(
div(dst, inv(src))
@@ -518,15 +472,11 @@ inline T cfDivide(T src, T dst) {
return clamp<T>(div(dst, src));
}
-template<class T,
- template <typename> typename ClampPolicy>
+template<class T>
inline T cfHardLight(T src, T dst) {
using namespace Arithmetic;
- using clamp_policy = ClampPolicy<T>;
- using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;
-
- src = clamp_policy::clampInputSrc(src);
-
+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
+
composite_type src2 = composite_type(src) + src;
if(src > halfValue<T>()) {
@@ -545,17 +495,6 @@ template<class T>
inline T cfSoftLightSvg(T src, T dst) {
using namespace Arithmetic;
- /**
- * Driver channel is always clamped to 0...1.0 range
- */
- src = clampChannelToSDR<T>(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);
@@ -571,83 +510,50 @@ inline T cfSoftLightSvg(T src, T dst) {
template<class T>
inline T cfSoftLight(T src, T dst) {
using namespace Arithmetic;
- /**
- * Driver channel is always clamped to 0...1.0 range
- */
- src = clampChannelToSDR<T>(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>
+template<class T>
inline T cfVividLight(T src, T dst) {
using namespace Arithmetic;
- using clamp_policy = ClampPolicy<T>;
- using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;
+ typedef typename KoColorSpaceMathsTraits<T>::compositetype composite_type;
- src = clamp_policy::clampInputSrc(src);
-
- if (src < halfValue<T>()) {
- if (tmp::isZeroValue(src)) {
- return tmp::isUnitValueClamped(dst) ? clamp_policy::clampResultAllowNegative(dst) : zeroValue<T>();
- }
+ if(src < halfValue<T>()) {
+ if(isUnsafeAsDivisor(src))
+ return (dst == unitValue<T>()) ? unitValue<T>() : zeroValue<T>();
// min(1,max(0,1-(1-dst) / (2*src)))
composite_type src2 = composite_type(src) + src;
composite_type dsti = inv(dst);
- return clamp_policy::clampResult(
- unitValue<T>() -
- clamp_policy::fixInfiniteAfterDivision(
- tmp::divideInCompositeSpace<T>(dsti, src2)
- )
- );
+ return clamp<T>(unitValue<T>() - (dsti * unitValue<T>() / src2));
}
- if (tmp::isUnitValue(src)) {
- return tmp::isNullValueClamped(dst) ? zeroValue<T>() : unitValue<T>();
- }
+ 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_policy::clampResultAllowNegative(
- clamp_policy::fixInfiniteAfterDivision(
- tmp::divideInCompositeSpace<T>(composite_type(dst), srci2)
- )
- );
+ return clamp<T>(composite_type(dst) * unitValue<T>() / srci2);
}
-template<class T,
- template <typename> typename ClampPolicy>
+template<class T>
inline T cfPinLight(T src, T dst) {
- using namespace Arithmetic;
- using clamp_policy = ClampPolicy<T>;
- using composite_type = typename KoColorSpaceMathsTraits<T>::compositetype;
-
- src = clampChannelToSDR(src);
-
+ 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 clamp_policy::clampResult(b);
+ return T(b);
}
template<class T>
diff --git a/libs/pigment/tests/KoCompositeOpGeneric2.h b/libs/pigment/tests/KoCompositeOpGeneric2.h
index e19794cb77..29cb4fdc1c 100644
--- a/libs/pigment/tests/KoCompositeOpGeneric2.h
+++ b/libs/pigment/tests/KoCompositeOpGeneric2.h
@@ -66,7 +66,7 @@ public:
}
else {
channels_type newDstAlpha = unionShapeOpacity(srcAlpha, dstAlpha);
-
+
if(newDstAlpha != zeroValue<channels_type>()) {
for(qint32 i=0; i <channels_nb; i++) {
@@ -83,17 +83,10 @@ public:
dst[i] = BlendingPolicy::fromAdditiveSpace(div(result, newDstAlpha));
- // qDebug() << i
- // << ppVar(src[i])
- // << ppVar(dst[i])
- // << fixed << qSetRealNumberPrecision(10)
- // << ppVar(compositeFunc(srcInBlendSpace, dstInBlendSpace))
- // << ppVar(result)
- // << div(result, newDstAlpha)
- // << reset
- // << ppVar(newDstAlpha)
- // << ppVar(srcAlpha)
- // << ppVar(dstAlpha);
+// qDebug() << i << ppVar(result)
+// << ppVar(srcInBlendSpace)
+// << ppVar(dstInBlendSpace)
+// << ppVar(compositeFunc(srcInBlendSpace, dstInBlendSpace)) << div(result, newDstAlpha);
}
}
}
diff --git a/libs/pigment/tests/TestCompositeOpInversion.cpp b/libs/pigment/tests/TestCompositeOpInversion.cpp
index ec7323032a..4f3280bac4 100644
--- a/libs/pigment/tests/TestCompositeOpInversion.cpp
+++ b/libs/pigment/tests/TestCompositeOpInversion.cpp
@@ -330,82 +330,6 @@ KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isHDR)
constexpr auto func = &cfLinearBurn<quint16, ClampPolicyInteger>;
op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
}
-
- } else if (id == COMPOSITE_HARD_LIGHT) {
- if (cs->colorDepthId() == Float32BitsColorDepthID) {
- using Traits = KoRgbF32Traits;
- if (isHDR) {
- constexpr auto func = &cfHardLight<float, ClampPolicyFloatHDR>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- } else {
- constexpr auto func = &cfHardLight<float, ClampPolicyFloatSDR>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- }
- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
- using Traits = KoRgbU16Traits;
- constexpr auto func = &cfHardLight<quint16, ClampPolicyInteger>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
- }
- } else if (id == COMPOSITE_SOFT_LIGHT_PHOTOSHOP) {
- if (cs->colorDepthId() == Float32BitsColorDepthID) {
- using Traits = KoRgbF32Traits;
- constexpr auto func = &cfSoftLight<float>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
- using Traits = KoRgbU16Traits;
- constexpr auto func = &cfSoftLight<quint16>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
- }
- } else if (id == COMPOSITE_SOFT_LIGHT_SVG) {
- if (cs->colorDepthId() == Float32BitsColorDepthID) {
- using Traits = KoRgbF32Traits;
- constexpr auto func = &cfSoftLightSvg<float>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
- using Traits = KoRgbU16Traits;
- constexpr auto func = &cfSoftLightSvg<quint16>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
- }
- } else if (id == COMPOSITE_VIVID_LIGHT) {
- if (cs->colorDepthId() == Float32BitsColorDepthID) {
- using Traits = KoRgbF32Traits;
- if (isHDR) {
- constexpr auto func = &cfVividLight<float, ClampPolicyFloatHDR>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- } else {
- constexpr auto func = &cfVividLight<float, ClampPolicyFloatSDR>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- }
- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
- using Traits = KoRgbU16Traits;
- constexpr auto func = &cfVividLight<quint16, ClampPolicyInteger>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
- }
- // } else if (id == COMPOSITE_FLAT_LIGHT) {
- // if (cs->colorDepthId() == Float32BitsColorDepthID) {
- // using Traits = KoRgbF32Traits;
- // constexpr auto func = &cfFlatLight<float>;
- // op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- // } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
- // using Traits = KoRgbU16Traits;
- // constexpr auto func = &cfFlatLight<quint16>;
- // op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
- // }
- } else if (id == COMPOSITE_PIN_LIGHT) {
- if (cs->colorDepthId() == Float32BitsColorDepthID) {
- using Traits = KoRgbF32Traits;
- if (isHDR) {
- constexpr auto func = &cfPinLight<float, ClampPolicyFloatHDR>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- } else {
- constexpr auto func = &cfPinLight<float, ClampPolicyFloatSDR>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
- }
- } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
- using Traits = KoRgbU16Traits;
- constexpr auto func = &cfPinLight<quint16, ClampPolicyInteger>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
- }
} else if (id == COMPOSITE_ADD) {
if (cs->colorDepthId() == Float32BitsColorDepthID) {
using Traits = KoRgbF32Traits;
@@ -456,6 +380,16 @@ KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isHDR)
constexpr auto func = &cfDivide<quint16>;
op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
}
+ } else if (id == COMPOSITE_HARD_LIGHT) {
+ if (cs->colorDepthId() == Float32BitsColorDepthID) {
+ using Traits = KoRgbF32Traits;
+ constexpr auto func = &cfHardLight<float>;
+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
+ } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
+ using Traits = KoRgbU16Traits;
+ constexpr auto func = &cfHardLight<quint16>;
+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
+ }
} else if (id == COMPOSITE_EXCLUSION) {
if (cs->colorDepthId() == Float32BitsColorDepthID) {
using Traits = KoRgbF32Traits;
@@ -530,8 +464,7 @@ enum TestFlag {
HDR = 0x1,
UndefinedIfSrcInHDRRange = 0x2,
AllowClampedComparisonInSDR = 0x4,
- SrcCannotMakeNegative = 0x8,
- ForceClippedResult = 0x10
+ SrcCannotMakeNegative = 0x8
};
Q_DECLARE_FLAGS(TestFlags, TestFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(TestFlags)
@@ -581,7 +514,6 @@ void TestCompositeOpInversion::testFloatModes()
1.0});
//std::vector<qreal> opacityValues({1.0});
std::vector<qreal> alphaValues({1.0});
- //std::vector<qreal> alphaValues = opacityValues;
std::vector<qreal> values({-0.1,
0 - std::numeric_limits<float>::epsilon(),
0,
@@ -605,10 +537,10 @@ void TestCompositeOpInversion::testFloatModes()
Q_FOREACH (qreal dstColorValue, valuesDst) {
- float tolerance = opacity > 0.999 ? 0.001 :
- opacity > 0.5 ? 10 :
- opacity > 0.2 ? 100 :
- 100;
+ float tolerance = opacity > 0.8 ? 0.001 :
+ opacity > 0.5 ? 0.1 :
+ opacity > 0.2 ? 0.2 :
+ 1.0;
// {
// {
// {
@@ -667,7 +599,6 @@ void TestCompositeOpInversion::testFloatModes()
}
QVERIFY(!std::isnan(resultColorValueF));
- QVERIFY(!std::isinf(resultColorValueF));
if (dstColorValue >= -std::numeric_limits<float>::epsilon() &&
dstColorValue <= 1.0 + std::numeric_limits<float>::epsilon() &&
@@ -718,20 +649,6 @@ void TestCompositeOpInversion::testFloatModes()
QFAIL("resulting value in SDR range is negative for SRC-clipped op!");
}
- // TODO; it doesn't work for some reason
- if (opacity > 0.01 &&
- flags.testFlag(ForceClippedResult) &&
- resultColorValueF > 1.0f) {
-
- qDebug() << "--- resulting value in outside SDR range for clipped op! ---";
- qDebug() << ppVar(opacity);
- qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)
- << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)
- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);
- QFAIL("resulting value in outside SDR range for clipped op!");
- }
-
#if 0
if (flags.testFlag(HDR)) {
// just verify sanity of the result
@@ -842,14 +759,16 @@ void TestCompositeOpInversion::testFloatModes_data()
ids << COMPOSITE_DODGE;
// ids << COMPOSITE_LINEAR_DODGE;
// ids << COMPOSITE_LIGHTEN;
- ids << COMPOSITE_HARD_LIGHT;
+// ids << COMPOSITE_HARD_LIGHT;
// ids << COMPOSITE_SOFT_LIGHT_IFS_ILLUSIONS;
// ids << COMPOSITE_SOFT_LIGHT_PEGTOP_DELPHI;
+// ids << COMPOSITE_SOFT_LIGHT_SVG;
+// ids << COMPOSITE_SOFT_LIGHT_PHOTOSHOP;
// ids << COMPOSITE_GAMMA_LIGHT;
// ids << COMPOSITE_GAMMA_ILLUMINATION;
- ids << COMPOSITE_VIVID_LIGHT;
- ids << COMPOSITE_FLAT_LIGHT;
- ids << COMPOSITE_PIN_LIGHT;
+// ids << COMPOSITE_VIVID_LIGHT;
+// ids << COMPOSITE_FLAT_LIGHT;
+// ids << COMPOSITE_PIN_LIGHT;
// ids << COMPOSITE_LINEAR_LIGHT;
// ids << COMPOSITE_PNORM_A;
// ids << COMPOSITE_PNORM_B;
@@ -917,9 +836,6 @@ void TestCompositeOpInversion::testFloatModes_data()
specialIds << COMPOSITE_NEGATION;
- // ids << COMPOSITE_SOFT_LIGHT_SVG;
- // ids << COMPOSITE_SOFT_LIGHT_PHOTOSHOP;
-
QTest::addColumn<QString>("id");
QTest::addColumn<TestFlags>("flags");
@@ -929,11 +845,6 @@ void TestCompositeOpInversion::testFloatModes_data()
Q_FOREACH (const bool isHDR, isHDRValues) {
TestFlags flags = isHDR ? HDR : None;
flags |= SrcCannotMakeNegative;
-
- if (!isHDR) {
- //flags |= ForceClippedResult;
- }
-
QTest::addRow("%s_%s", id.toLatin1().data(), isHDR ? "hdr" : "sdr") << id << flags;
}
}
@@ -943,9 +854,7 @@ void TestCompositeOpInversion::testFloatModes_data()
QTest::addRow("%s_%s", id.toLatin1().data(), "sdr") << id << flags;
}
- // both channels are clamped, sdr only!
- QTest::addRow("%s_%s", COMPOSITE_SOFT_LIGHT_SVG.toLatin1().data(), "sdr") << COMPOSITE_SOFT_LIGHT_SVG << TestFlags(SrcCannotMakeNegative/* | ForceClippedResult*/);
- QTest::addRow("%s_%s", COMPOSITE_SOFT_LIGHT_PHOTOSHOP.toLatin1().data(), "sdr") << COMPOSITE_SOFT_LIGHT_PHOTOSHOP << TestFlags(SrcCannotMakeNegative/* | ForceClippedResult*/);
+// QTest::addRow("%s_%s", COMPOSITE_MULT.toLatin1().data(), "sdr") << COMPOSITE_MULT << TestFlags(None);
// QTest::addRow("%s_%s", COMPOSITE_DIVIDE.toLatin1().data(), "sdr") << COMPOSITE_DIVIDE << TestFlags(None);
}