Title: [146206] trunk/Tools
Revision
146206
Author
allan.jen...@digia.com
Date
2013-03-19 08:39:46 -0700 (Tue, 19 Mar 2013)

Log Message

[Qt] Make ImageDiff similar to Chromium's ImageDiff
https://bugs.webkit.org/show_bug.cgi?id=94782

Based on patch by Csaba Osztrogonác.
Reviewed by Jocelyn Turcotte.

The diff image is generated with bright red indicating errors, but letting the base image
shine through so the context of the error-pixel can be identified.

* DumpRenderTree/qt/ImageDiff.cpp:
(main):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (146205 => 146206)


--- trunk/Tools/ChangeLog	2013-03-19 15:18:47 UTC (rev 146205)
+++ trunk/Tools/ChangeLog	2013-03-19 15:39:46 UTC (rev 146206)
@@ -1,3 +1,17 @@
+2013-03-19  Allan Sandfeld Jensen  <allan.jen...@digia.com>
+
+        [Qt] Make ImageDiff similar to Chromium's ImageDiff
+        https://bugs.webkit.org/show_bug.cgi?id=94782
+
+        Based on patch by Csaba Osztrogonác.
+        Reviewed by Jocelyn Turcotte.
+
+        The diff image is generated with bright red indicating errors, but letting the base image
+        shine through so the context of the error-pixel can be identified.
+
+        * DumpRenderTree/qt/ImageDiff.cpp:
+        (main):
+
 2013-03-18  Andras Becsi  <andras.be...@digia.com>
 
         [Qt] Fix the build of QtTestBrowser if the print preview dialog is disabled in Qt

Modified: trunk/Tools/ImageDiff/qt/ImageDiff.cpp (146205 => 146206)


--- trunk/Tools/ImageDiff/qt/ImageDiff.cpp	2013-03-19 15:18:47 UTC (rev 146205)
+++ trunk/Tools/ImageDiff/qt/ImageDiff.cpp	2013-03-19 15:39:46 UTC (rev 146206)
@@ -31,7 +31,7 @@
 {
     QCoreApplication app(argc, argv);
 
-    qreal tolerance = 0;
+    qreal tolerance = 0; // Tolerated percentage of error pixels.
 
     QStringList args = app.arguments();
     for (int i = 0; i < argc; ++i)
@@ -93,11 +93,9 @@
                 int h = actualImage.height();
                 QImage diffImage(w, h, QImage::Format_ARGB32);
 
-                int count = 0;
-                qreal sum = 0;
-                qreal maxDistance = 0;
+                int errorCount = 0;
 
-                for (int x = 0; x < w; ++x)
+                for (int x = 0; x < w; ++x) {
                     for (int y = 0; y < h; ++y) {
                         QRgb pixel = actualImage.pixel(x, y);
                         QRgb basePixel = baselineImage.pixel(x, y);
@@ -106,26 +104,19 @@
                         qreal blue = (qBlue(pixel) - qBlue(basePixel)) / static_cast<float>(qMax(255 - qBlue(basePixel), qBlue(basePixel)));
                         qreal alpha = (qAlpha(pixel) - qAlpha(basePixel)) / static_cast<float>(qMax(255 - qAlpha(basePixel), qAlpha(basePixel)));
                         qreal distance = qSqrt(red * red + green * green + blue * blue + alpha * alpha) / 2.0f;
-                        int gray = distance * qreal(255);
-                        diffImage.setPixel(x, y, qRgb(gray, gray, gray));
                         if (distance >= 1 / qreal(255)) {
-                            count++;
-                            sum += distance;
-                            maxDistance = qMax(maxDistance, distance);
-                        }
+                            errorCount++;
+                            diffImage.setPixel(x, y, qRgb(255, 0, 0));
+                        } else
+                            diffImage.setPixel(x, y, qRgba(qRed(basePixel), qGreen(basePixel), qBlue(basePixel), qAlpha(basePixel) * 0.5));
+                    }
                 }
 
                 qreal difference = 0;
-                if (count)
-                    difference = 100 * sum / static_cast<qreal>(w * h);
-                if (difference <= tolerance) {
-                    difference = 0;
-                } else {
-                    difference = qRound(difference * 100) / 100.0f;
-                    difference = qMax(difference, qreal(0.01));
-                }
+                if (errorCount)
+                    difference = 100 * errorCount / static_cast<qreal>(w * h);
 
-                if (!difference)
+                if (difference <= tolerance)
                     fprintf(stdout, "diff: %01.2f%% passed\n", difference);
                 else {
                     QBuffer buffer;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to