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.
|
|
|
|
*/
|
2012-12-05 20:13:12 +00:00
|
|
|
#include "skdiff.h"
|
|
|
|
#include "skdiff_html.h"
|
|
|
|
#include "skdiff_utils.h"
|
|
|
|
#include "SkBitmap.h"
|
2012-05-22 13:45:35 +00:00
|
|
|
#include "SkData.h"
|
2013-06-18 21:23:31 +00:00
|
|
|
#include "SkForceLinking.h"
|
2011-04-27 15:39:30 +00:00
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkImageEncoder.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkTemplates.h"
|
|
|
|
#include "SkTSearch.h"
|
|
|
|
|
2013-06-18 21:23:31 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
typedef SkTDArray<SkString*> StringArray;
|
|
|
|
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();
|
|
|
|
const char* trimmed = strrchr(src, SkPATH_SEPARATOR);
|
|
|
|
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) {
|
|
|
|
if (*array->getAt(i) == result) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*array->append() = new SkString(result);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
, fMaxMismatchPercent(0) { };
|
2011-06-09 15:47:10 +00:00
|
|
|
|
2012-03-22 18:20:06 +00:00
|
|
|
~DiffSummary() {
|
2012-12-05 20:13:12 +00:00
|
|
|
for (int i = 0; i < DiffRecord::kResultCount; ++i) {
|
2012-05-31 15:12:09 +00:00
|
|
|
fResultsOfType[i].deleteAll();
|
|
|
|
}
|
2012-12-05 20:13:12 +00:00
|
|
|
for (int base = 0; base < DiffResource::kStatusCount; ++base) {
|
|
|
|
for (int comparison = 0; comparison < DiffResource::kStatusCount; ++comparison) {
|
|
|
|
fStatusOfType[base][comparison].deleteAll();
|
|
|
|
}
|
2012-12-06 02:01:25 +00:00
|
|
|
}
|
2012-03-22 18:20:06 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
printf("%s ", fileArray[i]->c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
printf("%s%s", array[j]->c_str(), separator);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-09 15:47:10 +00:00
|
|
|
void add (DiffRecord* drp) {
|
2012-05-22 13:45:35 +00:00
|
|
|
uint32_t mismatchValue;
|
2012-05-16 14:57:28 +00:00
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
if (drp->fBase.fFilename.equals(drp->fComparison.fFilename)) {
|
|
|
|
fResultsOfType[drp->fResult].push(new SkString(drp->fBase.fFilename));
|
|
|
|
} else {
|
|
|
|
SkString* blame = new SkString("(");
|
|
|
|
blame->append(drp->fBase.fFilename);
|
|
|
|
blame->append(", ");
|
|
|
|
blame->append(drp->fComparison.fFilename);
|
|
|
|
blame->append(")");
|
|
|
|
fResultsOfType[drp->fResult].push(blame);
|
|
|
|
}
|
2012-05-16 14:57:28 +00:00
|
|
|
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++;
|
|
|
|
if (drp->fFractionDifference * 100 > fMaxMismatchPercent) {
|
|
|
|
fMaxMismatchPercent = drp->fFractionDifference * 100;
|
|
|
|
}
|
2012-05-22 13:45:35 +00:00
|
|
|
mismatchValue = MAX3(drp->fMaxMismatchR, drp->fMaxMismatchG,
|
|
|
|
drp->fMaxMismatchB);
|
|
|
|
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++;
|
2012-12-05 20:13:12 +00:00
|
|
|
fStatusOfType[drp->fBase.fStatus][drp->fComparison.fStatus].push(
|
|
|
|
new SkString(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
|
|
|
|
|
|
|
switch (drp->fResult) {
|
|
|
|
case DiffRecord::kEqualBits_Result:
|
|
|
|
case DiffRecord::kEqualPixels_Result:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
add_unique_basename(&fFailedBaseNames[drp->fResult], drp->fBase.fFilename);
|
|
|
|
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++) {
|
|
|
|
if (string.contains(substrings[i]->c_str())) {
|
|
|
|
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)) {
|
|
|
|
files->push(new SkString(pathRelativeToRootDir));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
static void release_file_list(FileArray *files) {
|
|
|
|
files->deleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Comparison routines for qsort, sort by file names.
|
|
|
|
static int compare_file_name_metrics(SkString **lhs, SkString **rhs) {
|
|
|
|
return strcmp((*lhs)->c_str(), (*rhs)->c_str());
|
|
|
|
}
|
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
class AutoReleasePixels {
|
|
|
|
public:
|
|
|
|
AutoReleasePixels(DiffRecord* drp)
|
|
|
|
: fDrp(drp) {
|
|
|
|
SkASSERT(drp != NULL);
|
|
|
|
}
|
|
|
|
~AutoReleasePixels() {
|
|
|
|
fDrp->fBase.fBitmap.setPixelRef(NULL);
|
|
|
|
fDrp->fComparison.fBitmap.setPixelRef(NULL);
|
|
|
|
fDrp->fDifference.fBitmap.setPixelRef(NULL);
|
|
|
|
fDrp->fWhite.fBitmap.setPixelRef(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DiffRecord* fDrp;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void get_bounds(DiffResource& resource, const char* name) {
|
|
|
|
if (resource.fBitmap.empty() && !DiffResource::isStatusFailed(resource.fStatus)) {
|
|
|
|
SkAutoDataUnref fileBits(read_file(resource.fFullPath.c_str()));
|
|
|
|
if (NULL == fileBits) {
|
|
|
|
SkDebugf("WARNING: couldn't read %s file <%s>\n", name, resource.fFullPath.c_str());
|
|
|
|
resource.fStatus = DiffResource::kCouldNotRead_Status;
|
|
|
|
} else {
|
|
|
|
get_bitmap(fileBits, resource, SkImageDecoder::kDecodeBounds_Mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#define VERBOSE_STATUS(status,color,filename) if (verbose) printf( "[ " color " %10s " ANSI_COLOR_RESET " ] %s\n", status, filename->c_str())
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
2012-05-01 13:26:16 +00:00
|
|
|
if (!baseFiles.isEmpty()) {
|
2012-05-07 14:52:12 +00:00
|
|
|
qsort(baseFiles.begin(), baseFiles.count(), sizeof(SkString*),
|
|
|
|
SkCastForQSort(compare_file_name_metrics));
|
2012-05-01 13:26:16 +00:00
|
|
|
}
|
|
|
|
if (!comparisonFiles.isEmpty()) {
|
2012-05-07 14:52:12 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2012-12-05 20:13:12 +00:00
|
|
|
DiffRecord *drp = new DiffRecord;
|
|
|
|
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
|
2012-12-05 20:13:12 +00:00
|
|
|
drp->fResult = DiffRecord::kCouldNotCompare_Result;
|
|
|
|
|
|
|
|
basePath.append(*baseFiles[i]);
|
|
|
|
comparisonPath.append(*baseFiles[i]);
|
|
|
|
|
|
|
|
drp->fBase.fFilename = *baseFiles[i];
|
|
|
|
drp->fBase.fFullPath = basePath;
|
|
|
|
drp->fBase.fStatus = DiffResource::kExists_Status;
|
|
|
|
|
|
|
|
drp->fComparison.fFilename = *baseFiles[i];
|
|
|
|
drp->fComparison.fFullPath = comparisonPath;
|
|
|
|
drp->fComparison.fStatus = DiffResource::kDoesNotExist_Status;
|
|
|
|
|
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
|
2012-12-05 20:13:12 +00:00
|
|
|
drp->fResult = DiffRecord::kCouldNotCompare_Result;
|
|
|
|
|
|
|
|
basePath.append(*comparisonFiles[j]);
|
|
|
|
comparisonPath.append(*comparisonFiles[j]);
|
|
|
|
|
|
|
|
drp->fBase.fFilename = *comparisonFiles[j];
|
|
|
|
drp->fBase.fFullPath = basePath;
|
|
|
|
drp->fBase.fStatus = DiffResource::kDoesNotExist_Status;
|
|
|
|
|
|
|
|
drp->fComparison.fFilename = *comparisonFiles[j];
|
|
|
|
drp->fComparison.fFullPath = comparisonPath;
|
|
|
|
drp->fComparison.fStatus = DiffResource::kExists_Status;
|
|
|
|
|
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.
|
2012-12-05 20:13:12 +00:00
|
|
|
SkASSERT(DiffRecord::kUnknown_Result == drp->fResult);
|
|
|
|
|
|
|
|
basePath.append(*baseFiles[i]);
|
|
|
|
comparisonPath.append(*comparisonFiles[j]);
|
|
|
|
|
|
|
|
drp->fBase.fFilename = *baseFiles[i];
|
|
|
|
drp->fBase.fFullPath = basePath;
|
|
|
|
drp->fBase.fStatus = DiffResource::kExists_Status;
|
|
|
|
|
|
|
|
drp->fComparison.fFilename = *comparisonFiles[j];
|
|
|
|
drp->fComparison.fFullPath = comparisonPath;
|
|
|
|
drp->fComparison.fStatus = DiffResource::kExists_Status;
|
|
|
|
|
|
|
|
SkAutoDataUnref baseFileBits(read_file(drp->fBase.fFullPath.c_str()));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (baseFileBits) {
|
2012-12-05 20:13:12 +00:00
|
|
|
drp->fBase.fStatus = DiffResource::kRead_Status;
|
|
|
|
}
|
|
|
|
SkAutoDataUnref comparisonFileBits(read_file(drp->fComparison.fFullPath.c_str()));
|
2014-09-05 20:34:00 +00:00
|
|
|
if (comparisonFileBits) {
|
2012-12-05 20:13:12 +00:00
|
|
|
drp->fComparison.fStatus = DiffResource::kRead_Status;
|
|
|
|
}
|
|
|
|
if (NULL == baseFileBits || NULL == comparisonFileBits) {
|
|
|
|
if (NULL == baseFileBits) {
|
|
|
|
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
|
|
|
}
|
|
|
|
if (NULL == comparisonFileBits) {
|
|
|
|
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
|
|
|
}
|
|
|
|
drp->fResult = DiffRecord::kCouldNotCompare_Result;
|
|
|
|
|
|
|
|
} else if (are_buffers_equal(baseFileBits, comparisonFileBits)) {
|
|
|
|
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 {
|
2012-12-05 20:13:12 +00:00
|
|
|
AutoReleasePixels arp(drp);
|
|
|
|
get_bitmap(baseFileBits, drp->fBase, SkImageDecoder::kDecodePixels_Mode);
|
|
|
|
get_bitmap(comparisonFileBits, drp->fComparison,
|
|
|
|
SkImageDecoder::kDecodePixels_Mode);
|
2014-05-28 18:26:00 +00:00
|
|
|
VERBOSE_STATUS("DIFFERENT", ANSI_COLOR_RED, baseFiles[i]);
|
2012-12-05 20:13:12 +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 {
|
2012-12-05 20:13:12 +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) {
|
|
|
|
get_bounds(*drp);
|
|
|
|
}
|
|
|
|
SkASSERT(DiffRecord::kUnknown_Result != drp->fResult);
|
2012-03-22 18:20:06 +00:00
|
|
|
differences->push(drp);
|
|
|
|
summary->add(drp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < baseFiles.count(); ++i) {
|
|
|
|
// files only in baseDir
|
2012-12-05 20:13:12 +00:00
|
|
|
DiffRecord *drp = new DiffRecord();
|
|
|
|
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;
|
|
|
|
if (getBounds) {
|
|
|
|
get_bounds(*drp);
|
|
|
|
}
|
2012-03-22 18:20:06 +00:00
|
|
|
differences->push(drp);
|
|
|
|
summary->add(drp);
|
|
|
|
}
|
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
|
2012-12-05 20:13:12 +00:00
|
|
|
DiffRecord *drp = new DiffRecord();
|
|
|
|
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;
|
|
|
|
if (getBounds) {
|
|
|
|
get_bounds(*drp);
|
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
differences->push(drp);
|
2011-06-09 15:47:10 +00:00
|
|
|
summary->add(drp);
|
2011-04-27 15:39:30 +00:00
|
|
|
}
|
2012-03-22 18:20:06 +00:00
|
|
|
|
|
|
|
release_file_list(&baseFiles);
|
|
|
|
release_file_list(&comparisonFiles);
|
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."
|
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
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_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;
|
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 i;
|
|
|
|
int numUnflaggedArguments = 0;
|
|
|
|
for (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")) {
|
|
|
|
matchSubstrings.push(new SkString(argv[++i]));
|
|
|
|
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")) {
|
|
|
|
nomatchSubstrings.push(new SkString(argv[++i]));
|
|
|
|
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).
|
2012-05-01 13:26:16 +00:00
|
|
|
if (matchSubstrings.isEmpty()) {
|
|
|
|
matchSubstrings.push(new SkString(""));
|
|
|
|
}
|
2011-04-27 15:39:30 +00:00
|
|
|
|
2012-05-18 20:10:06 +00:00
|
|
|
create_diff_images(diffProc, colorThreshold, &differences,
|
|
|
|
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()) {
|
2012-05-07 14:52:12 +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
|
|
|
|
2011-04-27 15:39:30 +00:00
|
|
|
for (i = 0; i < differences.count(); i++) {
|
|
|
|
delete differences[i];
|
|
|
|
}
|
2012-05-01 13:26:16 +00:00
|
|
|
matchSubstrings.deleteAll();
|
|
|
|
nomatchSubstrings.deleteAll();
|
2012-05-31 15:13:45 +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
|
|
|
}
|
2012-10-02 18:33:14 +00:00
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|