No more use of JPG files.

This commit is contained in:
NissimHadar 2018-06-19 11:59:31 -07:00
parent d55d3c54da
commit 79293310e5
3 changed files with 9 additions and 34 deletions

View file

@ -15,10 +15,8 @@
// Computes SSIM - see https://en.wikipedia.org/wiki/Structural_similarity // Computes SSIM - see https://en.wikipedia.org/wiki/Structural_similarity
// The value is computed for the luminance component and the average value is returned // The value is computed for the luminance component and the average value is returned
double ImageComparer::compareImages(QImage resultImage, QImage expectedImage) const { 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 int L = 255; // (2^number of bits per pixel) - 1
const double K1 { 0.01 }; const double K1 { 0.01 };
const double K2 { 0.03 }; const double K2 { 0.03 };
const double c1 = pow((K1 * L), 2); const double c1 = pow((K1 * L), 2);

View file

@ -202,17 +202,6 @@ void Test::startTestsEvaluation(const QString& testFolder, const QString& branch
return; 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 // 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 // The expected images are represented as a URL to enable download from GitHub
// Images that are in the wrong format are ignored. // Images that are in the wrong format are ignored.
@ -513,13 +502,13 @@ void Test::createTests() {
return; return;
} }
QStringList sortedImageFilenames = createListOfAll_imagesInDirectory("jpg", snapshotDirectory); QStringList sortedImageFilenames = createListOfAll_imagesInDirectory("png", snapshotDirectory);
int i = 1; int i = 1;
const int maxImages = pow(10, NUM_DIGITS); const int maxImages = pow(10, NUM_DIGITS);
foreach (QString currentFilename, sortedImageFilenames) { foreach (QString currentFilename, sortedImageFilenames) {
QString fullCurrentFilename = snapshotDirectory + "/" + currentFilename; QString fullCurrentFilename = snapshotDirectory + "/" + currentFilename;
if (isInSnapshotFilenameFormat("jpg", currentFilename)) { if (isInSnapshotFilenameFormat("png", currentFilename)) {
if (i >= maxImages) { if (i >= maxImages) {
QMessageBox::critical(0, "Error", "More than " + QString::number(maxImages) + " images not supported"); QMessageBox::critical(0, "Error", "More than " + QString::number(maxImages) + " images not supported");
exit(-1); exit(-1);
@ -543,9 +532,12 @@ void Test::createTests() {
fullNewFileName += "/" + newFilename; fullNewFileName += "/" + newFilename;
try { try {
copyJPGtoPNG(fullCurrentFilename, fullNewFileName); if (QFile::exists(fullNewFileName)) {
QFile::remove(fullNewFileName);
}
QFile::copy(fullCurrentFilename, fullNewFileName);
} catch (...) { } 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); exit(-1);
} }
++i; ++i;
@ -824,19 +816,6 @@ void Test::createTestsOutline() {
QMessageBox::information(0, "Success", "Test outline file " + testsOutlineFilename + " has been created"); 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) { QStringList Test::createListOfAll_imagesInDirectory(const QString& imageFormat, const QString& pathToImageDirectory) {
imageDirectory = QDir(pathToImageDirectory); imageDirectory = QDir(pathToImageDirectory);
QStringList nameFilters; QStringList nameFilters;

View file

@ -69,14 +69,12 @@ public:
QString getExpectedImageDestinationDirectory(const QString& filename); QString getExpectedImageDestinationDirectory(const QString& filename);
QString getExpectedImagePartialSourceDirectory(const QString& filename); QString getExpectedImagePartialSourceDirectory(const QString& filename);
void copyJPGtoPNG(const QString& sourceJPGFullFilename, const QString& destinationPNGFullFilename);
private: private:
const QString TEST_FILENAME { "test.js" }; const QString TEST_FILENAME { "test.js" };
const QString TEST_RESULTS_FOLDER { "TestResults" }; const QString TEST_RESULTS_FOLDER { "TestResults" };
const QString TEST_RESULTS_FILENAME { "TestResults.txt" }; const QString TEST_RESULTS_FILENAME { "TestResults.txt" };
const double THRESHOLD{ 0.999 }; const double THRESHOLD{ 0.96 };
QDir imageDirectory; QDir imageDirectory;