2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkImageEncoder.h"
|
|
|
|
#include "include/core/SkPixelRef.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
2019-05-15 13:28:52 +00:00
|
|
|
#include "src/core/SkTSearch.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkOSPath.h"
|
|
|
|
#include "tools/skdiff/skdiff.h"
|
|
|
|
#include "tools/skdiff/skdiff_html.h"
|
|
|
|
#include "tools/skdiff/skdiff_utils.h"
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2015-08-26 12:15:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-04-27 15:39:30 +00:00
|
|
|
/**
|
|
|
|
* skdiff
|
|
|
|
*
|
|
|
|
* Given three directory names, expects to find identically-named files in
|
|
|
|
* each of the first two; the first are treated as a set of baseline,
|
|
|
|
* the second a set of variant images, and a diff image is written into the
|
|
|
|
* third directory for each pair.
|
2011-07-14 13:15:55 +00:00
|
|
|
* Creates an index.html in the current third directory to compare each
|
2011-04-27 15:39:30 +00:00
|
|
|
* pair that does not match exactly.
|
2012-08-16 13:42:13 +00:00
|
|
|
* Recursively descends directories, unless run with --norecurse.
|
2012-05-31 15:13:45 +00:00
|
|
|
*
|
|
|
|
* Returns zero exit code if all images match across baseDir and comparisonDir.
|
2011-04-27 15:39:30 +00:00
|
|
|
*/
|
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
typedef SkTArray<SkString> StringArray;
|
2012-05-01 13:26:16 +00:00
|
|
|
typedef StringArray FileArray;
|
2012-03-22 18:20:06 +00:00
|
|
|
|
2015-01-06 15:39:55 +00:00
|
|
|
static void add_unique_basename(StringArray* array, const SkString& filename) {
|
|
|
|
// trim off dirs
|
|
|
|
const char* src = filename.c_str();
|
2016-11-07 23:05:29 +00:00
|
|
|
const char* trimmed = strrchr(src, SkOSPath::SEPARATOR);
|
2015-01-06 15:39:55 +00:00
|
|
|
if (trimmed) {
|
|
|
|
trimmed += 1; // skip the separator
|
|
|
|
} else {
|
|
|
|
trimmed = src;
|
|
|
|
}
|
|
|
|
const char* end = strrchr(trimmed, '.');
|
|
|
|
if (!end) {
|
|
|
|
end = trimmed + strlen(trimmed);
|
|
|
|
}
|
|
|
|
SkString result(trimmed, end - trimmed);
|
|
|
|
|
|
|
|
// only add unique entries
|
|
|
|
for (int i = 0; i < array->count(); ++i) {
|
2021-08-06 20:33:55 +00:00
|
|
|
if (array->at(i) == result) {
|
2015-01-06 15:39:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-08-06 20:33:55 +00:00
|
|
|
array->push_back(std::move(result));
|
2015-01-06 15:39:55 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 15:47:10 +00:00
|
|
|
struct DiffSummary {
|
|
|
|
DiffSummary ()
|
2012-12-05 20:13:12 +00:00
|
|
|
: fNumMatches(0)
|
|
|
|
, fNumMismatches(0)
|
|
|
|
, fMaxMismatchV(0)
|
2016-10-13 21:36:40 +00:00
|
|
|
, fMaxMismatchPercent(0) { }
|
2011-06-09 15:47:10 +00:00
|
|
|
|
|
|
|
uint32_t fNumMatches;
|
|
|
|
uint32_t fNumMismatches;
|
|
|
|
uint32_t fMaxMismatchV;
|
|
|
|
float fMaxMismatchPercent;
|
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
FileArray fResultsOfType[DiffRecord::kResultCount];
|
|
|
|
FileArray fStatusOfType[DiffResource::kStatusCount][DiffResource::kStatusCount];
|
|
|
|
|
2015-01-06 15:39:55 +00:00
|
|
|
StringArray fFailedBaseNames[DiffRecord::kResultCount];
|
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
void printContents(const FileArray& fileArray,
|
|
|
|
const char* baseStatus, const char* comparisonStatus,
|
|
|
|
bool listFilenames) {
|
|
|
|
int n = fileArray.count();
|
|
|
|
printf("%d file pairs %s in baseDir and %s in comparisonDir",
|
|
|
|
n, baseStatus, comparisonStatus);
|
|
|
|
if (listFilenames) {
|
|
|
|
printf(": ");
|
|
|
|
for (int i = 0; i < n; ++i) {
|
2021-08-06 20:33:55 +00:00
|
|
|
printf("%s ", fileArray[i].c_str());
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void printStatus(bool listFilenames,
|
|
|
|
bool failOnStatusType[DiffResource::kStatusCount]
|
|
|
|
[DiffResource::kStatusCount]) {
|
|
|
|
typedef DiffResource::Status Status;
|
|
|
|
|
|
|
|
for (int base = 0; base < DiffResource::kStatusCount; ++base) {
|
|
|
|
Status baseStatus = static_cast<Status>(base);
|
|
|
|
for (int comparison = 0; comparison < DiffResource::kStatusCount; ++comparison) {
|
|
|
|
Status comparisonStatus = static_cast<Status>(comparison);
|
|
|
|
const FileArray& fileArray = fStatusOfType[base][comparison];
|
|
|
|
if (fileArray.count() > 0) {
|
|
|
|
if (failOnStatusType[base][comparison]) {
|
|
|
|
printf(" [*] ");
|
|
|
|
} else {
|
|
|
|
printf(" [_] ");
|
|
|
|
}
|
|
|
|
printContents(fileArray,
|
|
|
|
DiffResource::getStatusDescription(baseStatus),
|
|
|
|
DiffResource::getStatusDescription(comparisonStatus),
|
|
|
|
listFilenames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-22 18:20:06 +00:00
|
|
|
|
2012-07-19 17:35:04 +00:00
|
|
|
// Print a line about the contents of this FileArray to stdout.
|
2012-07-12 18:16:02 +00:00
|
|
|
void printContents(const FileArray& fileArray, const char* headerText, bool listFilenames) {
|
2012-05-31 15:12:09 +00:00
|
|
|
int n = fileArray.count();
|
2012-07-19 17:35:04 +00:00
|
|
|
printf("%d file pairs %s", n, headerText);
|
|
|
|
if (listFilenames) {
|
|
|
|
printf(": ");
|
|
|
|
for (int i = 0; i < n; ++i) {
|
2021-08-06 20:33:55 +00:00
|
|
|
printf("%s ", fileArray[i].c_str());
|
2012-03-22 18:20:06 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-19 17:35:04 +00:00
|
|
|
printf("\n");
|
2012-05-31 15:12:09 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
void print(bool listFilenames, bool failOnResultType[DiffRecord::kResultCount],
|
|
|
|
bool failOnStatusType[DiffResource::kStatusCount]
|
|
|
|
[DiffResource::kStatusCount]) {
|
2012-07-19 17:35:04 +00:00
|
|
|
printf("\ncompared %d file pairs:\n", fNumMatches + fNumMismatches);
|
2012-12-05 20:13:12 +00:00
|
|
|
for (int resultInt = 0; resultInt < DiffRecord::kResultCount; ++resultInt) {
|
|
|
|
DiffRecord::Result result = static_cast<DiffRecord::Result>(resultInt);
|
2012-07-19 17:35:04 +00:00
|
|
|
if (failOnResultType[result]) {
|
|
|
|
printf("[*] ");
|
|
|
|
} else {
|
|
|
|
printf("[_] ");
|
|
|
|
}
|
2012-12-05 20:13:12 +00:00
|
|
|
printContents(fResultsOfType[result], DiffRecord::getResultDescription(result),
|
|
|
|
listFilenames);
|
|
|
|
if (DiffRecord::kCouldNotCompare_Result == result) {
|
|
|
|
printStatus(listFilenames, failOnStatusType);
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
}
|
2012-07-19 17:35:04 +00:00
|
|
|
printf("(results marked with [*] will cause nonzero return value)\n");
|
|
|
|
printf("\nnumber of mismatching file pairs: %d\n", fNumMismatches);
|
2011-06-09 15:47:10 +00:00
|
|
|
if (fNumMismatches > 0) {
|
|
|
|
printf("Maximum pixel intensity mismatch %d\n", fMaxMismatchV);
|
2012-07-12 18:16:02 +00:00
|
|
|
printf("Largest area mismatch was %.2f%% of pixels\n",fMaxMismatchPercent);
|
2011-06-09 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 15:39:55 +00:00
|
|
|
void printfFailingBaseNames(const char separator[]) {
|
|
|
|
for (int resultInt = 0; resultInt < DiffRecord::kResultCount; ++resultInt) {
|
|
|
|
const StringArray& array = fFailedBaseNames[resultInt];
|
|
|
|
if (array.count()) {
|
|
|
|
printf("%s [%d]%s", DiffRecord::ResultNames[resultInt], array.count(), separator);
|
|
|
|
for (int j = 0; j < array.count(); ++j) {
|
2021-08-06 20:33:55 +00:00
|
|
|
printf("%s%s", array[j].c_str(), separator);
|
2015-01-06 15:39:55 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
void add (const DiffRecord& drp) {
|
2012-05-22 13:45:35 +00:00
|
|
|
uint32_t mismatchValue;
|
2012-05-16 14:57:28 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
if (drp.fBase.fFilename.equals(drp.fComparison.fFilename)) {
|
|
|
|
fResultsOfType[drp.fResult].push_back(drp.fBase.fFilename);
|
2012-12-05 20:13:12 +00:00
|
|
|
} else {
|
2021-08-06 20:33:55 +00:00
|
|
|
SkString blame("(");
|
|
|
|
blame.append(drp.fBase.fFilename);
|
|
|
|
blame.append(", ");
|
|
|
|
blame.append(drp.fComparison.fFilename);
|
|
|
|
blame.append(")");
|
|
|
|
fResultsOfType[drp.fResult].push_back(std::move(blame));
|
|
|
|
}
|
|
|
|
switch (drp.fResult) {
|
2012-12-05 20:13:12 +00:00
|
|
|
case DiffRecord::kEqualBits_Result:
|
2012-05-16 14:57:28 +00:00
|
|
|
fNumMatches++;
|
|
|
|
break;
|
2012-12-05 20:13:12 +00:00
|
|
|
case DiffRecord::kEqualPixels_Result:
|
2012-05-22 13:45:35 +00:00
|
|
|
fNumMatches++;
|
2012-05-16 14:57:28 +00:00
|
|
|
break;
|
2012-12-05 20:13:12 +00:00
|
|
|
case DiffRecord::kDifferentSizes_Result:
|
2012-03-22 18:20:06 +00:00
|
|
|
fNumMismatches++;
|
2012-05-16 14:57:28 +00:00
|
|
|
break;
|
2012-12-05 20:13:12 +00:00
|
|
|
case DiffRecord::kDifferentPixels_Result:
|
2011-06-09 15:47:10 +00:00
|
|
|
fNumMismatches++;
|
2021-08-06 20:33:55 +00:00
|
|
|
if (drp.fFractionDifference * 100 > fMaxMismatchPercent) {
|
|
|
|
fMaxMismatchPercent = drp.fFractionDifference * 100;
|
2011-06-09 15:47:10 +00:00
|
|
|
}
|
2021-08-06 20:33:55 +00:00
|
|
|
mismatchValue = MAX3(drp.fMaxMismatchR, drp.fMaxMismatchG,
|
|
|
|
drp.fMaxMismatchB);
|
2012-05-22 13:45:35 +00:00
|
|
|
if (mismatchValue > fMaxMismatchV) {
|
|
|
|
fMaxMismatchV = mismatchValue;
|
2011-06-09 15:47:10 +00:00
|
|
|
}
|
2012-05-16 14:57:28 +00:00
|
|
|
break;
|
2012-12-05 20:13:12 +00:00
|
|
|
case DiffRecord::kCouldNotCompare_Result:
|
2012-05-22 13:45:35 +00:00
|
|
|
fNumMismatches++;
|
2021-08-06 20:33:55 +00:00
|
|
|
fStatusOfType[drp.fBase.fStatus][drp.fComparison.fStatus].push_back(
|
|
|
|
drp.fBase.fFilename);
|
2012-05-22 13:45:35 +00:00
|
|
|
break;
|
2012-12-05 20:13:12 +00:00
|
|
|
case DiffRecord::kUnknown_Result:
|
2012-05-22 13:45:35 +00:00
|
|
|
SkDEBUGFAIL("adding uncategorized DiffRecord");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("adding DiffRecord with unhandled fResult value");
|
|
|
|
break;
|
2011-06-09 15:47:10 +00:00
|
|
|
}
|
2015-01-06 15:39:55 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
switch (drp.fResult) {
|
2015-01-06 15:39:55 +00:00
|
|
|
case DiffRecord::kEqualBits_Result:
|
|
|
|
case DiffRecord::kEqualPixels_Result:
|
|
|
|
break;
|
|
|
|
default:
|
2021-08-06 20:33:55 +00:00
|
|
|
add_unique_basename(&fFailedBaseNames[drp.fResult], drp.fBase.fFilename);
|
2015-01-06 15:39:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-06-09 15:47:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
/// Returns true if string contains any of these substrings.
|
|
|
|
static bool string_contains_any_of(const SkString& string,
|
|
|
|
const StringArray& substrings) {
|
|
|
|
for (int i = 0; i < substrings.count(); i++) {
|
2021-08-06 20:33:55 +00:00
|
|
|
if (string.contains(substrings[i].c_str())) {
|
2012-05-01 13:26:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-16 13:42:13 +00:00
|
|
|
/// Internal (potentially recursive) implementation of get_file_list.
|
|
|
|
static void get_file_list_subdir(const SkString& rootDir, const SkString& subDir,
|
|
|
|
const StringArray& matchSubstrings,
|
|
|
|
const StringArray& nomatchSubstrings,
|
|
|
|
bool recurseIntoSubdirs, FileArray *files) {
|
|
|
|
bool isSubDirEmpty = subDir.isEmpty();
|
|
|
|
SkString dir(rootDir);
|
|
|
|
if (!isSubDirEmpty) {
|
|
|
|
dir.append(PATH_DIV_STR);
|
|
|
|
dir.append(subDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over files (not directories) within dir.
|
|
|
|
SkOSFile::Iter fileIterator(dir.c_str());
|
|
|
|
SkString fileName;
|
|
|
|
while (fileIterator.next(&fileName, false)) {
|
|
|
|
if (fileName.startsWith(".")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkString pathRelativeToRootDir(subDir);
|
|
|
|
if (!isSubDirEmpty) {
|
|
|
|
pathRelativeToRootDir.append(PATH_DIV_STR);
|
|
|
|
}
|
|
|
|
pathRelativeToRootDir.append(fileName);
|
|
|
|
if (string_contains_any_of(pathRelativeToRootDir, matchSubstrings) &&
|
|
|
|
!string_contains_any_of(pathRelativeToRootDir, nomatchSubstrings)) {
|
2021-08-06 20:33:55 +00:00
|
|
|
files->push_back(std::move(pathRelativeToRootDir));
|
2012-08-16 13:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recurse into any non-ignored subdirectories.
|
|
|
|
if (recurseIntoSubdirs) {
|
|
|
|
SkOSFile::Iter dirIterator(dir.c_str());
|
|
|
|
SkString dirName;
|
|
|
|
while (dirIterator.next(&dirName, true)) {
|
|
|
|
if (dirName.startsWith(".")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkString pathRelativeToRootDir(subDir);
|
|
|
|
if (!isSubDirEmpty) {
|
|
|
|
pathRelativeToRootDir.append(PATH_DIV_STR);
|
|
|
|
}
|
|
|
|
pathRelativeToRootDir.append(dirName);
|
|
|
|
if (!string_contains_any_of(pathRelativeToRootDir, nomatchSubstrings)) {
|
|
|
|
get_file_list_subdir(rootDir, pathRelativeToRootDir,
|
|
|
|
matchSubstrings, nomatchSubstrings, recurseIntoSubdirs,
|
|
|
|
files);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Iterate over dir and get all files whose filename:
|
|
|
|
/// - matches any of the substrings in matchSubstrings, but...
|
|
|
|
/// - DOES NOT match any of the substrings in nomatchSubstrings
|
|
|
|
/// - DOES NOT start with a dot (.)
|
|
|
|
/// Adds the matching files to the list in *files.
|
2012-05-01 13:26:16 +00:00
|
|
|
static void get_file_list(const SkString& dir,
|
|
|
|
const StringArray& matchSubstrings,
|
|
|
|
const StringArray& nomatchSubstrings,
|
2012-08-16 13:42:13 +00:00
|
|
|
bool recurseIntoSubdirs, FileArray *files) {
|
|
|
|
get_file_list_subdir(dir, SkString(""),
|
|
|
|
matchSubstrings, nomatchSubstrings, recurseIntoSubdirs,
|
|
|
|
files);
|
2012-03-22 18:20:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 00:13:51 +00:00
|
|
|
/// Comparison routines for qsort, sort by file names.
|
2021-08-06 20:33:55 +00:00
|
|
|
static int compare_file_name_metrics(SkString *lhs, SkString *rhs) {
|
|
|
|
return strcmp(lhs->c_str(), rhs->c_str());
|
2012-03-22 18:20:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
class AutoReleasePixels {
|
|
|
|
public:
|
|
|
|
AutoReleasePixels(DiffRecord* drp)
|
|
|
|
: fDrp(drp) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(drp != nullptr);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
|
|
|
~AutoReleasePixels() {
|
2016-12-12 18:48:12 +00:00
|
|
|
fDrp->fBase.fBitmap.setPixelRef(nullptr, 0, 0);
|
|
|
|
fDrp->fComparison.fBitmap.setPixelRef(nullptr, 0, 0);
|
|
|
|
fDrp->fDifference.fBitmap.setPixelRef(nullptr, 0, 0);
|
|
|
|
fDrp->fWhite.fBitmap.setPixelRef(nullptr, 0, 0);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DiffRecord* fDrp;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void get_bounds(DiffResource& resource, const char* name) {
|
|
|
|
if (resource.fBitmap.empty() && !DiffResource::isStatusFailed(resource.fStatus)) {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> fileBits(read_file(resource.fFullPath.c_str()));
|
|
|
|
if (fileBits) {
|
2018-07-17 20:45:40 +00:00
|
|
|
get_bitmap(fileBits, resource, true, true);
|
2016-08-02 21:40:46 +00:00
|
|
|
} else {
|
2012-12-05 20:13:12 +00:00
|
|
|
SkDebugf("WARNING: couldn't read %s file <%s>\n", name, resource.fFullPath.c_str());
|
|
|
|
resource.fStatus = DiffResource::kCouldNotRead_Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_bounds(DiffRecord& drp) {
|
|
|
|
get_bounds(drp.fBase, "base");
|
|
|
|
get_bounds(drp.fComparison, "comparison");
|
|
|
|
}
|
|
|
|
|
2014-05-28 18:26:00 +00:00
|
|
|
#ifdef SK_OS_WIN
|
|
|
|
#define ANSI_COLOR_RED ""
|
|
|
|
#define ANSI_COLOR_GREEN ""
|
|
|
|
#define ANSI_COLOR_YELLOW ""
|
|
|
|
#define ANSI_COLOR_RESET ""
|
|
|
|
#else
|
|
|
|
#define ANSI_COLOR_RED "\x1b[31m"
|
|
|
|
#define ANSI_COLOR_GREEN "\x1b[32m"
|
|
|
|
#define ANSI_COLOR_YELLOW "\x1b[33m"
|
|
|
|
#define ANSI_COLOR_RESET "\x1b[0m"
|
|
|
|
#endif
|
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
#define VERBOSE_STATUS(status,color,filename) if (verbose) printf( "[ " color " %10s " ANSI_COLOR_RESET " ] %s\n", status, filename.c_str())
|
2014-05-28 18:26:00 +00:00
|
|
|
|
2011-04-27 15:39:30 +00:00
|
|
|
/// Creates difference images, returns the number that have a 0 metric.
|
2012-05-01 13:26:16 +00:00
|
|
|
/// If outputDir.isEmpty(), don't write out diff files.
|
2011-06-09 15:47:10 +00:00
|
|
|
static void create_diff_images (DiffMetricProc dmp,
|
|
|
|
const int colorThreshold,
|
2018-07-17 20:45:40 +00:00
|
|
|
bool ignoreColorSpace,
|
2011-06-09 15:47:10 +00:00
|
|
|
RecordArray* differences,
|
|
|
|
const SkString& baseDir,
|
|
|
|
const SkString& comparisonDir,
|
|
|
|
const SkString& outputDir,
|
2012-05-01 13:26:16 +00:00
|
|
|
const StringArray& matchSubstrings,
|
|
|
|
const StringArray& nomatchSubstrings,
|
2012-08-16 13:42:13 +00:00
|
|
|
bool recurseIntoSubdirs,
|
2012-12-05 20:13:12 +00:00
|
|
|
bool getBounds,
|
2014-05-28 18:26:00 +00:00
|
|
|
bool verbose,
|
2011-06-09 15:47:10 +00:00
|
|
|
DiffSummary* summary) {
|
2012-05-01 13:26:16 +00:00
|
|
|
SkASSERT(!baseDir.isEmpty());
|
|
|
|
SkASSERT(!comparisonDir.isEmpty());
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
FileArray baseFiles;
|
|
|
|
FileArray comparisonFiles;
|
|
|
|
|
2012-08-16 13:42:13 +00:00
|
|
|
get_file_list(baseDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, &baseFiles);
|
|
|
|
get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, recurseIntoSubdirs,
|
2012-05-01 13:26:16 +00:00
|
|
|
&comparisonFiles);
|
2012-03-22 18:20:06 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
if (!baseFiles.empty()) {
|
|
|
|
qsort(baseFiles.begin(), baseFiles.count(), sizeof(SkString),
|
2020-07-14 00:13:51 +00:00
|
|
|
SkCastForQSort(compare_file_name_metrics));
|
2012-05-01 13:26:16 +00:00
|
|
|
}
|
2021-08-06 20:33:55 +00:00
|
|
|
if (!comparisonFiles.empty()) {
|
|
|
|
qsort(comparisonFiles.begin(), comparisonFiles.count(), sizeof(SkString),
|
|
|
|
SkCastForQSort(compare_file_name_metrics));
|
2012-05-01 13:26:16 +00:00
|
|
|
}
|
2012-05-16 17:40:57 +00:00
|
|
|
|
2016-04-05 18:37:49 +00:00
|
|
|
if (!outputDir.isEmpty()) {
|
|
|
|
sk_mkdir(outputDir.c_str());
|
|
|
|
}
|
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
while (i < baseFiles.count() &&
|
|
|
|
j < comparisonFiles.count()) {
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
SkString basePath(baseDir);
|
|
|
|
SkString comparisonPath(comparisonDir);
|
2012-03-22 18:20:06 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
DiffRecord drp;
|
|
|
|
int v = strcmp(baseFiles[i].c_str(), comparisonFiles[j].c_str());
|
2012-03-22 18:20:06 +00:00
|
|
|
|
|
|
|
if (v < 0) {
|
|
|
|
// in baseDir, but not in comparisonDir
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fResult = DiffRecord::kCouldNotCompare_Result;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
basePath.append(baseFiles[i]);
|
|
|
|
comparisonPath.append(baseFiles[i]);
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fBase.fFilename = baseFiles[i];
|
|
|
|
drp.fBase.fFullPath = basePath;
|
|
|
|
drp.fBase.fStatus = DiffResource::kExists_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fComparison.fFilename = baseFiles[i];
|
|
|
|
drp.fComparison.fFullPath = comparisonPath;
|
|
|
|
drp.fComparison.fStatus = DiffResource::kDoesNotExist_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, baseFiles[i]);
|
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
++i;
|
|
|
|
} else if (v > 0) {
|
|
|
|
// in comparisonDir, but not in baseDir
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fResult = DiffRecord::kCouldNotCompare_Result;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
basePath.append(comparisonFiles[j]);
|
|
|
|
comparisonPath.append(comparisonFiles[j]);
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fBase.fFilename = comparisonFiles[j];
|
|
|
|
drp.fBase.fFullPath = basePath;
|
|
|
|
drp.fBase.fStatus = DiffResource::kDoesNotExist_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fComparison.fFilename = comparisonFiles[j];
|
|
|
|
drp.fComparison.fFullPath = comparisonPath;
|
|
|
|
drp.fComparison.fStatus = DiffResource::kExists_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("MISSING", ANSI_COLOR_YELLOW, comparisonFiles[j]);
|
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
++j;
|
|
|
|
} else {
|
2012-05-22 13:45:35 +00:00
|
|
|
// Found the same filename in both baseDir and comparisonDir.
|
2021-08-06 20:33:55 +00:00
|
|
|
SkASSERT(DiffRecord::kUnknown_Result == drp.fResult);
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
basePath.append(baseFiles[i]);
|
|
|
|
comparisonPath.append(comparisonFiles[j]);
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fBase.fFilename = baseFiles[i];
|
|
|
|
drp.fBase.fFullPath = basePath;
|
|
|
|
drp.fBase.fStatus = DiffResource::kExists_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fComparison.fFilename = comparisonFiles[j];
|
|
|
|
drp.fComparison.fFullPath = comparisonPath;
|
|
|
|
drp.fComparison.fStatus = DiffResource::kExists_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2021-08-06 20:33:55 +00:00
|
|
|
sk_sp<SkData> baseFileBits(read_file(drp.fBase.fFullPath.c_str()));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (baseFileBits) {
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fBase.fStatus = DiffResource::kRead_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2021-08-06 20:33:55 +00:00
|
|
|
sk_sp<SkData> comparisonFileBits(read_file(drp.fComparison.fFullPath.c_str()));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (comparisonFileBits) {
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fComparison.fStatus = DiffResource::kRead_Status;
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == baseFileBits || nullptr == comparisonFileBits) {
|
|
|
|
if (nullptr == baseFileBits) {
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fBase.fStatus = DiffResource::kCouldNotRead_Status;
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, baseFiles[i]);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == comparisonFileBits) {
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fComparison.fStatus = DiffResource::kCouldNotRead_Status;
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("READ FAIL", ANSI_COLOR_RED, comparisonFiles[j]);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fResult = DiffRecord::kCouldNotCompare_Result;
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
} else if (are_buffers_equal(baseFileBits.get(), comparisonFileBits.get())) {
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fResult = DiffRecord::kEqualBits_Result;
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("MATCH", ANSI_COLOR_GREEN, baseFiles[i]);
|
2012-05-22 13:45:35 +00:00
|
|
|
} else {
|
2021-08-06 20:33:55 +00:00
|
|
|
AutoReleasePixels arp(&drp);
|
|
|
|
get_bitmap(baseFileBits, drp.fBase, false, ignoreColorSpace);
|
|
|
|
get_bitmap(comparisonFileBits, drp.fComparison, false, ignoreColorSpace);
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("DIFFERENT", ANSI_COLOR_RED, baseFiles[i]);
|
2021-08-06 20:33:55 +00:00
|
|
|
if (DiffResource::kDecoded_Status == drp.fBase.fStatus &&
|
|
|
|
DiffResource::kDecoded_Status == drp.fComparison.fStatus) {
|
|
|
|
create_and_write_diff_image(&drp, dmp, colorThreshold,
|
|
|
|
outputDir, drp.fBase.fFilename);
|
2012-05-22 13:45:35 +00:00
|
|
|
} else {
|
2021-08-06 20:33:55 +00:00
|
|
|
drp.fResult = DiffRecord::kCouldNotCompare_Result;
|
2012-05-22 13:45:35 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-05 20:13:12 +00:00
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
++i;
|
|
|
|
++j;
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2012-12-05 20:13:12 +00:00
|
|
|
|
|
|
|
if (getBounds) {
|
2021-08-06 20:33:55 +00:00
|
|
|
get_bounds(drp);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2021-08-06 20:33:55 +00:00
|
|
|
SkASSERT(DiffRecord::kUnknown_Result != drp.fResult);
|
2012-03-22 18:20:06 +00:00
|
|
|
summary->add(drp);
|
2021-08-06 20:33:55 +00:00
|
|
|
differences->push_back(std::move(drp));
|
2012-03-22 18:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < baseFiles.count(); ++i) {
|
|
|
|
// files only in baseDir
|
2021-08-06 20:33:55 +00:00
|
|
|
DiffRecord drp;
|
|
|
|
drp.fBase.fFilename = baseFiles[i];
|
|
|
|
drp.fBase.fFullPath = baseDir;
|
|
|
|
drp.fBase.fFullPath.append(drp.fBase.fFilename);
|
|
|
|
drp.fBase.fStatus = DiffResource::kExists_Status;
|
|
|
|
|
|
|
|
drp.fComparison.fFilename = baseFiles[i];
|
|
|
|
drp.fComparison.fFullPath = comparisonDir;
|
|
|
|
drp.fComparison.fFullPath.append(drp.fComparison.fFilename);
|
|
|
|
drp.fComparison.fStatus = DiffResource::kDoesNotExist_Status;
|
|
|
|
|
|
|
|
drp.fResult = DiffRecord::kCouldNotCompare_Result;
|
2012-12-05 20:13:12 +00:00
|
|
|
if (getBounds) {
|
2021-08-06 20:33:55 +00:00
|
|
|
get_bounds(drp);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2012-03-22 18:20:06 +00:00
|
|
|
summary->add(drp);
|
2021-08-06 20:33:55 +00:00
|
|
|
differences->push_back(std::move(drp));
|
2012-03-22 18:20:06 +00:00
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
for (; j < comparisonFiles.count(); ++j) {
|
|
|
|
// files only in comparisonDir
|
2021-08-06 20:33:55 +00:00
|
|
|
DiffRecord drp;
|
|
|
|
drp.fBase.fFilename = comparisonFiles[j];
|
|
|
|
drp.fBase.fFullPath = baseDir;
|
|
|
|
drp.fBase.fFullPath.append(drp.fBase.fFilename);
|
|
|
|
drp.fBase.fStatus = DiffResource::kDoesNotExist_Status;
|
|
|
|
|
|
|
|
drp.fComparison.fFilename = comparisonFiles[j];
|
|
|
|
drp.fComparison.fFullPath = comparisonDir;
|
|
|
|
drp.fComparison.fFullPath.append(drp.fComparison.fFilename);
|
|
|
|
drp.fComparison.fStatus = DiffResource::kExists_Status;
|
|
|
|
|
|
|
|
drp.fResult = DiffRecord::kCouldNotCompare_Result;
|
2012-12-05 20:13:12 +00:00
|
|
|
if (getBounds) {
|
2021-08-06 20:33:55 +00:00
|
|
|
get_bounds(drp);
|
2012-12-05 20:13:12 +00:00
|
|
|
}
|
2011-06-09 15:47:10 +00:00
|
|
|
summary->add(drp);
|
2021-08-06 20:33:55 +00:00
|
|
|
differences->push_back(std::move(drp));
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2011-07-14 13:15:55 +00:00
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
|
|
|
|
static void usage (char * argv0) {
|
|
|
|
SkDebugf("Skia baseline image diff tool\n");
|
2012-05-01 13:26:16 +00:00
|
|
|
SkDebugf("\n"
|
|
|
|
"Usage: \n"
|
2012-12-05 20:13:12 +00:00
|
|
|
" %s <baseDir> <comparisonDir> [outputDir] \n", argv0);
|
2012-07-09 21:01:50 +00:00
|
|
|
SkDebugf(
|
2012-07-12 18:16:02 +00:00
|
|
|
"\nArguments:"
|
2012-07-13 21:22:02 +00:00
|
|
|
"\n --failonresult <result>: After comparing all file pairs, exit with nonzero"
|
|
|
|
"\n return code (number of file pairs yielding this"
|
|
|
|
"\n result) if any file pairs yielded this result."
|
|
|
|
"\n This flag may be repeated, in which case the"
|
|
|
|
"\n return code will be the number of fail pairs"
|
|
|
|
"\n yielding ANY of these results."
|
2012-12-05 20:13:12 +00:00
|
|
|
"\n --failonstatus <baseStatus> <comparisonStatus>: exit with nonzero return"
|
|
|
|
"\n code if any file pairs yielded this status."
|
2012-07-12 18:16:02 +00:00
|
|
|
"\n --help: display this info"
|
|
|
|
"\n --listfilenames: list all filenames for each result type in stdout"
|
2012-07-13 21:22:02 +00:00
|
|
|
"\n --match <substring>: compare files whose filenames contain this substring;"
|
|
|
|
"\n if unspecified, compare ALL files."
|
|
|
|
"\n this flag may be repeated."
|
2018-07-17 20:45:40 +00:00
|
|
|
"\n --nocolorspace: Ignore color space of images."
|
2012-07-12 18:16:02 +00:00
|
|
|
"\n --nodiffs: don't write out image diffs or index.html, just generate"
|
|
|
|
"\n report on stdout"
|
2012-07-13 21:22:02 +00:00
|
|
|
"\n --nomatch <substring>: regardless of --match, DO NOT compare files whose"
|
|
|
|
"\n filenames contain this substring."
|
|
|
|
"\n this flag may be repeated."
|
2012-07-12 18:16:02 +00:00
|
|
|
"\n --noprintdirs: do not print the directories used."
|
2012-08-16 13:42:13 +00:00
|
|
|
"\n --norecurse: do not recurse into subdirectories."
|
2012-07-12 18:16:02 +00:00
|
|
|
"\n --sortbymaxmismatch: sort by worst color channel mismatch;"
|
|
|
|
"\n break ties with -sortbymismatch"
|
|
|
|
"\n --sortbymismatch: sort by average color channel mismatch"
|
|
|
|
"\n --threshold <n>: only report differences > n (per color channel) [default 0]"
|
|
|
|
"\n --weighted: sort by # pixels different weighted by color difference"
|
|
|
|
"\n"
|
|
|
|
"\n baseDir: directory to read baseline images from."
|
|
|
|
"\n comparisonDir: directory to read comparison images from"
|
|
|
|
"\n outputDir: directory to write difference images and index.html to;"
|
|
|
|
"\n defaults to comparisonDir"
|
|
|
|
"\n"
|
|
|
|
"\nIf no sort is specified, it will sort by fraction of pixels mismatching."
|
|
|
|
"\n");
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 18:37:55 +00:00
|
|
|
const int kNoError = 0;
|
|
|
|
const int kGenericError = -1;
|
2012-07-12 18:16:02 +00:00
|
|
|
|
2017-02-06 17:46:20 +00:00
|
|
|
int main(int argc, char** argv) {
|
2011-04-27 15:39:30 +00:00
|
|
|
DiffMetricProc diffProc = compute_diff_pmcolor;
|
2012-06-28 16:47:34 +00:00
|
|
|
int (*sortProc)(const void*, const void*) = compare<CompareDiffMetrics>;
|
2011-04-27 15:39:30 +00:00
|
|
|
|
|
|
|
// Maximum error tolerated in any one color channel in any one pixel before
|
|
|
|
// a difference is reported.
|
|
|
|
int colorThreshold = 0;
|
|
|
|
SkString baseDir;
|
|
|
|
SkString comparisonDir;
|
|
|
|
SkString outputDir;
|
2012-07-13 21:22:02 +00:00
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
StringArray matchSubstrings;
|
|
|
|
StringArray nomatchSubstrings;
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
bool generateDiffs = true;
|
2012-07-12 18:16:02 +00:00
|
|
|
bool listFilenames = false;
|
2012-08-16 13:42:13 +00:00
|
|
|
bool printDirNames = true;
|
|
|
|
bool recurseIntoSubdirs = true;
|
2014-05-28 18:26:00 +00:00
|
|
|
bool verbose = false;
|
2015-01-06 15:39:55 +00:00
|
|
|
bool listFailingBase = false;
|
2018-07-17 20:45:40 +00:00
|
|
|
bool ignoreColorSpace = false;
|
2011-07-14 13:15:55 +00:00
|
|
|
|
2011-04-27 15:39:30 +00:00
|
|
|
RecordArray differences;
|
2011-06-09 15:47:10 +00:00
|
|
|
DiffSummary summary;
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
bool failOnResultType[DiffRecord::kResultCount];
|
|
|
|
for (int i = 0; i < DiffRecord::kResultCount; i++) {
|
2012-07-19 17:35:04 +00:00
|
|
|
failOnResultType[i] = false;
|
|
|
|
}
|
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
bool failOnStatusType[DiffResource::kStatusCount][DiffResource::kStatusCount];
|
|
|
|
for (int base = 0; base < DiffResource::kStatusCount; ++base) {
|
|
|
|
for (int comparison = 0; comparison < DiffResource::kStatusCount; ++comparison) {
|
|
|
|
failOnStatusType[base][comparison] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
int numUnflaggedArguments = 0;
|
2021-08-11 15:01:17 +00:00
|
|
|
for (int i = 1; i < argc; i++) {
|
2012-07-13 21:22:02 +00:00
|
|
|
if (!strcmp(argv[i], "--failonresult")) {
|
2012-12-05 20:13:12 +00:00
|
|
|
if (argc == ++i) {
|
|
|
|
SkDebugf("failonresult expects one argument.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DiffRecord::Result type = DiffRecord::getResultByName(argv[i]);
|
|
|
|
if (type != DiffRecord::kResultCount) {
|
|
|
|
failOnResultType[type] = true;
|
|
|
|
} else {
|
|
|
|
SkDebugf("ignoring unrecognized result <%s>\n", argv[i]);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--failonstatus")) {
|
|
|
|
if (argc == ++i) {
|
|
|
|
SkDebugf("failonstatus missing base status.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool baseStatuses[DiffResource::kStatusCount];
|
|
|
|
if (!DiffResource::getMatchingStatuses(argv[i], baseStatuses)) {
|
|
|
|
SkDebugf("unrecognized base status <%s>\n", argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == ++i) {
|
|
|
|
SkDebugf("failonstatus missing comparison status.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool comparisonStatuses[DiffResource::kStatusCount];
|
|
|
|
if (!DiffResource::getMatchingStatuses(argv[i], comparisonStatuses)) {
|
|
|
|
SkDebugf("unrecognized comarison status <%s>\n", argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int base = 0; base < DiffResource::kStatusCount; ++base) {
|
|
|
|
for (int comparison = 0; comparison < DiffResource::kStatusCount; ++comparison) {
|
|
|
|
failOnStatusType[base][comparison] |=
|
|
|
|
baseStatuses[base] && comparisonStatuses[comparison];
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-14 13:15:55 +00:00
|
|
|
if (!strcmp(argv[i], "--help")) {
|
2011-04-27 15:39:30 +00:00
|
|
|
usage(argv[0]);
|
2012-07-12 18:37:55 +00:00
|
|
|
return kNoError;
|
2012-05-01 13:26:16 +00:00
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
if (!strcmp(argv[i], "--listfilenames")) {
|
|
|
|
listFilenames = true;
|
2012-05-01 13:26:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-28 18:26:00 +00:00
|
|
|
if (!strcmp(argv[i], "--verbose")) {
|
|
|
|
verbose = true;
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
if (!strcmp(argv[i], "--match")) {
|
2021-08-06 20:33:55 +00:00
|
|
|
matchSubstrings.emplace_back(argv[++i]);
|
2012-05-01 13:26:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-07-17 20:45:40 +00:00
|
|
|
if (!strcmp(argv[i], "--nocolorspace")) {
|
|
|
|
ignoreColorSpace = true;
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
if (!strcmp(argv[i], "--nodiffs")) {
|
|
|
|
generateDiffs = false;
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
if (!strcmp(argv[i], "--nomatch")) {
|
2021-08-06 20:33:55 +00:00
|
|
|
nomatchSubstrings.emplace_back(argv[++i]);
|
2012-05-01 13:26:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
if (!strcmp(argv[i], "--noprintdirs")) {
|
2012-08-16 13:42:13 +00:00
|
|
|
printDirNames = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--norecurse")) {
|
|
|
|
recurseIntoSubdirs = false;
|
2011-04-27 15:39:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-14 13:15:55 +00:00
|
|
|
if (!strcmp(argv[i], "--sortbymaxmismatch")) {
|
2012-06-28 16:47:34 +00:00
|
|
|
sortProc = compare<CompareDiffMaxMismatches>;
|
2011-04-27 15:39:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
if (!strcmp(argv[i], "--sortbymismatch")) {
|
|
|
|
sortProc = compare<CompareDiffMeanMismatches>;
|
2011-05-24 19:41:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
if (!strcmp(argv[i], "--threshold")) {
|
|
|
|
colorThreshold = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--weighted")) {
|
|
|
|
sortProc = compare<CompareDiffWeighted>;
|
2012-07-09 21:01:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
if (argv[i][0] != '-') {
|
2012-05-01 13:26:16 +00:00
|
|
|
switch (numUnflaggedArguments++) {
|
2011-04-27 15:39:30 +00:00
|
|
|
case 0:
|
|
|
|
baseDir.set(argv[i]);
|
|
|
|
continue;
|
|
|
|
case 1:
|
|
|
|
comparisonDir.set(argv[i]);
|
|
|
|
continue;
|
|
|
|
case 2:
|
|
|
|
outputDir.set(argv[i]);
|
|
|
|
continue;
|
|
|
|
default:
|
2012-05-01 13:26:16 +00:00
|
|
|
SkDebugf("extra unflagged argument <%s>\n", argv[i]);
|
2011-04-27 15:39:30 +00:00
|
|
|
usage(argv[0]);
|
2012-07-12 18:37:55 +00:00
|
|
|
return kGenericError;
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-06 15:39:55 +00:00
|
|
|
if (!strcmp(argv[i], "--listFailingBase")) {
|
|
|
|
listFailingBase = true;
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
|
|
|
|
SkDebugf("Unrecognized argument <%s>\n", argv[i]);
|
|
|
|
usage(argv[0]);
|
2012-07-12 18:37:55 +00:00
|
|
|
return kGenericError;
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
|
|
|
|
if (numUnflaggedArguments == 2) {
|
2011-06-09 15:47:10 +00:00
|
|
|
outputDir = comparisonDir;
|
2012-05-01 13:26:16 +00:00
|
|
|
} else if (numUnflaggedArguments != 3) {
|
2011-06-09 15:47:10 +00:00
|
|
|
usage(argv[0]);
|
2012-07-12 18:37:55 +00:00
|
|
|
return kGenericError;
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 14:56:37 +00:00
|
|
|
if (!baseDir.endsWith(PATH_DIV_STR)) {
|
|
|
|
baseDir.append(PATH_DIV_STR);
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2012-08-16 13:42:13 +00:00
|
|
|
if (printDirNames) {
|
2012-07-09 21:01:50 +00:00
|
|
|
printf("baseDir is [%s]\n", baseDir.c_str());
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
|
2011-09-23 14:56:37 +00:00
|
|
|
if (!comparisonDir.endsWith(PATH_DIV_STR)) {
|
|
|
|
comparisonDir.append(PATH_DIV_STR);
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2012-08-16 13:42:13 +00:00
|
|
|
if (printDirNames) {
|
2012-07-09 21:01:50 +00:00
|
|
|
printf("comparisonDir is [%s]\n", comparisonDir.c_str());
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
|
2011-09-23 14:56:37 +00:00
|
|
|
if (!outputDir.endsWith(PATH_DIV_STR)) {
|
|
|
|
outputDir.append(PATH_DIV_STR);
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
if (generateDiffs) {
|
2012-08-16 13:42:13 +00:00
|
|
|
if (printDirNames) {
|
2012-07-09 21:01:50 +00:00
|
|
|
printf("writing diffs to outputDir is [%s]\n", outputDir.c_str());
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
} else {
|
2012-08-16 13:42:13 +00:00
|
|
|
if (printDirNames) {
|
2012-07-09 21:01:50 +00:00
|
|
|
printf("not writing any diffs to outputDir [%s]\n", outputDir.c_str());
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
outputDir.set("");
|
|
|
|
}
|
|
|
|
|
2012-06-25 18:45:50 +00:00
|
|
|
// If no matchSubstrings were specified, match ALL strings
|
|
|
|
// (except for whatever nomatchSubstrings were specified, if any).
|
2021-08-06 20:33:55 +00:00
|
|
|
if (matchSubstrings.empty()) {
|
|
|
|
matchSubstrings.emplace_back("");
|
2012-05-01 13:26:16 +00:00
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2018-07-17 20:45:40 +00:00
|
|
|
create_diff_images(diffProc, colorThreshold, ignoreColorSpace, &differences,
|
2012-05-18 20:10:06 +00:00
|
|
|
baseDir, comparisonDir, outputDir,
|
2012-12-05 20:13:12 +00:00
|
|
|
matchSubstrings, nomatchSubstrings, recurseIntoSubdirs, generateDiffs,
|
2014-05-28 18:26:00 +00:00
|
|
|
verbose, &summary);
|
2012-12-05 20:13:12 +00:00
|
|
|
summary.print(listFilenames, failOnResultType, failOnStatusType);
|
2011-07-14 13:15:55 +00:00
|
|
|
|
2015-01-06 15:39:55 +00:00
|
|
|
if (listFailingBase) {
|
|
|
|
summary.printfFailingBaseNames("\n");
|
|
|
|
}
|
|
|
|
|
2011-07-14 13:15:55 +00:00
|
|
|
if (differences.count()) {
|
2021-08-06 20:33:55 +00:00
|
|
|
qsort(differences.begin(), differences.count(), sizeof(DiffRecord), sortProc);
|
2011-07-14 13:15:55 +00:00
|
|
|
}
|
2012-05-16 17:40:57 +00:00
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
if (generateDiffs) {
|
|
|
|
print_diff_page(summary.fNumMatches, colorThreshold, differences,
|
|
|
|
baseDir, comparisonDir, outputDir);
|
|
|
|
}
|
2012-05-31 15:12:09 +00:00
|
|
|
|
2012-07-13 21:22:02 +00:00
|
|
|
int num_failing_results = 0;
|
2012-12-05 20:13:12 +00:00
|
|
|
for (int i = 0; i < DiffRecord::kResultCount; i++) {
|
2012-07-19 17:35:04 +00:00
|
|
|
if (failOnResultType[i]) {
|
|
|
|
num_failing_results += summary.fResultsOfType[i].count();
|
|
|
|
}
|
2012-07-12 18:16:02 +00:00
|
|
|
}
|
2012-12-05 20:13:12 +00:00
|
|
|
if (!failOnResultType[DiffRecord::kCouldNotCompare_Result]) {
|
|
|
|
for (int base = 0; base < DiffResource::kStatusCount; ++base) {
|
|
|
|
for (int comparison = 0; comparison < DiffResource::kStatusCount; ++comparison) {
|
|
|
|
if (failOnStatusType[base][comparison]) {
|
|
|
|
num_failing_results += summary.fStatusOfType[base][comparison].count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-16 18:01:06 +00:00
|
|
|
|
|
|
|
// On Linux (and maybe other platforms too), any results outside of the
|
|
|
|
// range [0...255] are wrapped (mod 256). Do the conversion ourselves, to
|
|
|
|
// make sure that we only return 0 when there were no failures.
|
|
|
|
return (num_failing_results > 255) ? 255 : num_failing_results;
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|