Commit dc61fb44 authored by ariya@webkit.org's avatar ariya@webkit.org

ChangeLog:

2009-07-29  Ariya Hidayat  <ariya.hidayat@nokia.com>

        Reviewed by Simon Hausmann.

        Adding ImageDiff project file.

        https://bugs.webkit.org/show_bug.cgi?id=27813

        * WebKit.pro: Added ImageDiff.pro.

WebKitTools/ChangeLog:

2009-07-29  Ariya Hidayat  <ariya.hidayat@nokia.com>

        Reviewed by Simon Hausmann.

        https://bugs.webkit.org/show_bug.cgi?id=27813

        [Qt] Implement ImageDiff.

        * DumpRenderTree/qt/ImageDiff.cpp: Added.
        * DumpRenderTree/qt/ImageDiff.pro: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@46577 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b0aacc79
2009-07-29 Ariya Hidayat <ariya.hidayat@nokia.com>
Reviewed by Simon Hausmann.
Adding ImageDiff project file.
https://bugs.webkit.org/show_bug.cgi?id=27813
* WebKit.pro: Added ImageDiff.pro.
2009-07-29 Jan Michael Alonzo <jmalonzo@webkit.org>
Reviewed by Eric Seidel and Xan Lopez.
......
......@@ -9,6 +9,7 @@ SUBDIRS += \
!win32:!symbian {
SUBDIRS += WebKitTools/DumpRenderTree/qt/DumpRenderTree.pro
SUBDIRS += WebKitTools/DumpRenderTree/qt/ImageDiff.pro
!mac: SUBDIRS += WebKitTools/DumpRenderTree/qt/TestNetscapePlugin/TestNetscapePlugin.pro
}
......
2009-07-29 Ariya Hidayat <ariya.hidayat@nokia.com>
Reviewed by Simon Hausmann.
https://bugs.webkit.org/show_bug.cgi?id=27813
[Qt] Implement ImageDiff.
* DumpRenderTree/qt/ImageDiff.cpp: Added.
* DumpRenderTree/qt/ImageDiff.pro: Added.
2009-07-30 Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
Reviewed by Eric Seidel.
......
/*
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <QApplication>
#include <QBuffer>
#include <QByteArray>
#include <QImage>
#include <QStringList>
#include <math.h>
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
qreal tolerance = 0;
QStringList args = app.arguments();
for (int i = 0; i < argc; ++i)
if (args[i] == "-t" || args[i] == "--tolerance")
tolerance = args[i + 1].toDouble();
char buffer[2048];
QImage actualImage;
QImage baselineImage;
while (fgets(buffer, sizeof(buffer), stdin)) {
// remove the CR
char* newLineCharacter = strchr(buffer, '\n');
if (newLineCharacter)
*newLineCharacter = '\0';
if (!strncmp("Content-Length: ", buffer, 16)) {
strtok(buffer, " ");
int imageSize = strtol(strtok(0, " "), 0, 10);
if (imageSize <= 0) {
fputs("error, image size must be specified.\n", stdout);
} else {
unsigned char buffer[2048];
QBuffer data;
// Read all the incoming chunks
data.open(QBuffer::WriteOnly);
while (imageSize > 0) {
size_t bytesToRead = qMin(imageSize, 2048);
size_t bytesRead = fread(buffer, 1, bytesToRead, stdin);
data.write(reinterpret_cast<const char*>(buffer), bytesRead);
imageSize -= static_cast<int>(bytesRead);
}
// Convert into QImage
QImage decodedImage;
decodedImage.loadFromData(data.data(), "PNG");
decodedImage.convertToFormat(QImage::Format_ARGB32);
// Place it in the right place
if (actualImage.isNull())
actualImage = decodedImage;
else
baselineImage = decodedImage;
}
}
if (!actualImage.isNull() && !baselineImage.isNull()) {
if (actualImage.size() != baselineImage.size()) {
fprintf(stderr, "error, test and reference image have different properties.\n");
fflush(stderr);
} else {
int w = actualImage.width();
int h = actualImage.height();
QImage diffImage(w, h, QImage::Format_ARGB32);
int count = 0;
qreal sum = 0;
qreal maxDistance = 0;
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);
qreal red = (qRed(pixel) - qRed(basePixel)) / static_cast<float>(qMax(255 - qRed(basePixel), qRed(basePixel)));
qreal green = (qGreen(pixel) - qGreen(basePixel)) / static_cast<float>(qMax(255 - qGreen(basePixel), qGreen(basePixel)));
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 = sqrt(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);
}
}
qreal difference = 0;
if (count)
difference = 100 * sum / static_cast<qreal>(w * h);
if (difference <= tolerance) {
difference = 0;
} else {
difference = round(difference * 100) / 100;
difference = qMax(difference, 0.01);
}
if (!count) {
fprintf(stdout, "diff: %01.2f%% passed\n", difference);
} else {
QBuffer buffer;
buffer.open(QBuffer::WriteOnly);
diffImage.save(&buffer, "PNG");
buffer.close();
const QByteArray &data = buffer.data();
printf("Content-Length: %lu\n", static_cast<unsigned long>(data.length()));
fwrite(data.constData(), 1, data.length(), stdout);
fprintf(stdout, "diff: %01.2f%% failed\n", difference);
}
fflush(stdout);
}
}
}
return 0;
}
TARGET = ImageDiff
CONFIG -= app_bundle
include(../../../WebKit.pri)
INCLUDEPATH += ../../../JavaScriptCore
DESTDIR = ../../../bin
QT = core gui
SOURCES = ImageDiff.cpp
unix:!mac {
QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR
}
lessThan(QT_MINOR_VERSION, 4) {
DEFINES += QT_BEGIN_NAMESPACE="" QT_END_NAMESPACE=""
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment