autotests: add a color pipeline test for identity transformations
If identity transformations aren't properly optimized out, we can have additional rounding errors and reduced performance. This test ensures that doesn't happen
This commit is contained in:
parent
9f2741af9f
commit
706d604305
5 changed files with 59 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <QTest>
|
||||
|
||||
#include "core/colorpipeline.h"
|
||||
#include "core/colorspace.h"
|
||||
|
||||
using namespace KWin;
|
||||
|
@ -21,6 +22,8 @@ private Q_SLOTS:
|
|||
void roundtripConversion_data();
|
||||
void roundtripConversion();
|
||||
void nonNormalizedPrimaries();
|
||||
void testIdentityTransformation_data();
|
||||
void testIdentityTransformation();
|
||||
};
|
||||
|
||||
static bool compareVectors(const QVector3D &one, const QVector3D &two, float maxDifference)
|
||||
|
@ -85,6 +88,34 @@ void TestColorspaces::nonNormalizedPrimaries()
|
|||
QCOMPARE_LE(std::abs(1 - convertedWhite.z()), s_resolution10bit);
|
||||
}
|
||||
|
||||
void TestColorspaces::testIdentityTransformation_data()
|
||||
{
|
||||
QTest::addColumn<NamedColorimetry>("colorimetry");
|
||||
QTest::addColumn<TransferFunction::Type>("transferFunction");
|
||||
|
||||
QTest::addRow("BT709 (sRGB)") << NamedColorimetry::BT709 << TransferFunction::sRGB;
|
||||
QTest::addRow("BT709 (gamma22)") << NamedColorimetry::BT709 << TransferFunction::gamma22;
|
||||
QTest::addRow("BT709 (PQ)") << NamedColorimetry::BT709 << TransferFunction::PerceptualQuantizer;
|
||||
QTest::addRow("BT709 (linear)") << NamedColorimetry::BT709 << TransferFunction::linear;
|
||||
QTest::addRow("BT2020 (sRGB)") << NamedColorimetry::BT2020 << TransferFunction::sRGB;
|
||||
QTest::addRow("BT2020 (gamma22)") << NamedColorimetry::BT2020 << TransferFunction::gamma22;
|
||||
QTest::addRow("BT2020 (PQ)") << NamedColorimetry::BT2020 << TransferFunction::PerceptualQuantizer;
|
||||
QTest::addRow("BT2020 (linear)") << NamedColorimetry::BT2020 << TransferFunction::linear;
|
||||
}
|
||||
|
||||
void TestColorspaces::testIdentityTransformation()
|
||||
{
|
||||
QFETCH(NamedColorimetry, colorimetry);
|
||||
QFETCH(TransferFunction::Type, transferFunction);
|
||||
const ColorDescription color(colorimetry, transferFunction, 100, 0, 100, 100);
|
||||
|
||||
const auto pipeline = ColorPipeline::create(color, color);
|
||||
if (!pipeline.isIdentity()) {
|
||||
qWarning() << pipeline;
|
||||
}
|
||||
QVERIFY(pipeline.isIdentity());
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestColorspaces)
|
||||
|
||||
#include "test_colorspaces.moc"
|
||||
|
|
|
@ -252,3 +252,21 @@ ColorMultiplier::ColorMultiplier(double factor)
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const KWin::ColorPipeline &pipeline)
|
||||
{
|
||||
debug << "ColorPipeline(";
|
||||
for (const auto &op : pipeline.ops) {
|
||||
if (auto tf = std::get_if<KWin::ColorTransferFunction>(&op.operation)) {
|
||||
debug << tf->tf;
|
||||
} else if (auto tf = std::get_if<KWin::InverseColorTransferFunction>(&op.operation)) {
|
||||
debug << "inverse" << tf->tf;
|
||||
} else if (auto mat = std::get_if<KWin::ColorMatrix>(&op.operation)) {
|
||||
debug << mat->mat;
|
||||
} else if (auto mult = std::get_if<KWin::ColorMultiplier>(&op.operation)) {
|
||||
debug << mult->factors;
|
||||
}
|
||||
}
|
||||
debug << ")";
|
||||
return debug;
|
||||
}
|
||||
|
|
|
@ -100,3 +100,5 @@ public:
|
|||
std::vector<ColorOp> ops;
|
||||
};
|
||||
}
|
||||
|
||||
KWIN_EXPORT QDebug operator<<(QDebug debug, const KWin::ColorPipeline &pipeline);
|
||||
|
|
|
@ -382,3 +382,9 @@ bool TransferFunction::isRelative() const
|
|||
Q_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const KWin::TransferFunction &tf)
|
||||
{
|
||||
debug << "TransferFunction(" << tf.type << ")";
|
||||
return debug;
|
||||
}
|
||||
|
|
|
@ -170,3 +170,5 @@ private:
|
|||
std::optional<double> m_maxHdrLuminance;
|
||||
};
|
||||
}
|
||||
|
||||
KWIN_EXPORT QDebug operator<<(QDebug debug, const KWin::TransferFunction &tf);
|
||||
|
|
Loading…
Reference in a new issue