From 4fe2b5d9b8dd43becf69cdf848ce7cdfca39b3bd Mon Sep 17 00:00:00 2001 From: aavit Date: Mon, 30 Aug 2010 14:46:47 +0200 Subject: Add reporting of difference score on mismatches --- tests/auto/lancelot/tst_lancelot.cpp | 72 ++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/tests/auto/lancelot/tst_lancelot.cpp b/tests/auto/lancelot/tst_lancelot.cpp index f1c6e5c..5e346ff 100644 --- a/tests/auto/lancelot/tst_lancelot.cpp +++ b/tests/auto/lancelot/tst_lancelot.cpp @@ -67,6 +67,7 @@ private: QImage getBaseline(const QString &fileName, bool *created); QImage render(const QString &fileName); QStringList loadScriptFile(const QString &filePath); + QString computeMismatchScore(const QImage& baseline, const QImage& rendered); QString errorMsg; BaselineProtocol proto; @@ -158,27 +159,68 @@ void tst_Lancelot::testRendering() // The actual check: if (rendered != baseline) { - QByteArray failMsg; - proto.submitMismatch(fileName, rendered, &failMsg); - -#if 1 - // Also generate & submit the diff image - QImage diff(rendered.size(), QImage::Format_RGB32); - diff.fill(0); - QPainter p(&diff); - p.drawImage(0, 0, rendered); - p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); - p.drawImage(0, 0, baseline); - p.end(); - proto.submitMismatch(fileName + QLatin1String("_diff"), diff, 0); -#endif + QString scoreMsg = computeMismatchScore(baseline, rendered); + QByteArray serverMsg; + proto.submitMismatch(fileName, rendered, &serverMsg); - failMsg.prepend("Rendered image differs from baseline. "); + QByteArray failMsg = QByteArray("Rendered image differs from baseline. ") + + scoreMsg.toLatin1() + '\n' + serverMsg; QFAIL(failMsg.constData()); } } +QString tst_Lancelot::computeMismatchScore(const QImage &baseline, const QImage &rendered) +{ + if (baseline.size() != rendered.size() || baseline.format() != rendered.format()) + return QLatin1String("[No score, incomparable images.]"); + if (baseline.depth() != 32) + return QLatin1String("[Score computation not implemented for format.]"); + + int w = baseline.width(); + int h = baseline.height(); + + uint ncd = 0; // number of differing color pixels + uint nad = 0; // number of differing alpha pixels + uint scd = 0; // sum of color pixel difference + uint sad = 0; // sum of alpha pixel difference + + for (int y=0; y