autotests: add very basic color pipeline test

It just tests rec.709 <-> rec.2020 at 0%, 50% and 100% rec.709 luminance, to have
a very simple indicator for when something's gone really wrong while working on
color pipeline changes
This commit is contained in:
Xaver Hugl 2024-07-08 18:56:09 +02:00
parent bea4d1064c
commit 2cbf4543fa

View file

@ -24,6 +24,8 @@ private Q_SLOTS:
void nonNormalizedPrimaries();
void testIdentityTransformation_data();
void testIdentityTransformation();
void testColorPipeline_data();
void testColorPipeline();
};
static bool compareVectors(const QVector3D &one, const QVector3D &two, float maxDifference)
@ -115,6 +117,45 @@ void TestColorspaces::testIdentityTransformation()
QVERIFY(pipeline.isIdentity());
}
void TestColorspaces::testColorPipeline_data()
{
QTest::addColumn<ColorDescription>("srcColor");
QTest::addColumn<ColorDescription>("dstColor");
QTest::addColumn<QVector3D>("dstBlack");
QTest::addColumn<QVector3D>("dstGray");
QTest::addColumn<QVector3D>("dstWhite");
QTest::addRow("sRGB -> rec.2020") << ColorDescription(NamedColorimetry::BT709, TransferFunction::Type::gamma22, TransferFunction::defaultReferenceLuminanceFor(TransferFunction::Type::gamma22), 0, std::nullopt, std::nullopt)
<< ColorDescription(NamedColorimetry::BT2020, TransferFunction::Type::PerceptualQuantizer, 500, 0, std::nullopt, std::nullopt)
<< QVector3D(0.044, 0.044, 0.044)
<< QVector3D(0.517, 0.517, 0.517)
<< QVector3D(0.677, 0.677, 0.677);
QTest::addRow("sRGB -> scRGB") << ColorDescription(NamedColorimetry::BT709, TransferFunction::Type::gamma22, TransferFunction::defaultReferenceLuminanceFor(TransferFunction::Type::gamma22), 0, std::nullopt, std::nullopt)
<< ColorDescription(NamedColorimetry::BT709, TransferFunction(TransferFunction::Type::linear, 0, 80), 80, 0, std::nullopt, std::nullopt)
<< QVector3D(0.0001, 0.0001, 0.0001)
<< QVector3D(0.2177376408240310, 0.2177376408240310, 0.2177376408240310)
<< QVector3D(1, 1, 1);
}
void TestColorspaces::testColorPipeline()
{
QFETCH(ColorDescription, srcColor);
QFETCH(ColorDescription, dstColor);
QFETCH(QVector3D, dstBlack);
QFETCH(QVector3D, dstGray);
QFETCH(QVector3D, dstWhite);
const auto pipeline = ColorPipeline::create(srcColor, dstColor);
QVERIFY(compareVectors(pipeline.evaluate(QVector3D(0, 0, 0)), dstBlack, s_resolution10bit));
QVERIFY(compareVectors(pipeline.evaluate(QVector3D(0.5, 0.5, 0.5)), dstGray, s_resolution10bit));
QVERIFY(compareVectors(pipeline.evaluate(QVector3D(1, 1, 1)), dstWhite, s_resolution10bit));
const auto inversePipeline = ColorPipeline::create(dstColor, srcColor);
QVERIFY(compareVectors(inversePipeline.evaluate(dstBlack), QVector3D(0, 0, 0), s_resolution10bit));
QVERIFY(compareVectors(inversePipeline.evaluate(dstGray), QVector3D(0.5, 0.5, 0.5), s_resolution10bit));
QVERIFY(compareVectors(inversePipeline.evaluate(dstWhite), QVector3D(1, 1, 1), s_resolution10bit));
}
QTEST_MAIN(TestColorspaces)
#include "test_colorspaces.moc"