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

temp2

Dmitry Kazakov42d19f923363
diff --git a/libs/pigment/tests/KoCompositeOpFunctions2.h b/libs/pigment/tests/KoCompositeOpFunctions2.h
index dd8bbd0e68..ee59f114ff 100644
--- a/libs/pigment/tests/KoCompositeOpFunctions2.h
+++ b/libs/pigment/tests/KoCompositeOpFunctions2.h
@@ -466,8 +466,8 @@ 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(tmp::isZeroValue(src))
+ return tmp::isZeroValue(dst) ? zeroValue<T>() : unitValue<T>();
return clamp<T>(div(dst, src));
}
diff --git a/libs/pigment/tests/TestCompositeOpInversion.cpp b/libs/pigment/tests/TestCompositeOpInversion.cpp
index aa1d3b1eca..51863a937d 100644
--- a/libs/pigment/tests/TestCompositeOpInversion.cpp
+++ b/libs/pigment/tests/TestCompositeOpInversion.cpp
@@ -280,6 +280,7 @@ quint16 getColorValueU(const KoColor &c) {
}
+
KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isHDR)
{
KoCompositeOp *op = nullptr;
@@ -333,11 +334,61 @@ KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isHDR)
if (cs->colorDepthId() == Float32BitsColorDepthID) {
using Traits = KoRgbF32Traits;
constexpr auto func = &cfAddition<float>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
} else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
using Traits = KoRgbU16Traits;
- constexpr auto func = &cfLinearBurn<quint16, ClampPolicyInteger>;
- op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryDark());
+ 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;
+ constexpr auto func = &cfInverseSubtract<float>;
+ op = new KoCompositeOpGenericSC<Traits, func, KoAdditiveBlendingPolicy<Traits>>(cs, id, KoCompositeOp::categoryArithmetic());
+ } else if (cs->colorDepthId() == Integer16BitsColorDepthID) {
+ using Traits = KoRgbU16Traits;
+ constexpr auto func = &cfInverseSubtract<quint16>;
+ op = new KoCompositeOpGenericSC<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_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());
}
}
@@ -346,20 +397,30 @@ KoCompositeOp* createOp(const KoColorSpace *cs, const QString &id, bool isHDR)
return op;
}
-
}
+enum TestFlag {
+ None = 0x0,
+ HDR = 0x1,
+ UndefinedIfSrcInHDRRange = 0x2,
+ AllowClampedComparisonInSDR = 0x4,
+ SrcCannotMakeNegative = 0x8
+};
+Q_DECLARE_FLAGS(TestFlags, TestFlag)
+Q_DECLARE_OPERATORS_FOR_FLAGS(TestFlags)
+Q_DECLARE_METATYPE(TestFlags)
+
void TestCompositeOpInversion::testFloatModes()
{
QFETCH(QString, id);
- QFETCH(bool, isHDR);
+ QFETCH(TestFlags, flags);
const KoColorSpace* csU = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Integer16BitsColorDepthID.id(), 0);
- const KoCompositeOp *opU = createOp(csU, id, isHDR);
+ const KoCompositeOp *opU = createOp(csU, id, flags.testFlag(HDR));
const KoCompositeOp *opU2 = csU->compositeOp(id);
const KoColorSpace* csF = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0);
- const KoCompositeOp *opF = createOp(csF, id, isHDR);
+ const KoCompositeOp *opF = createOp(csF, id, flags.testFlag(HDR));
auto createColorU = [&] (qreal colorF, qreal alphaF) {
using namespace Arithmetic;
@@ -443,7 +504,7 @@ void TestCompositeOpInversion::testFloatModes()
float resultColorValueF = getColorValue(resultColorF);
- if (!isHDR) {
+ if (!flags.testFlag(HDR)) {
KoColor resultColorU2 = dstColorU;
opU2->composite(resultColorU2.data(), 0, srcColorU.data(), 0,
@@ -455,6 +516,7 @@ void TestCompositeOpInversion::testFloatModes()
const quint16 resultColor = getColorValueU(resultColorU);
if (resultColor != referenceColor) {
+
qDebug() << "--- integer implementation is inconsistent to the original mode! ---";
qDebug() << "U16 result: " << fixed << qSetRealNumberPrecision(8)
<< "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
@@ -464,7 +526,54 @@ void TestCompositeOpInversion::testFloatModes()
}
}
- if (isHDR) {
+ if (dstColorValue >= -std::numeric_limits<float>::epsilon() &&
+ dstColorValue <= 1.0 + std::numeric_limits<float>::epsilon() &&
+ srcColorValue >= -std::numeric_limits<float>::epsilon() &&
+ srcColorValue <= 1.0 + std::numeric_limits<float>::epsilon() &&
+ qAbs(resultColorValueF - resultColorValueU) > 0.001) {
+
+ if (qFuzzyIsNull(resultColorValueU) &&
+ qAbs(resultColorValueU - qMax(0.0f, resultColorValueF)) <= 0.001) {
+ // noop, should be fine result
+ } else if (qFuzzyCompare(resultColorValueU, 1.0f) &&
+ qAbs(resultColorValueU - qMin(1.0f, resultColorValueF)) <= 0.001) {
+ // noop, should be fine result as well
+ } else if (resultColorValueF < 0.0) {
+ qDebug() << "--- resulting value in SDR range is negative! ---";
+ qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
+ qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);
+ QFAIL("resulting value in SDR range is negative!");
+ } else {
+
+ // in non-HDR mode both blending modes should behave in
+ // exactly the same way (including zero and unit values)
+
+ qDebug() << "--- inconsistent result in SDR range ---";
+ qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
+ qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);
+ QFAIL("inconsistent result in SDR range!");
+ }
+ }
+
+ if (flags.testFlag(SrcCannotMakeNegative) &&
+ dstColorValue >= 0.0f &&
+ dstColorValue <= 1.0f &&
+ resultColorValueF < 0.0) {
+
+ qDebug() << "--- resulting value in SDR range is negative for SRC-clipped op! ---";
+ qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
+ qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);
+ QFAIL("resulting value in SDR range is negative for SRC-clipped op!");
+ }
+
+#if 0
+ if (flags.testFlag(HDR)) {
// just verify sanity of the result
if (dstColorValue >= 0.0 && resultColorValueF < 0.0) {
@@ -495,17 +604,31 @@ void TestCompositeOpInversion::testFloatModes()
} else if (dstColorValue >= -std::numeric_limits<float>::epsilon() &&
dstColorValue <= 1.0 + std::numeric_limits<float>::epsilon() &&
qAbs(resultColorValueF - resultColorValueU) > 0.001) {
- // in non-HDR mode both blending modes should behave in
- // exactly the same way (including zero and unit values)
- qDebug() << "--- inconsistent result between int and float_sdr modes ---";
- qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)
- << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
- qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)
- << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);
- //QFAIL("inconsistent result between int and float_sdr modes!");
+ if (flags.testFlag(AllowClampedComparisonInSDR) &&
+ qFuzzyIsNull(resultColorValueU) &&
+ qAbs(resultColorValueU - qMax(0.0f, resultColorValueF)) <= 0.001) {
+ // noop, should be fine result
+ } else if (flags.testFlag(AllowClampedComparisonInSDR) &&
+ qFuzzyCompare(resultColorValueU, 1.0f) &&
+ qAbs(resultColorValueU - qMin(1.0f, resultColorValueF)) <= 0.001) {
+ // noop, should be fine result as well
+ } else if (!flags.testFlag(UndefinedIfSrcInHDRRange) ||
+ (srcColorValue >= -std::numeric_limits<float>::epsilon() &&
+ srcColorValue <= 1.0 + std::numeric_limits<float>::epsilon())) {
+
+ // in non-HDR mode both blending modes should behave in
+ // exactly the same way (including zero and unit values)
+
+ qDebug() << "--- inconsistent result between int and float_sdr modes ---";
+ qDebug() << "U16:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorU) << "+" << "d:" << dumpPixel(dstColorU) << "->" << dumpPixel(resultColorU);
+ qDebug() << "F32:" << fixed << qSetRealNumberPrecision(8)
+ << "s:" << dumpPixel(srcColorF) << "+" << "d:" << dumpPixel(dstColorF) << "->" << dumpPixel(resultColorF);
+ QFAIL("inconsistent result between int and float_sdr modes!");
+ }
}
-
+#endif
}
}
}
@@ -583,11 +706,6 @@ void TestCompositeOpInversion::testFloatModes_data()
// ids << COMPOSITE_SHADE_IFS_ILLUSIONS;
// ids << COMPOSITE_FOG_DARKEN_IFS_ILLUSIONS;
// ids << COMPOSITE_EASY_BURN;
- ids << COMPOSITE_ADD;
-// ids << COMPOSITE_SUBTRACT;
-// ids << COMPOSITE_INVERSE_SUBTRACT;
-// ids << COMPOSITE_MULT;
-// ids << COMPOSITE_DIVIDE;
// ids << COMPOSITE_MOD;
// ids << COMPOSITE_MOD_CON;
// ids << COMPOSITE_DIVISIVE_MOD;
@@ -626,16 +744,34 @@ void TestCompositeOpInversion::testFloatModes_data()
// ids << COMPOSITE_LUMINOSITY_SAI;
+ QStringList specialIds;
+ specialIds << COMPOSITE_ADD;
+ specialIds << COMPOSITE_SUBTRACT;
+ specialIds << COMPOSITE_INVERSE_SUBTRACT;
+ specialIds << COMPOSITE_MULT;
+ specialIds << COMPOSITE_DIVIDE;
+
QTest::addColumn<QString>("id");
- QTest::addColumn<bool>("isHDR");
+ QTest::addColumn<TestFlags>("flags");
std::vector<bool> isHDRValues({false, true});
Q_FOREACH (const QString &id, ids) {
Q_FOREACH (const bool isHDR, isHDRValues) {
- QTest::addRow("%s_%s", id.toLatin1().data(), isHDR ? "hdr" : "sdr") << id << isHDR;
+ TestFlags flags = isHDR ? HDR : None;
+ flags |= SrcCannotMakeNegative;
+ QTest::addRow("%s_%s", id.toLatin1().data(), isHDR ? "hdr" : "sdr") << id << flags;
}
}
+
+ Q_FOREACH (const QString &id, specialIds) {
+ TestFlags flags = None;
+ QTest::addRow("%s_%s", id.toLatin1().data(), "sdr") << id << flags;
+ }
+
+// 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);
+
}
SIMPLE_TEST_MAIN(TestCompositeOpInversion)