[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [gwenview/KDE/4.14] tests/auto: Improve fuzzyImageCompare
From: Aurélien Gâteau <agateau () kde ! org>
Date: 2014-07-18 8:27:31
Message-ID: E1X83Vr-0002wm-V6 () scm ! kde ! org
[Download RAW message or body]
Git commit 3c2fd7fbf6a75f0af51ee3467894a4461bee42c1 by Aurélien Gâteau.
Committed on 18/07/2014 at 08:21.
Pushed by gateau into branch 'KDE/4.14'.
Improve fuzzyImageCompare
Fuzziness is a param, delta is done per color component,
cope with image format variants.
M +52 -0 tests/auto/testutils.cpp
M +10 -22 tests/auto/testutils.h
http://commits.kde.org/gwenview/3c2fd7fbf6a75f0af51ee3467894a4461bee42c1
diff --git a/tests/auto/testutils.cpp b/tests/auto/testutils.cpp
index 583946b..9f5ed6c 100644
--- a/tests/auto/testutils.cpp
+++ b/tests/auto/testutils.cpp
@@ -104,6 +104,58 @@ void purgeUserConfiguration()
kClearDebugConfig();
}
+static QImage simplifyFormats(const QImage& img)
+{
+ switch (img.format()) {
+ case QImage::Format_RGB32:
+ case QImage::Format_ARGB32_Premultiplied:
+ return img.convertToFormat(QImage::Format_ARGB32);
+ default:
+ return img;
+ }
+}
+
+inline bool fuzzyColorComponentCompare(int c1, int c2, int delta)
+{
+ return qAbs(c1 - c2) < delta;
+}
+
+bool fuzzyImageCompare(const QImage& img1_, const QImage& img2_, int delta)
+{
+ if (img1_.size() != img2_.size()) {
+ kWarning() << "Different sizes" << img1_.size() << "!=" << img2_.size();
+ return false;
+ }
+ QImage img1 = simplifyFormats(img1_);
+ QImage img2 = simplifyFormats(img2_);
+ if (img1.format() != img2.format()) {
+ kWarning() << "Different formats" << img1.format() << "!=" << img2.format();
+ return false;
+ }
+
+ for (int posY = 0; posY < img1.height(); ++posY) {
+ for (int posX = 0; posX < img2.width(); ++posX) {
+ QColor col1 = img1.pixel(posX, posY);
+ QColor col2 = img2.pixel(posX, posY);
+ bool ok =
+ fuzzyColorComponentCompare(col1.red(), col2.red(), delta)
+ && fuzzyColorComponentCompare(col1.green(), col2.green(), delta)
+ && fuzzyColorComponentCompare(col1.blue(), col2.blue(), delta)
+ && fuzzyColorComponentCompare(col1.alpha(), col2.alpha(), delta);
+ if (!ok) {
+ kWarning() << "Different at" << QPoint(posX, posY) << col1.name() << \
"!=" << col2.name(); + return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool imageCompare(const QImage& img1, const QImage& img2)
+{
+ return fuzzyImageCompare(img1, img2, 1);
+}
+
SandBoxDir::SandBoxDir()
: mTempDir(QDir::currentPath() + "/sandbox-")
{
diff --git a/tests/auto/testutils.h b/tests/auto/testutils.h
index 71861c5..7b4cf64 100644
--- a/tests/auto/testutils.h
+++ b/tests/auto/testutils.h
@@ -72,28 +72,6 @@ inline bool waitForSignal(const QSignalSpy& spy, int timeout = 5)
return false;
}
-inline bool fuzzyImageCompare(const QImage& img1, const QImage& img2)
-{
- if (img1.size() != img2.size()) {
- kWarning() << "Different sizes" << img1.size() << img2.size();
- return false;
- }
- if (img1.format() != img2.format()) {
- kWarning() << "Different formats" << img1.format() << img2.format();
- return false;
- }
-
- for (int posY = 0; posY < img1.height(); ++posY) {
- for (int posX = 0; posX < img2.width(); ++posX) {
- if (qAbs(img1.pixel(posX, posY) - img2.pixel(posX, posY)) > 2) {
- kWarning() << "Different at" << QPoint(posX, posY);
- return false;
- }
- }
- }
- return true;
-}
-
void createEmptyFile(const QString& path);
/**
@@ -113,6 +91,10 @@ void waitForDeferredDeletes();
namespace TestUtils
{
+bool fuzzyImageCompare(const QImage& img1, const QImage& img2, int delta = 2);
+
+bool imageCompare(const QImage& img1, const QImage& img2);
+
void purgeUserConfiguration();
class SandBoxDir : public QDir
@@ -145,4 +127,10 @@ private:
} // namespace
+inline bool fuzzyImageCompare(const QImage& img1, const QImage& img2)
+{
+ return TestUtils::fuzzyImageCompare(img1, img2);
+}
+
+
#endif /* TESTUTILS_H */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic