From 79293310e56a58efd40d0978e99635514d9d1f78 Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Tue, 19 Jun 2018 11:59:31 -0700 Subject: [PATCH] No more use of JPG files. --- tools/auto-tester/src/ImageComparer.cpp | 4 +-- tools/auto-tester/src/Test.cpp | 35 +++++-------------------- tools/auto-tester/src/Test.h | 4 +-- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/tools/auto-tester/src/ImageComparer.cpp b/tools/auto-tester/src/ImageComparer.cpp index 56da37f225..fa73f97887 100644 --- a/tools/auto-tester/src/ImageComparer.cpp +++ b/tools/auto-tester/src/ImageComparer.cpp @@ -15,10 +15,8 @@ // Computes SSIM - see https://en.wikipedia.org/wiki/Structural_similarity // The value is computed for the luminance component and the average value is returned double ImageComparer::compareImages(QImage resultImage, QImage expectedImage) const { - // Make sure the image is 8 bits per colour - QImage::Format format = expectedImage.format(); - const int L = 255; // (2^number of bits per pixel) - 1 + const double K1 { 0.01 }; const double K2 { 0.03 }; const double c1 = pow((K1 * L), 2); diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 7a61782f9e..88f4e58782 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -202,17 +202,6 @@ void Test::startTestsEvaluation(const QString& testFolder, const QString& branch return; } - // Before any processing - all images are converted to PNGs, as this is the format stored on GitHub - QStringList sortedSnapshotFilenames = createListOfAll_imagesInDirectory("jpg", snapshotDirectory); - foreach(QString filename, sortedSnapshotFilenames) { - QString filenameWithoutExtension = filename.left(filename.length() - 4); - copyJPGtoPNG(snapshotDirectory + "/" + filenameWithoutExtension + ".jpg", - snapshotDirectory + "/" + filenameWithoutExtension + ".png" - ); - - QFile::remove(snapshotDirectory + "/" + filenameWithoutExtension + ".jpg"); - } - // Create two lists. The first is the test results, the second is the expected images // The expected images are represented as a URL to enable download from GitHub // Images that are in the wrong format are ignored. @@ -513,13 +502,13 @@ void Test::createTests() { return; } - QStringList sortedImageFilenames = createListOfAll_imagesInDirectory("jpg", snapshotDirectory); + QStringList sortedImageFilenames = createListOfAll_imagesInDirectory("png", snapshotDirectory); int i = 1; const int maxImages = pow(10, NUM_DIGITS); foreach (QString currentFilename, sortedImageFilenames) { QString fullCurrentFilename = snapshotDirectory + "/" + currentFilename; - if (isInSnapshotFilenameFormat("jpg", currentFilename)) { + if (isInSnapshotFilenameFormat("png", currentFilename)) { if (i >= maxImages) { QMessageBox::critical(0, "Error", "More than " + QString::number(maxImages) + " images not supported"); exit(-1); @@ -543,9 +532,12 @@ void Test::createTests() { fullNewFileName += "/" + newFilename; try { - copyJPGtoPNG(fullCurrentFilename, fullNewFileName); + if (QFile::exists(fullNewFileName)) { + QFile::remove(fullNewFileName); + } + QFile::copy(fullCurrentFilename, fullNewFileName); } catch (...) { - QMessageBox::critical(0, "Error", "Could not delete existing file: " + currentFilename + "\nTest creation aborted"); + QMessageBox::critical(0, "Error", "Could not copy file: " + fullCurrentFilename + " to " + fullNewFileName + "\n"); exit(-1); } ++i; @@ -824,19 +816,6 @@ void Test::createTestsOutline() { QMessageBox::information(0, "Success", "Test outline file " + testsOutlineFilename + " has been created"); } -void Test::copyJPGtoPNG(const QString& sourceJPGFullFilename, const QString& destinationPNGFullFilename) { - QFile::remove(destinationPNGFullFilename); - - QImageReader reader; - reader.setFileName(sourceJPGFullFilename); - - QImage image = reader.read(); - - QImageWriter writer; - writer.setFileName(destinationPNGFullFilename); - writer.write(image); -} - QStringList Test::createListOfAll_imagesInDirectory(const QString& imageFormat, const QString& pathToImageDirectory) { imageDirectory = QDir(pathToImageDirectory); QStringList nameFilters; diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index b91a49ed95..94d868338d 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -69,14 +69,12 @@ public: QString getExpectedImageDestinationDirectory(const QString& filename); QString getExpectedImagePartialSourceDirectory(const QString& filename); - void copyJPGtoPNG(const QString& sourceJPGFullFilename, const QString& destinationPNGFullFilename); - private: const QString TEST_FILENAME { "test.js" }; const QString TEST_RESULTS_FOLDER { "TestResults" }; const QString TEST_RESULTS_FILENAME { "TestResults.txt" }; - const double THRESHOLD{ 0.999 }; + const double THRESHOLD{ 0.96 }; QDir imageDirectory;