2011-07-28 18:26:00 +04: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.
|
|
|
|
*/
|
2011-04-27 19:39:30 +04:00
|
|
|
#include "SkColorPriv.h"
|
2012-05-22 17:45:35 +04:00
|
|
|
#include "SkData.h"
|
2011-04-27 19:39:30 +04:00
|
|
|
#include "SkImageDecoder.h"
|
|
|
|
#include "SkImageEncoder.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkTemplates.h"
|
|
|
|
#include "SkTime.h"
|
|
|
|
#include "SkTSearch.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 17:15:55 +04:00
|
|
|
* Creates an index.html in the current third directory to compare each
|
2011-04-27 19:39:30 +04:00
|
|
|
* pair that does not match exactly.
|
|
|
|
* Does *not* recursively descend directories.
|
2012-05-31 19:13:45 +04:00
|
|
|
*
|
|
|
|
* Returns zero exit code if all images match across baseDir and comparisonDir.
|
2011-04-27 19:39:30 +04:00
|
|
|
*/
|
|
|
|
|
2011-09-23 18:56:37 +04:00
|
|
|
#if SK_BUILD_FOR_WIN32
|
|
|
|
#define PATH_DIV_STR "\\"
|
|
|
|
#define PATH_DIV_CHAR '\\'
|
|
|
|
#else
|
|
|
|
#define PATH_DIV_STR "/"
|
|
|
|
#define PATH_DIV_CHAR '/'
|
|
|
|
#endif
|
|
|
|
|
2012-05-16 18:57:28 +04:00
|
|
|
// Result of comparison for each pair of files.
|
|
|
|
enum Result {
|
|
|
|
kEqualBits, // both files in the pair contain exactly the same bits
|
|
|
|
kEqualPixels, // not bitwise equal, but their pixels are exactly the same
|
|
|
|
kDifferentSizes, // both are images we can parse, but of different sizes
|
|
|
|
kDifferentPixels,// both are images we can parse, but with different pixels
|
|
|
|
kDifferentOther, // files have different bits but are not parsable images
|
|
|
|
kBaseMissing, // missing from baseDir
|
|
|
|
kComparisonMissing,// missing from comparisonDir
|
2012-05-31 19:12:09 +04:00
|
|
|
kUnknown, // not compared yet
|
|
|
|
//
|
|
|
|
kNumResultTypes // NOT A VALID VALUE--used to set up arrays. Must be last.
|
2012-05-16 18:57:28 +04:00
|
|
|
};
|
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
struct DiffRecord {
|
2011-07-13 21:42:46 +04:00
|
|
|
DiffRecord (const SkString filename,
|
|
|
|
const SkString basePath,
|
2012-03-22 22:20:06 +04:00
|
|
|
const SkString comparisonPath,
|
2012-05-16 18:57:28 +04:00
|
|
|
const Result result = kUnknown)
|
2011-04-27 19:39:30 +04:00
|
|
|
: fFilename (filename)
|
2011-07-13 21:42:46 +04:00
|
|
|
, fBasePath (basePath)
|
|
|
|
, fComparisonPath (comparisonPath)
|
2011-08-02 18:10:04 +04:00
|
|
|
, fBaseBitmap (new SkBitmap ())
|
|
|
|
, fComparisonBitmap (new SkBitmap ())
|
|
|
|
, fDifferenceBitmap (new SkBitmap ())
|
2012-02-03 00:50:36 +04:00
|
|
|
, fWhiteBitmap (new SkBitmap ())
|
2011-08-02 18:10:04 +04:00
|
|
|
, fBaseHeight (0)
|
|
|
|
, fBaseWidth (0)
|
2011-06-09 19:47:10 +04:00
|
|
|
, fFractionDifference (0)
|
|
|
|
, fWeightedFraction (0)
|
2011-04-27 19:39:30 +04:00
|
|
|
, fAverageMismatchR (0)
|
|
|
|
, fAverageMismatchG (0)
|
|
|
|
, fAverageMismatchB (0)
|
|
|
|
, fMaxMismatchR (0)
|
|
|
|
, fMaxMismatchG (0)
|
2011-11-30 21:01:00 +04:00
|
|
|
, fMaxMismatchB (0)
|
2012-05-16 18:57:28 +04:00
|
|
|
, fResult(result) {
|
2011-07-13 21:42:46 +04:00
|
|
|
};
|
2011-04-27 19:39:30 +04:00
|
|
|
|
|
|
|
SkString fFilename;
|
2011-07-13 21:42:46 +04:00
|
|
|
SkString fBasePath;
|
|
|
|
SkString fComparisonPath;
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2011-08-02 18:10:04 +04:00
|
|
|
SkBitmap* fBaseBitmap;
|
|
|
|
SkBitmap* fComparisonBitmap;
|
|
|
|
SkBitmap* fDifferenceBitmap;
|
2012-02-03 00:50:36 +04:00
|
|
|
SkBitmap* fWhiteBitmap;
|
2011-08-02 18:10:04 +04:00
|
|
|
|
|
|
|
int fBaseHeight;
|
|
|
|
int fBaseWidth;
|
2011-04-27 19:39:30 +04:00
|
|
|
|
|
|
|
/// Arbitrary floating-point metric to be used to sort images from most
|
|
|
|
/// to least different from baseline; values of 0 will be omitted from the
|
|
|
|
/// summary webpage.
|
2011-06-09 19:47:10 +04:00
|
|
|
float fFractionDifference;
|
|
|
|
float fWeightedFraction;
|
2011-04-27 19:39:30 +04:00
|
|
|
|
|
|
|
float fAverageMismatchR;
|
|
|
|
float fAverageMismatchG;
|
|
|
|
float fAverageMismatchB;
|
|
|
|
|
|
|
|
uint32_t fMaxMismatchR;
|
|
|
|
uint32_t fMaxMismatchG;
|
|
|
|
uint32_t fMaxMismatchB;
|
2011-11-30 21:01:00 +04:00
|
|
|
|
2012-05-16 18:57:28 +04:00
|
|
|
/// Which category of diff result.
|
|
|
|
Result fResult;
|
2011-04-27 19:39:30 +04:00
|
|
|
};
|
|
|
|
|
2011-06-09 19:47:10 +04:00
|
|
|
#define MAX2(a,b) (((b) < (a)) ? (a) : (b))
|
|
|
|
#define MAX3(a,b,c) (((b) < (a)) ? MAX2((a), (c)) : MAX2((b), (c)))
|
|
|
|
|
2012-02-03 00:50:36 +04:00
|
|
|
const SkPMColor PMCOLOR_WHITE = SkPreMultiplyColor(SK_ColorWHITE);
|
|
|
|
const SkPMColor PMCOLOR_BLACK = SkPreMultiplyColor(SK_ColorBLACK);
|
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
typedef SkTDArray<SkString*> StringArray;
|
|
|
|
typedef StringArray FileArray;
|
2012-03-22 22:20:06 +04:00
|
|
|
|
2011-06-09 19:47:10 +04:00
|
|
|
struct DiffSummary {
|
|
|
|
DiffSummary ()
|
|
|
|
: fNumMatches (0)
|
|
|
|
, fNumMismatches (0)
|
|
|
|
, fMaxMismatchV (0)
|
|
|
|
, fMaxMismatchPercent (0) { };
|
|
|
|
|
2012-03-22 22:20:06 +04:00
|
|
|
~DiffSummary() {
|
2012-05-31 19:12:09 +04:00
|
|
|
for (int i = 0; i < kNumResultTypes; i++) {
|
|
|
|
fResultsOfType[i].deleteAll();
|
|
|
|
}
|
2012-03-22 22:20:06 +04:00
|
|
|
}
|
|
|
|
|
2011-06-09 19:47:10 +04:00
|
|
|
uint32_t fNumMatches;
|
|
|
|
uint32_t fNumMismatches;
|
|
|
|
uint32_t fMaxMismatchV;
|
|
|
|
float fMaxMismatchPercent;
|
|
|
|
|
2012-05-31 19:12:09 +04:00
|
|
|
FileArray fResultsOfType[kNumResultTypes];
|
2012-03-22 22:20:06 +04:00
|
|
|
|
2012-05-31 19:12:09 +04:00
|
|
|
// Print the contents of this FileArray, if any, to stdout.
|
|
|
|
// (If the FileArray is empty, print nothing.)
|
|
|
|
void printContents(const FileArray& fileArray, const char* headerText) {
|
|
|
|
int n = fileArray.count();
|
2012-03-22 22:20:06 +04:00
|
|
|
if (n > 0) {
|
2012-05-31 19:12:09 +04:00
|
|
|
printf("%s:\n", headerText);
|
2012-03-22 22:20:06 +04:00
|
|
|
for (int i = 0; i < n; ++i) {
|
2012-05-31 19:12:09 +04:00
|
|
|
printf("\t%s\n", fileArray[i]->c_str());
|
2012-03-22 22:20:06 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-31 19:12:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void print () {
|
|
|
|
printContents(fResultsOfType[kBaseMissing],
|
|
|
|
"Missing in baseDir");
|
|
|
|
printContents(fResultsOfType[kComparisonMissing],
|
|
|
|
"Missing in comparisonDir");
|
2011-06-09 19:47:10 +04:00
|
|
|
printf("%d of %d images matched.\n", fNumMatches,
|
|
|
|
fNumMatches + fNumMismatches);
|
|
|
|
if (fNumMismatches > 0) {
|
|
|
|
printf("Maximum pixel intensity mismatch %d\n", fMaxMismatchV);
|
|
|
|
printf("Largest area mismatch was %.2f%% of pixels\n",
|
|
|
|
fMaxMismatchPercent);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void add (DiffRecord* drp) {
|
2012-05-22 17:45:35 +04:00
|
|
|
uint32_t mismatchValue;
|
2012-05-16 18:57:28 +04:00
|
|
|
|
2012-05-31 19:12:09 +04:00
|
|
|
fResultsOfType[drp->fResult].push(new SkString(drp->fFilename));
|
2012-05-16 18:57:28 +04:00
|
|
|
switch (drp->fResult) {
|
2012-05-22 17:45:35 +04:00
|
|
|
case kEqualBits:
|
2012-05-16 18:57:28 +04:00
|
|
|
fNumMatches++;
|
|
|
|
break;
|
2012-05-22 17:45:35 +04:00
|
|
|
case kEqualPixels:
|
|
|
|
fNumMatches++;
|
2012-05-16 18:57:28 +04:00
|
|
|
break;
|
2012-05-22 17:45:35 +04:00
|
|
|
case kDifferentSizes:
|
2012-03-22 22:20:06 +04:00
|
|
|
fNumMismatches++;
|
2012-06-06 16:11:10 +04:00
|
|
|
drp->fFractionDifference = 2;// sort as if 200% of pixels differed
|
2012-05-16 18:57:28 +04:00
|
|
|
break;
|
2012-05-22 17:45:35 +04:00
|
|
|
case kDifferentPixels:
|
2011-06-09 19:47:10 +04:00
|
|
|
fNumMismatches++;
|
|
|
|
if (drp->fFractionDifference * 100 > fMaxMismatchPercent) {
|
|
|
|
fMaxMismatchPercent = drp->fFractionDifference * 100;
|
|
|
|
}
|
2012-05-22 17:45:35 +04:00
|
|
|
mismatchValue = MAX3(drp->fMaxMismatchR, drp->fMaxMismatchG,
|
|
|
|
drp->fMaxMismatchB);
|
|
|
|
if (mismatchValue > fMaxMismatchV) {
|
|
|
|
fMaxMismatchV = mismatchValue;
|
2011-06-09 19:47:10 +04:00
|
|
|
}
|
2012-05-16 18:57:28 +04:00
|
|
|
break;
|
2012-05-22 17:45:35 +04:00
|
|
|
case kDifferentOther:
|
|
|
|
fNumMismatches++;
|
2012-06-06 16:11:10 +04:00
|
|
|
drp->fFractionDifference = 3;// sort as if 300% of pixels differed
|
2012-05-22 17:45:35 +04:00
|
|
|
break;
|
|
|
|
case kBaseMissing:
|
|
|
|
fNumMismatches++;
|
|
|
|
break;
|
|
|
|
case kComparisonMissing:
|
|
|
|
fNumMismatches++;
|
|
|
|
break;
|
|
|
|
case kUnknown:
|
|
|
|
SkDEBUGFAIL("adding uncategorized DiffRecord");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkDEBUGFAIL("adding DiffRecord with unhandled fResult value");
|
|
|
|
break;
|
2011-06-09 19:47:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
typedef SkTDArray<DiffRecord*> RecordArray;
|
|
|
|
|
2011-06-09 19:47:10 +04:00
|
|
|
/// Comparison routine for qsort; sorts by fFractionDifference
|
2011-04-27 19:39:30 +04:00
|
|
|
/// from largest to smallest.
|
|
|
|
static int compare_diff_metrics (DiffRecord** lhs, DiffRecord** rhs) {
|
2011-06-09 19:47:10 +04:00
|
|
|
if ((*lhs)->fFractionDifference < (*rhs)->fFractionDifference) {
|
2011-04-27 19:39:30 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2011-06-09 19:47:10 +04:00
|
|
|
if ((*rhs)->fFractionDifference < (*lhs)->fFractionDifference) {
|
2011-05-24 23:41:13 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_diff_weighted (DiffRecord** lhs, DiffRecord** rhs) {
|
2011-06-09 19:47:10 +04:00
|
|
|
if ((*lhs)->fWeightedFraction < (*rhs)->fWeightedFraction) {
|
2011-05-24 23:41:13 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2011-06-09 19:47:10 +04:00
|
|
|
if ((*lhs)->fWeightedFraction > (*rhs)->fWeightedFraction) {
|
2011-04-27 19:39:30 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Comparison routine for qsort; sorts by max(fAverageMismatch{RGB})
|
|
|
|
/// from largest to smallest.
|
|
|
|
static int compare_diff_mean_mismatches (DiffRecord** lhs, DiffRecord** rhs) {
|
|
|
|
float leftValue = MAX3((*lhs)->fAverageMismatchR,
|
|
|
|
(*lhs)->fAverageMismatchG,
|
|
|
|
(*lhs)->fAverageMismatchB);
|
|
|
|
float rightValue = MAX3((*rhs)->fAverageMismatchR,
|
|
|
|
(*rhs)->fAverageMismatchG,
|
|
|
|
(*rhs)->fAverageMismatchB);
|
|
|
|
if (leftValue < rightValue) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (rightValue < leftValue) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Comparison routine for qsort; sorts by max(fMaxMismatch{RGB})
|
|
|
|
/// from largest to smallest.
|
|
|
|
static int compare_diff_max_mismatches (DiffRecord** lhs, DiffRecord** rhs) {
|
2011-10-08 00:03:39 +04:00
|
|
|
uint32_t leftValue = MAX3((*lhs)->fMaxMismatchR,
|
|
|
|
(*lhs)->fMaxMismatchG,
|
|
|
|
(*lhs)->fMaxMismatchB);
|
|
|
|
uint32_t rightValue = MAX3((*rhs)->fMaxMismatchR,
|
|
|
|
(*rhs)->fMaxMismatchG,
|
|
|
|
(*rhs)->fMaxMismatchB);
|
2011-04-27 19:39:30 +04:00
|
|
|
if (leftValue < rightValue) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (rightValue < leftValue) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return compare_diff_mean_mismatches(lhs, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Parameterized routine to compute the color of a pixel in a difference image.
|
|
|
|
typedef SkPMColor (*DiffMetricProc)(SkPMColor, SkPMColor);
|
|
|
|
|
2012-06-06 16:11:10 +04:00
|
|
|
#if 0 // UNUSED
|
2011-11-30 21:01:00 +04:00
|
|
|
static void expand_and_copy (int width, int height, SkBitmap** dest) {
|
|
|
|
SkBitmap* temp = new SkBitmap ();
|
|
|
|
temp->reset();
|
|
|
|
temp->setConfig((*dest)->config(), width, height);
|
|
|
|
temp->allocPixels();
|
|
|
|
(*dest)->copyPixelsTo(temp->getPixels(), temp->getSize(),
|
|
|
|
temp->rowBytes());
|
|
|
|
*dest = temp;
|
|
|
|
}
|
2012-06-06 16:11:10 +04:00
|
|
|
#endif
|
2011-11-30 21:01:00 +04:00
|
|
|
|
2012-05-22 17:45:35 +04:00
|
|
|
/// Returns true if the two buffers passed in are both non-NULL, and include
|
|
|
|
/// exactly the same byte values (and identical lengths).
|
|
|
|
static bool are_buffers_equal(SkData* skdata1, SkData* skdata2) {
|
|
|
|
if ((NULL == skdata1) || (NULL == skdata2)) {
|
2011-04-27 19:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-22 17:45:35 +04:00
|
|
|
if (skdata1->size() != skdata2->size()) {
|
2011-04-27 19:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-22 17:45:35 +04:00
|
|
|
return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reads the file at the given path and returns its complete contents as an
|
|
|
|
/// SkData object (or returns NULL on error).
|
|
|
|
static SkData* read_file(const char* file_path) {
|
|
|
|
SkFILEStream fileStream(file_path);
|
|
|
|
if (!fileStream.isValid()) {
|
|
|
|
SkDebugf("WARNING: could not open file <%s> for reading\n", file_path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
size_t bytesInFile = fileStream.getLength();
|
|
|
|
size_t bytesLeftToRead = bytesInFile;
|
|
|
|
|
|
|
|
void* bufferStart = sk_malloc_throw(bytesInFile);
|
|
|
|
char* bufferPointer = (char*)bufferStart;
|
|
|
|
while (bytesLeftToRead > 0) {
|
|
|
|
size_t bytesReadThisTime = fileStream.read(
|
|
|
|
bufferPointer, bytesLeftToRead);
|
|
|
|
if (0 == bytesReadThisTime) {
|
|
|
|
SkDebugf("WARNING: error reading from <%s>\n", file_path);
|
|
|
|
sk_free(bufferStart);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bytesLeftToRead -= bytesReadThisTime;
|
|
|
|
bufferPointer += bytesReadThisTime;
|
|
|
|
}
|
|
|
|
return SkData::NewFromMalloc(bufferStart, bytesInFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Decodes binary contents of baseFile and comparisonFile into
|
|
|
|
/// diffRecord->fBaseBitmap and diffRecord->fComparisonBitmap.
|
|
|
|
/// Returns true if that succeeds.
|
|
|
|
static bool get_bitmaps (SkData* baseFileContents,
|
|
|
|
SkData* comparisonFileContents,
|
|
|
|
DiffRecord* diffRecord) {
|
|
|
|
SkMemoryStream compareStream(comparisonFileContents->data(),
|
|
|
|
comparisonFileContents->size());
|
|
|
|
SkMemoryStream baseStream(baseFileContents->data(),
|
|
|
|
baseFileContents->size());
|
2011-04-27 19:39:30 +04:00
|
|
|
|
|
|
|
SkImageDecoder* codec = SkImageDecoder::Factory(&baseStream);
|
|
|
|
if (NULL == codec) {
|
2012-05-22 17:45:35 +04:00
|
|
|
SkDebugf("ERROR: no codec found for basePath <%s>\n",
|
2011-07-13 21:42:46 +04:00
|
|
|
diffRecord->fBasePath.c_str());
|
2011-04-27 19:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-30 21:01:00 +04:00
|
|
|
// In debug, the DLL will automatically be unloaded when this is deleted,
|
|
|
|
// but that shouldn't be a problem in release mode.
|
2011-04-27 19:39:30 +04:00
|
|
|
SkAutoTDelete<SkImageDecoder> ad(codec);
|
|
|
|
|
|
|
|
baseStream.rewind();
|
2011-08-02 18:10:04 +04:00
|
|
|
if (!codec->decode(&baseStream, diffRecord->fBaseBitmap,
|
2011-04-27 19:39:30 +04:00
|
|
|
SkBitmap::kARGB_8888_Config,
|
|
|
|
SkImageDecoder::kDecodePixels_Mode)) {
|
2012-05-22 17:45:35 +04:00
|
|
|
SkDebugf("ERROR: codec failed for basePath <%s>\n",
|
2011-07-13 21:42:46 +04:00
|
|
|
diffRecord->fBasePath.c_str());
|
2011-04-27 19:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-02 18:10:04 +04:00
|
|
|
diffRecord->fBaseWidth = diffRecord->fBaseBitmap->width();
|
|
|
|
diffRecord->fBaseHeight = diffRecord->fBaseBitmap->height();
|
|
|
|
|
|
|
|
if (!codec->decode(&compareStream, diffRecord->fComparisonBitmap,
|
2011-04-27 19:39:30 +04:00
|
|
|
SkBitmap::kARGB_8888_Config,
|
|
|
|
SkImageDecoder::kDecodePixels_Mode)) {
|
2012-05-22 17:45:35 +04:00
|
|
|
SkDebugf("ERROR: codec failed for comparisonPath <%s>\n",
|
2011-07-13 21:42:46 +04:00
|
|
|
diffRecord->fComparisonPath.c_str());
|
2011-04-27 19:39:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-22 22:20:06 +04:00
|
|
|
static bool get_bitmap_height_width(const SkString& path,
|
|
|
|
int *height, int *width) {
|
|
|
|
SkFILEStream stream(path.c_str());
|
|
|
|
if (!stream.isValid()) {
|
|
|
|
SkDebugf("ERROR: couldn't open file <%s>\n",
|
|
|
|
path.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
|
|
|
|
if (NULL == codec) {
|
|
|
|
SkDebugf("ERROR: no codec found for <%s>\n",
|
|
|
|
path.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTDelete<SkImageDecoder> ad(codec);
|
|
|
|
SkBitmap bm;
|
|
|
|
|
|
|
|
stream.rewind();
|
|
|
|
if (!codec->decode(&stream, &bm,
|
|
|
|
SkBitmap::kARGB_8888_Config,
|
|
|
|
SkImageDecoder::kDecodePixels_Mode)) {
|
|
|
|
SkDebugf("ERROR: codec failed for <%s>\n",
|
|
|
|
path.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*height = bm.height();
|
|
|
|
*width = bm.width();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
// from gm - thanks to PNG, we need to force all pixels 100% opaque
|
|
|
|
static void force_all_opaque(const SkBitmap& bitmap) {
|
|
|
|
SkAutoLockPixels lock(bitmap);
|
|
|
|
for (int y = 0; y < bitmap.height(); y++) {
|
|
|
|
for (int x = 0; x < bitmap.width(); x++) {
|
|
|
|
*bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// from gm
|
2011-08-02 18:10:04 +04:00
|
|
|
static bool write_bitmap(const SkString& path, const SkBitmap* bitmap) {
|
2011-04-27 19:39:30 +04:00
|
|
|
SkBitmap copy;
|
2011-08-02 18:10:04 +04:00
|
|
|
bitmap->copyTo(©, SkBitmap::kARGB_8888_Config);
|
2011-04-27 19:39:30 +04:00
|
|
|
force_all_opaque(copy);
|
|
|
|
return SkImageEncoder::EncodeFile(path.c_str(), copy,
|
|
|
|
SkImageEncoder::kPNG_Type, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
// from gm
|
|
|
|
static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) {
|
|
|
|
int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
|
|
|
|
int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
|
|
|
|
int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
|
|
|
|
|
|
|
|
return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool colors_match_thresholded(SkPMColor c0, SkPMColor c1,
|
|
|
|
const int threshold) {
|
|
|
|
int da = SkGetPackedA32(c0) - SkGetPackedA32(c1);
|
|
|
|
int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
|
|
|
|
int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
|
|
|
|
int db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
|
|
|
|
|
|
|
|
return ((SkAbs32(da) <= threshold) &&
|
|
|
|
(SkAbs32(dr) <= threshold) &&
|
|
|
|
(SkAbs32(dg) <= threshold) &&
|
|
|
|
(SkAbs32(db) <= threshold));
|
|
|
|
}
|
|
|
|
|
|
|
|
// based on gm
|
2012-05-16 21:40:57 +04:00
|
|
|
// Postcondition: when we exit this method, dr->fResult should have some value
|
|
|
|
// other than kUnknown.
|
2011-04-27 19:39:30 +04:00
|
|
|
static void compute_diff(DiffRecord* dr,
|
|
|
|
DiffMetricProc diffFunction,
|
|
|
|
const int colorThreshold) {
|
2012-02-03 00:50:36 +04:00
|
|
|
SkAutoLockPixels alpDiff(*dr->fDifferenceBitmap);
|
|
|
|
SkAutoLockPixels alpWhite(*dr->fWhiteBitmap);
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2011-08-02 18:10:04 +04:00
|
|
|
const int w = dr->fComparisonBitmap->width();
|
|
|
|
const int h = dr->fComparisonBitmap->height();
|
2011-04-27 19:39:30 +04:00
|
|
|
int mismatchedPixels = 0;
|
|
|
|
int totalMismatchR = 0;
|
|
|
|
int totalMismatchG = 0;
|
|
|
|
int totalMismatchB = 0;
|
2011-11-30 21:01:00 +04:00
|
|
|
|
|
|
|
if (w != dr->fBaseWidth || h != dr->fBaseHeight) {
|
2012-05-16 18:57:28 +04:00
|
|
|
dr->fResult = kDifferentSizes;
|
2011-11-30 21:01:00 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-05-24 23:41:13 +04:00
|
|
|
// Accumulate fractionally different pixels, then divide out
|
|
|
|
// # of pixels at the end.
|
2011-06-09 19:47:10 +04:00
|
|
|
dr->fWeightedFraction = 0;
|
2011-04-27 19:39:30 +04:00
|
|
|
for (int y = 0; y < h; y++) {
|
|
|
|
for (int x = 0; x < w; x++) {
|
2011-08-02 18:10:04 +04:00
|
|
|
SkPMColor c0 = *dr->fBaseBitmap->getAddr32(x, y);
|
|
|
|
SkPMColor c1 = *dr->fComparisonBitmap->getAddr32(x, y);
|
2011-06-09 19:47:10 +04:00
|
|
|
SkPMColor trueDifference = compute_diff_pmcolor(c0, c1);
|
|
|
|
SkPMColor outputDifference = diffFunction(c0, c1);
|
|
|
|
uint32_t thisR = SkGetPackedR32(trueDifference);
|
|
|
|
uint32_t thisG = SkGetPackedG32(trueDifference);
|
|
|
|
uint32_t thisB = SkGetPackedB32(trueDifference);
|
2011-05-24 23:41:13 +04:00
|
|
|
totalMismatchR += thisR;
|
|
|
|
totalMismatchG += thisG;
|
|
|
|
totalMismatchB += thisB;
|
|
|
|
// In HSV, value is defined as max RGB component.
|
|
|
|
int value = MAX3(thisR, thisG, thisB);
|
2011-06-09 19:47:10 +04:00
|
|
|
dr->fWeightedFraction += ((float) value) / 255;
|
2011-05-24 23:41:13 +04:00
|
|
|
if (thisR > dr->fMaxMismatchR) {
|
|
|
|
dr->fMaxMismatchR = thisR;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2011-05-24 23:41:13 +04:00
|
|
|
if (thisG > dr->fMaxMismatchG) {
|
|
|
|
dr->fMaxMismatchG = thisG;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2011-05-24 23:41:13 +04:00
|
|
|
if (thisB > dr->fMaxMismatchB) {
|
|
|
|
dr->fMaxMismatchB = thisB;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
if (!colors_match_thresholded(c0, c1, colorThreshold)) {
|
|
|
|
mismatchedPixels++;
|
2011-08-02 18:10:04 +04:00
|
|
|
*dr->fDifferenceBitmap->getAddr32(x, y) = outputDifference;
|
2012-02-03 00:50:36 +04:00
|
|
|
*dr->fWhiteBitmap->getAddr32(x, y) = PMCOLOR_WHITE;
|
2011-04-27 19:39:30 +04:00
|
|
|
} else {
|
2011-08-02 18:10:04 +04:00
|
|
|
*dr->fDifferenceBitmap->getAddr32(x, y) = 0;
|
2012-02-03 00:50:36 +04:00
|
|
|
*dr->fWhiteBitmap->getAddr32(x, y) = PMCOLOR_BLACK;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-16 18:57:28 +04:00
|
|
|
if (0 == mismatchedPixels) {
|
|
|
|
dr->fResult = kEqualPixels;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dr->fResult = kDifferentPixels;
|
2011-05-24 23:41:13 +04:00
|
|
|
int pixelCount = w * h;
|
2011-06-09 19:47:10 +04:00
|
|
|
dr->fFractionDifference = ((float) mismatchedPixels) / pixelCount;
|
|
|
|
dr->fWeightedFraction /= pixelCount;
|
2011-05-24 23:41:13 +04:00
|
|
|
dr->fAverageMismatchR = ((float) totalMismatchR) / pixelCount;
|
|
|
|
dr->fAverageMismatchG = ((float) totalMismatchG) / pixelCount;
|
|
|
|
dr->fAverageMismatchB = ((float) totalMismatchB) / pixelCount;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
|
2012-02-03 00:50:36 +04:00
|
|
|
static SkString filename_to_derived_filename (const SkString& filename,
|
|
|
|
const char *suffix) {
|
2011-06-09 19:47:10 +04:00
|
|
|
SkString diffName (filename);
|
|
|
|
const char* cstring = diffName.c_str();
|
|
|
|
int dotOffset = strrchr(cstring, '.') - cstring;
|
|
|
|
diffName.remove(dotOffset, diffName.size() - dotOffset);
|
2012-02-03 00:50:36 +04:00
|
|
|
diffName.append(suffix);
|
2011-06-09 19:47:10 +04:00
|
|
|
return diffName;
|
|
|
|
}
|
|
|
|
|
2012-02-03 00:50:36 +04:00
|
|
|
/// Given a image filename, returns the name of the file containing the
|
|
|
|
/// associated difference image.
|
|
|
|
static SkString filename_to_diff_filename (const SkString& filename) {
|
|
|
|
return filename_to_derived_filename(filename, "-diff.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a image filename, returns the name of the file containing the
|
|
|
|
/// "white" difference image.
|
|
|
|
static SkString filename_to_white_filename (const SkString& filename) {
|
|
|
|
return filename_to_derived_filename(filename, "-white.png");
|
|
|
|
}
|
|
|
|
|
2011-08-02 18:10:04 +04:00
|
|
|
static void release_bitmaps(DiffRecord* drp) {
|
|
|
|
delete drp->fBaseBitmap;
|
|
|
|
drp->fBaseBitmap = NULL;
|
|
|
|
delete drp->fComparisonBitmap;
|
|
|
|
drp->fComparisonBitmap = NULL;
|
|
|
|
delete drp->fDifferenceBitmap;
|
|
|
|
drp->fDifferenceBitmap = NULL;
|
2012-02-03 00:50:36 +04:00
|
|
|
delete drp->fWhiteBitmap;
|
|
|
|
drp->fWhiteBitmap = NULL;
|
2011-08-02 18:10:04 +04:00
|
|
|
}
|
|
|
|
|
2011-07-14 17:15:55 +04:00
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
/// If outputDir.isEmpty(), don't write out diff files.
|
2011-07-14 17:15:55 +04:00
|
|
|
static void create_and_write_diff_image(DiffRecord* drp,
|
|
|
|
DiffMetricProc dmp,
|
|
|
|
const int colorThreshold,
|
|
|
|
const SkString& outputDir,
|
|
|
|
const SkString& filename) {
|
2011-08-02 18:10:04 +04:00
|
|
|
const int w = drp->fBaseWidth;
|
|
|
|
const int h = drp->fBaseHeight;
|
|
|
|
drp->fDifferenceBitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h);
|
|
|
|
drp->fDifferenceBitmap->allocPixels();
|
2012-02-03 00:50:36 +04:00
|
|
|
drp->fWhiteBitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h);
|
|
|
|
drp->fWhiteBitmap->allocPixels();
|
2012-05-16 21:40:57 +04:00
|
|
|
|
|
|
|
SkASSERT(kUnknown == drp->fResult);
|
2011-07-13 21:42:46 +04:00
|
|
|
compute_diff(drp, dmp, colorThreshold);
|
2012-05-16 21:40:57 +04:00
|
|
|
SkASSERT(kUnknown != drp->fResult);
|
2011-07-14 17:15:55 +04:00
|
|
|
|
2012-05-16 21:40:57 +04:00
|
|
|
if ((kDifferentPixels == drp->fResult) && !outputDir.isEmpty()) {
|
2012-05-01 17:26:16 +04:00
|
|
|
SkString differencePath (outputDir);
|
|
|
|
differencePath.append(filename_to_diff_filename(filename));
|
|
|
|
write_bitmap(differencePath, drp->fDifferenceBitmap);
|
|
|
|
SkString whitePath (outputDir);
|
|
|
|
whitePath.append(filename_to_white_filename(filename));
|
|
|
|
write_bitmap(whitePath, drp->fWhiteBitmap);
|
|
|
|
}
|
2012-05-16 21:40:57 +04:00
|
|
|
|
2011-08-02 18:10:04 +04:00
|
|
|
release_bitmaps(drp);
|
2011-07-13 21:42:46 +04:00
|
|
|
}
|
|
|
|
|
2012-05-01 17:26:16 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Iterate over dir and get all files that:
|
|
|
|
/// - match any of the substrings in matchSubstrings, but...
|
|
|
|
/// - DO NOT match any of the substrings in nomatchSubstrings
|
|
|
|
/// Returns the list of files in *files.
|
|
|
|
static void get_file_list(const SkString& dir,
|
|
|
|
const StringArray& matchSubstrings,
|
|
|
|
const StringArray& nomatchSubstrings,
|
|
|
|
FileArray *files) {
|
2012-03-22 22:20:06 +04:00
|
|
|
SkOSFile::Iter it(dir.c_str());
|
|
|
|
SkString filename;
|
|
|
|
while (it.next(&filename)) {
|
2012-05-01 17:26:16 +04:00
|
|
|
if (string_contains_any_of(filename, matchSubstrings) &&
|
|
|
|
!string_contains_any_of(filename, nomatchSubstrings)) {
|
|
|
|
files->push(new SkString(filename));
|
2012-03-22 22:20:06 +04: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());
|
|
|
|
}
|
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
/// Creates difference images, returns the number that have a 0 metric.
|
2012-05-01 17:26:16 +04:00
|
|
|
/// If outputDir.isEmpty(), don't write out diff files.
|
2011-06-09 19:47:10 +04: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 17:26:16 +04:00
|
|
|
const StringArray& matchSubstrings,
|
|
|
|
const StringArray& nomatchSubstrings,
|
2011-06-09 19:47:10 +04:00
|
|
|
DiffSummary* summary) {
|
2012-05-01 17:26:16 +04:00
|
|
|
SkASSERT(!baseDir.isEmpty());
|
|
|
|
SkASSERT(!comparisonDir.isEmpty());
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2012-03-22 22:20:06 +04:00
|
|
|
FileArray baseFiles;
|
|
|
|
FileArray comparisonFiles;
|
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
get_file_list(baseDir, matchSubstrings, nomatchSubstrings, &baseFiles);
|
|
|
|
get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings,
|
|
|
|
&comparisonFiles);
|
2012-03-22 22:20:06 +04:00
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
if (!baseFiles.isEmpty()) {
|
2012-05-07 18:52:12 +04:00
|
|
|
qsort(baseFiles.begin(), baseFiles.count(), sizeof(SkString*),
|
|
|
|
SkCastForQSort(compare_file_name_metrics));
|
2012-05-01 17:26:16 +04:00
|
|
|
}
|
|
|
|
if (!comparisonFiles.isEmpty()) {
|
2012-05-07 18:52:12 +04:00
|
|
|
qsort(comparisonFiles.begin(), comparisonFiles.count(),
|
|
|
|
sizeof(SkString*), SkCastForQSort(compare_file_name_metrics));
|
2012-05-01 17:26:16 +04:00
|
|
|
}
|
2012-05-16 21:40:57 +04:00
|
|
|
|
2012-03-22 22:20:06 +04:00
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
while (i < baseFiles.count() &&
|
|
|
|
j < comparisonFiles.count()) {
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2011-07-13 21:42:46 +04:00
|
|
|
SkString basePath (baseDir);
|
2012-03-22 22:20:06 +04:00
|
|
|
basePath.append(*baseFiles[i]);
|
2011-07-14 17:15:55 +04:00
|
|
|
SkString comparisonPath (comparisonDir);
|
2012-03-22 22:20:06 +04:00
|
|
|
comparisonPath.append(*comparisonFiles[j]);
|
|
|
|
|
|
|
|
DiffRecord *drp = NULL;
|
|
|
|
int v = strcmp(baseFiles[i]->c_str(),
|
|
|
|
comparisonFiles[j]->c_str());
|
|
|
|
|
|
|
|
if (v < 0) {
|
|
|
|
// in baseDir, but not in comparisonDir
|
2012-05-16 18:57:28 +04:00
|
|
|
drp = new DiffRecord(*baseFiles[i], basePath, comparisonPath,
|
|
|
|
kComparisonMissing);
|
2012-03-22 22:20:06 +04:00
|
|
|
++i;
|
|
|
|
} else if (v > 0) {
|
|
|
|
// in comparisonDir, but not in baseDir
|
2012-05-16 18:57:28 +04:00
|
|
|
drp = new DiffRecord(*comparisonFiles[j], basePath, comparisonPath,
|
|
|
|
kBaseMissing);
|
2012-03-22 22:20:06 +04:00
|
|
|
++j;
|
|
|
|
} else {
|
2012-05-22 17:45:35 +04:00
|
|
|
// Found the same filename in both baseDir and comparisonDir.
|
2012-03-22 22:20:06 +04:00
|
|
|
drp = new DiffRecord(*baseFiles[i], basePath, comparisonPath);
|
2012-05-22 17:45:35 +04:00
|
|
|
SkASSERT(kUnknown == drp->fResult);
|
|
|
|
|
|
|
|
SkData* baseFileBits;
|
|
|
|
SkData* comparisonFileBits;
|
|
|
|
if (NULL == (baseFileBits = read_file(basePath.c_str()))) {
|
|
|
|
SkDebugf("WARNING: couldn't read base file <%s>\n",
|
|
|
|
basePath.c_str());
|
|
|
|
drp->fResult = kBaseMissing;
|
|
|
|
} else if (NULL == (comparisonFileBits = read_file(
|
|
|
|
comparisonPath.c_str()))) {
|
|
|
|
SkDebugf("WARNING: couldn't read comparison file <%s>\n",
|
|
|
|
comparisonPath.c_str());
|
|
|
|
drp->fResult = kComparisonMissing;
|
|
|
|
} else {
|
|
|
|
if (are_buffers_equal(baseFileBits, comparisonFileBits)) {
|
|
|
|
drp->fResult = kEqualBits;
|
|
|
|
} else if (get_bitmaps(baseFileBits, comparisonFileBits, drp)) {
|
|
|
|
create_and_write_diff_image(drp, dmp, colorThreshold,
|
|
|
|
outputDir, *baseFiles[i]);
|
|
|
|
} else {
|
|
|
|
drp->fResult = kDifferentOther;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (baseFileBits) {
|
|
|
|
baseFileBits->unref();
|
|
|
|
}
|
|
|
|
if (comparisonFileBits) {
|
|
|
|
comparisonFileBits->unref();
|
2012-03-22 22:20:06 +04:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
++j;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2012-05-22 17:45:35 +04:00
|
|
|
SkASSERT(kUnknown != drp->fResult);
|
2012-03-22 22:20:06 +04:00
|
|
|
differences->push(drp);
|
|
|
|
summary->add(drp);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < baseFiles.count(); ++i) {
|
|
|
|
// files only in baseDir
|
|
|
|
SkString basePath (baseDir);
|
|
|
|
basePath.append(*baseFiles[i]);
|
|
|
|
SkString comparisonPath;
|
|
|
|
DiffRecord *drp = new DiffRecord(*baseFiles[i], basePath,
|
2012-05-16 18:57:28 +04:00
|
|
|
comparisonPath, kComparisonMissing);
|
2012-03-22 22:20:06 +04:00
|
|
|
differences->push(drp);
|
|
|
|
summary->add(drp);
|
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2012-03-22 22:20:06 +04:00
|
|
|
for (; j < comparisonFiles.count(); ++j) {
|
|
|
|
// files only in comparisonDir
|
|
|
|
SkString basePath;
|
|
|
|
SkString comparisonPath(comparisonDir);
|
|
|
|
comparisonPath.append(*comparisonFiles[j]);
|
|
|
|
DiffRecord *drp = new DiffRecord(*comparisonFiles[j], basePath,
|
2012-05-16 18:57:28 +04:00
|
|
|
comparisonPath, kBaseMissing);
|
2011-04-27 19:39:30 +04:00
|
|
|
differences->push(drp);
|
2011-06-09 19:47:10 +04:00
|
|
|
summary->add(drp);
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2012-03-22 22:20:06 +04:00
|
|
|
|
|
|
|
release_file_list(&baseFiles);
|
|
|
|
release_file_list(&comparisonFiles);
|
2011-07-14 17:15:55 +04:00
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
|
|
|
|
/// Make layout more consistent by scaling image to 240 height, 360 width,
|
|
|
|
/// or natural size, whichever is smallest.
|
2011-08-02 18:10:04 +04:00
|
|
|
static int compute_image_height (int height, int width) {
|
2011-04-27 19:39:30 +04:00
|
|
|
int retval = 240;
|
2011-08-02 18:10:04 +04:00
|
|
|
if (height < retval) {
|
|
|
|
retval = height;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2011-08-02 18:10:04 +04:00
|
|
|
float scale = (float) retval / height;
|
|
|
|
if (width * scale > 360) {
|
|
|
|
scale = (float) 360 / width;
|
2011-10-08 00:03:39 +04:00
|
|
|
retval = static_cast<int>(height * scale);
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-02-03 00:50:36 +04:00
|
|
|
static void print_table_header (SkFILEWStream* stream,
|
|
|
|
const int matchCount,
|
|
|
|
const int colorThreshold,
|
|
|
|
const RecordArray& differences,
|
|
|
|
const SkString &baseDir,
|
2012-05-15 18:58:53 +04:00
|
|
|
const SkString &comparisonDir,
|
|
|
|
bool doOutputDate=false) {
|
2012-02-03 00:50:36 +04:00
|
|
|
stream->writeText("<table>\n");
|
|
|
|
stream->writeText("<tr><th>");
|
2012-05-15 18:58:53 +04:00
|
|
|
if (doOutputDate) {
|
|
|
|
SkTime::DateTime dt;
|
|
|
|
SkTime::GetDateTime(&dt);
|
|
|
|
stream->writeText("SkDiff run at ");
|
|
|
|
stream->writeDecAsText(dt.fHour);
|
|
|
|
stream->writeText(":");
|
|
|
|
if (dt.fMinute < 10) {
|
|
|
|
stream->writeText("0");
|
|
|
|
}
|
|
|
|
stream->writeDecAsText(dt.fMinute);
|
|
|
|
stream->writeText(":");
|
|
|
|
if (dt.fSecond < 10) {
|
|
|
|
stream->writeText("0");
|
|
|
|
}
|
|
|
|
stream->writeDecAsText(dt.fSecond);
|
|
|
|
stream->writeText("<br>");
|
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
stream->writeDecAsText(matchCount);
|
|
|
|
stream->writeText(" of ");
|
|
|
|
stream->writeDecAsText(differences.count());
|
|
|
|
stream->writeText(" images matched ");
|
|
|
|
if (colorThreshold == 0) {
|
|
|
|
stream->writeText("exactly");
|
|
|
|
} else {
|
|
|
|
stream->writeText("within ");
|
|
|
|
stream->writeDecAsText(colorThreshold);
|
|
|
|
stream->writeText(" color units per component");
|
|
|
|
}
|
|
|
|
stream->writeText(".<br>");
|
2012-02-03 00:50:36 +04:00
|
|
|
stream->writeText("</th>\n<th>");
|
|
|
|
stream->writeText("every different pixel shown in white");
|
|
|
|
stream->writeText("</th>\n<th>");
|
|
|
|
stream->writeText("color difference at each pixel");
|
|
|
|
stream->writeText("</th>\n<th>");
|
|
|
|
stream->writeText(baseDir.c_str());
|
|
|
|
stream->writeText("</th>\n<th>");
|
|
|
|
stream->writeText(comparisonDir.c_str());
|
|
|
|
stream->writeText("</th>\n");
|
|
|
|
stream->writeText("</tr>\n");
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_pixel_count (SkFILEWStream* stream,
|
|
|
|
const DiffRecord& diff) {
|
|
|
|
stream->writeText("<br>(");
|
2011-10-08 00:03:39 +04:00
|
|
|
stream->writeDecAsText(static_cast<int>(diff.fFractionDifference *
|
|
|
|
diff.fBaseWidth *
|
|
|
|
diff.fBaseHeight));
|
2011-04-27 19:39:30 +04:00
|
|
|
stream->writeText(" pixels)");
|
2011-05-24 23:41:13 +04:00
|
|
|
/*
|
2011-06-09 19:47:10 +04:00
|
|
|
stream->writeDecAsText(diff.fWeightedFraction *
|
2011-08-02 18:10:04 +04:00
|
|
|
diff.fBaseWidth *
|
|
|
|
diff.fBaseHeight);
|
2011-05-24 23:41:13 +04:00
|
|
|
stream->writeText(" weighted pixels)");
|
|
|
|
*/
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_label_cell (SkFILEWStream* stream,
|
|
|
|
const DiffRecord& diff) {
|
2012-05-22 17:45:35 +04:00
|
|
|
char metricBuf [20];
|
|
|
|
|
|
|
|
stream->writeText("<td><b>");
|
2011-04-27 19:39:30 +04:00
|
|
|
stream->writeText(diff.fFilename.c_str());
|
2012-05-22 17:45:35 +04:00
|
|
|
stream->writeText("</b><br>");
|
2012-05-16 18:57:28 +04:00
|
|
|
switch (diff.fResult) {
|
2012-05-22 17:45:35 +04:00
|
|
|
case kEqualBits:
|
|
|
|
SkDEBUGFAIL("should not encounter DiffRecord with kEqualBits here");
|
|
|
|
return;
|
|
|
|
case kEqualPixels:
|
|
|
|
SkDEBUGFAIL("should not encounter DiffRecord with kEqualPixels here");
|
2012-03-22 22:20:06 +04:00
|
|
|
return;
|
2012-05-16 18:57:28 +04:00
|
|
|
case kDifferentSizes:
|
2012-05-22 17:45:35 +04:00
|
|
|
stream->writeText("Image sizes differ</td>");
|
|
|
|
return;
|
|
|
|
case kDifferentPixels:
|
|
|
|
sprintf(metricBuf, "%12.4f%%", 100 * diff.fFractionDifference);
|
|
|
|
stream->writeText(metricBuf);
|
|
|
|
stream->writeText(" of pixels differ");
|
|
|
|
stream->writeText("\n (");
|
|
|
|
sprintf(metricBuf, "%12.4f%%", 100 * diff.fWeightedFraction);
|
|
|
|
stream->writeText(metricBuf);
|
|
|
|
stream->writeText(" weighted)");
|
|
|
|
// Write the actual number of pixels that differ if it's < 1%
|
|
|
|
if (diff.fFractionDifference < 0.01) {
|
|
|
|
print_pixel_count(stream, diff);
|
|
|
|
}
|
|
|
|
stream->writeText("<br>Average color mismatch ");
|
|
|
|
stream->writeDecAsText(static_cast<int>(MAX3(diff.fAverageMismatchR,
|
|
|
|
diff.fAverageMismatchG,
|
|
|
|
diff.fAverageMismatchB)));
|
|
|
|
stream->writeText("<br>Max color mismatch ");
|
|
|
|
stream->writeDecAsText(MAX3(diff.fMaxMismatchR,
|
|
|
|
diff.fMaxMismatchG,
|
|
|
|
diff.fMaxMismatchB));
|
2011-11-30 21:01:00 +04:00
|
|
|
stream->writeText("</td>");
|
2012-05-22 17:45:35 +04:00
|
|
|
break;
|
|
|
|
case kDifferentOther:
|
|
|
|
stream->writeText("Files differ; unable to parse one or both files</td>");
|
|
|
|
return;
|
|
|
|
case kBaseMissing:
|
|
|
|
stream->writeText("Missing from baseDir</td>");
|
|
|
|
return;
|
|
|
|
case kComparisonMissing:
|
|
|
|
stream->writeText("Missing from comparisonDir</td>");
|
2011-11-30 21:01:00 +04:00
|
|
|
return;
|
2012-05-16 18:57:28 +04:00
|
|
|
default:
|
2012-05-22 17:45:35 +04:00
|
|
|
SkDEBUGFAIL("encountered DiffRecord with unknown result type");
|
|
|
|
return;
|
2011-11-30 21:01:00 +04:00
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_image_cell (SkFILEWStream* stream,
|
2011-07-13 21:42:46 +04:00
|
|
|
const SkString& path,
|
2011-04-27 19:39:30 +04:00
|
|
|
int height) {
|
|
|
|
stream->writeText("<td><a href=\"");
|
2011-07-13 21:42:46 +04:00
|
|
|
stream->writeText(path.c_str());
|
2011-04-27 19:39:30 +04:00
|
|
|
stream->writeText("\"><img src=\"");
|
2011-07-13 21:42:46 +04:00
|
|
|
stream->writeText(path.c_str());
|
2011-04-27 19:39:30 +04:00
|
|
|
stream->writeText("\" height=\"");
|
|
|
|
stream->writeDecAsText(height);
|
|
|
|
stream->writeText("px\"></a></td>");
|
|
|
|
}
|
|
|
|
|
2012-06-06 16:11:10 +04:00
|
|
|
#if 0 // UNUSED
|
2012-04-12 20:32:04 +04:00
|
|
|
static void print_text_cell (SkFILEWStream* stream, const char* text) {
|
|
|
|
stream->writeText("<td align=center>");
|
|
|
|
if (NULL != text) {
|
|
|
|
stream->writeText(text);
|
|
|
|
}
|
|
|
|
stream->writeText("</td>");
|
|
|
|
}
|
2012-06-06 16:11:10 +04:00
|
|
|
#endif
|
2012-04-12 20:32:04 +04:00
|
|
|
|
2012-03-22 22:20:06 +04:00
|
|
|
static void print_diff_with_missing_file(SkFILEWStream* stream,
|
|
|
|
DiffRecord& diff,
|
|
|
|
const SkString& relativePath) {
|
|
|
|
stream->writeText("<tr>\n");
|
|
|
|
print_label_cell(stream, diff);
|
|
|
|
stream->writeText("<td>N/A</td>");
|
|
|
|
stream->writeText("<td>N/A</td>");
|
2012-05-16 18:57:28 +04:00
|
|
|
if (kBaseMissing != diff.fResult) {
|
2012-03-22 22:20:06 +04:00
|
|
|
int h, w;
|
|
|
|
if (!get_bitmap_height_width(diff.fBasePath, &h, &w)) {
|
|
|
|
stream->writeText("<td>N/A</td>");
|
|
|
|
} else {
|
|
|
|
int height = compute_image_height(h, w);
|
|
|
|
if (!diff.fBasePath.startsWith(PATH_DIV_STR)) {
|
|
|
|
diff.fBasePath.prepend(relativePath);
|
|
|
|
}
|
|
|
|
print_image_cell(stream, diff.fBasePath, height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->writeText("<td>N/A</td>");
|
|
|
|
}
|
2012-05-16 18:57:28 +04:00
|
|
|
if (kComparisonMissing != diff.fResult) {
|
2012-03-22 22:20:06 +04:00
|
|
|
int h, w;
|
|
|
|
if (!get_bitmap_height_width(diff.fComparisonPath, &h, &w)) {
|
|
|
|
stream->writeText("<td>N/A</td>");
|
|
|
|
} else {
|
|
|
|
int height = compute_image_height(h, w);
|
|
|
|
if (!diff.fComparisonPath.startsWith(PATH_DIV_STR)) {
|
|
|
|
diff.fComparisonPath.prepend(relativePath);
|
|
|
|
}
|
|
|
|
print_image_cell(stream, diff.fComparisonPath, height);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stream->writeText("<td>N/A</td>");
|
|
|
|
}
|
|
|
|
stream->writeText("</tr>\n");
|
|
|
|
stream->flush();
|
|
|
|
}
|
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
static void print_diff_page (const int matchCount,
|
|
|
|
const int colorThreshold,
|
|
|
|
const RecordArray& differences,
|
|
|
|
const SkString& baseDir,
|
|
|
|
const SkString& comparisonDir,
|
|
|
|
const SkString& outputDir) {
|
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
SkASSERT(!baseDir.isEmpty());
|
|
|
|
SkASSERT(!comparisonDir.isEmpty());
|
|
|
|
SkASSERT(!outputDir.isEmpty());
|
|
|
|
|
2011-05-24 23:41:13 +04:00
|
|
|
SkString outputPath (outputDir);
|
|
|
|
outputPath.append("index.html");
|
|
|
|
//SkFILEWStream outputStream ("index.html");
|
|
|
|
SkFILEWStream outputStream (outputPath.c_str());
|
|
|
|
|
2011-07-13 21:42:46 +04:00
|
|
|
// Need to convert paths from relative-to-cwd to relative-to-outputDir
|
2011-05-24 23:41:13 +04:00
|
|
|
// FIXME this doesn't work if there are '..' inside the outputDir
|
|
|
|
unsigned int ui;
|
|
|
|
SkString relativePath;
|
|
|
|
for (ui = 0; ui < outputDir.size(); ui++) {
|
2011-09-23 18:56:37 +04:00
|
|
|
if (outputDir[ui] == PATH_DIV_CHAR) {
|
|
|
|
relativePath.append(".." PATH_DIV_STR);
|
2011-05-24 23:41:13 +04:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
|
|
|
|
outputStream.writeText("<html>\n<body>\n");
|
2012-02-03 00:50:36 +04:00
|
|
|
print_table_header(&outputStream, matchCount, colorThreshold, differences,
|
|
|
|
baseDir, comparisonDir);
|
2011-04-27 19:39:30 +04:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < differences.count(); i++) {
|
|
|
|
DiffRecord* diff = differences[i];
|
2012-03-22 22:20:06 +04:00
|
|
|
|
2012-05-16 18:57:28 +04:00
|
|
|
switch (diff->fResult) {
|
2012-05-22 17:45:35 +04:00
|
|
|
// Cases in which there is no diff to report.
|
|
|
|
case kEqualBits:
|
2012-05-16 18:57:28 +04:00
|
|
|
case kEqualPixels:
|
2012-03-22 22:20:06 +04:00
|
|
|
continue;
|
2012-05-22 17:45:35 +04:00
|
|
|
// Cases in which we want a detailed pixel diff.
|
|
|
|
case kDifferentPixels:
|
|
|
|
break;
|
|
|
|
// Cases in which the files differed, but we can't display the diff.
|
|
|
|
case kDifferentSizes:
|
|
|
|
case kDifferentOther:
|
2012-05-16 18:57:28 +04:00
|
|
|
case kBaseMissing:
|
|
|
|
case kComparisonMissing:
|
|
|
|
print_diff_with_missing_file(&outputStream, *diff, relativePath);
|
2011-04-27 19:39:30 +04:00
|
|
|
continue;
|
2012-05-16 18:57:28 +04:00
|
|
|
default:
|
2012-05-22 17:45:35 +04:00
|
|
|
SkDEBUGFAIL("encountered DiffRecord with unknown result type");
|
|
|
|
continue;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2012-03-22 22:20:06 +04:00
|
|
|
|
2011-09-23 18:56:37 +04:00
|
|
|
if (!diff->fBasePath.startsWith(PATH_DIV_STR)) {
|
2011-07-13 21:42:46 +04:00
|
|
|
diff->fBasePath.prepend(relativePath);
|
|
|
|
}
|
2011-09-23 18:56:37 +04:00
|
|
|
if (!diff->fComparisonPath.startsWith(PATH_DIV_STR)) {
|
2011-07-13 21:42:46 +04:00
|
|
|
diff->fComparisonPath.prepend(relativePath);
|
|
|
|
}
|
2012-03-22 22:20:06 +04:00
|
|
|
|
2011-08-02 18:10:04 +04:00
|
|
|
int height = compute_image_height(diff->fBaseHeight, diff->fBaseWidth);
|
2011-04-27 19:39:30 +04:00
|
|
|
outputStream.writeText("<tr>\n");
|
|
|
|
print_label_cell(&outputStream, *diff);
|
2012-05-22 17:45:35 +04:00
|
|
|
print_image_cell(&outputStream,
|
|
|
|
filename_to_white_filename(diff->fFilename), height);
|
|
|
|
print_image_cell(&outputStream,
|
|
|
|
filename_to_diff_filename(diff->fFilename), height);
|
2012-02-03 00:50:36 +04:00
|
|
|
print_image_cell(&outputStream, diff->fBasePath, height);
|
2011-07-13 21:42:46 +04:00
|
|
|
print_image_cell(&outputStream, diff->fComparisonPath, height);
|
2011-04-27 19:39:30 +04:00
|
|
|
outputStream.writeText("</tr>\n");
|
|
|
|
outputStream.flush();
|
|
|
|
}
|
|
|
|
outputStream.writeText("</table>\n");
|
|
|
|
outputStream.writeText("</body>\n</html>\n");
|
|
|
|
outputStream.flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usage (char * argv0) {
|
|
|
|
SkDebugf("Skia baseline image diff tool\n");
|
2012-05-01 17:26:16 +04:00
|
|
|
SkDebugf("\n"
|
|
|
|
"Usage: \n"
|
|
|
|
" %s <baseDir> <comparisonDir> [outputDir] \n"
|
2012-05-19 00:10:06 +04:00
|
|
|
, argv0, argv0);
|
2012-05-01 17:26:16 +04:00
|
|
|
SkDebugf("\n"
|
|
|
|
"Arguments: \n"
|
|
|
|
" --nodiffs: don't write out image diffs or index.html, just generate \n"
|
|
|
|
" report on stdout \n"
|
|
|
|
" --threshold <n>: only report differences > n (per color channel) [default 0]\n"
|
|
|
|
" --match: compare files whose filenames contain this substring; if \n"
|
|
|
|
" unspecified, compare ALL files. \n"
|
|
|
|
" this flag may be repeated to add more matching substrings. \n"
|
|
|
|
" --nomatch: regardless of --match, DO NOT compare files whose filenames \n"
|
|
|
|
" contain this substring. \n"
|
|
|
|
" this flag may be repeated to add more forbidden substrings. \n"
|
2011-07-14 17:15:55 +04:00
|
|
|
" --sortbymismatch: sort by average color channel mismatch\n");
|
2011-04-27 19:39:30 +04:00
|
|
|
SkDebugf(
|
2012-05-01 17:26:16 +04:00
|
|
|
" --sortbymaxmismatch: sort by worst color channel mismatch;\n"
|
|
|
|
" break ties with -sortbymismatch\n"
|
|
|
|
" [default sort is by fraction of pixels mismatching]\n");
|
2011-05-24 23:41:13 +04:00
|
|
|
SkDebugf(
|
2011-07-14 17:15:55 +04:00
|
|
|
" --weighted: sort by # pixels different weighted by color difference\n");
|
|
|
|
SkDebugf(
|
2012-05-19 00:10:06 +04:00
|
|
|
" baseDir: directory to read baseline images from.\n");
|
2011-06-09 19:47:10 +04:00
|
|
|
SkDebugf(
|
2012-05-01 17:26:16 +04:00
|
|
|
" comparisonDir: directory to read comparison images from\n");
|
|
|
|
SkDebugf(
|
|
|
|
" outputDir: directory to write difference images and index.html to; \n"
|
2012-05-19 00:10:06 +04:00
|
|
|
" defaults to comparisonDir \n");
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char ** argv) {
|
|
|
|
DiffMetricProc diffProc = compute_diff_pmcolor;
|
2012-05-07 18:52:12 +04:00
|
|
|
int (*sortProc)(const void*, const void*) = SkCastForQSort(compare_diff_metrics);
|
2011-04-27 19:39:30 +04: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-05-01 17:26:16 +04:00
|
|
|
StringArray matchSubstrings;
|
|
|
|
StringArray nomatchSubstrings;
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
bool generateDiffs = true;
|
2011-07-14 17:15:55 +04:00
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
RecordArray differences;
|
2011-06-09 19:47:10 +04:00
|
|
|
DiffSummary summary;
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
int i;
|
|
|
|
int numUnflaggedArguments = 0;
|
|
|
|
for (i = 1; i < argc; i++) {
|
2011-07-14 17:15:55 +04:00
|
|
|
if (!strcmp(argv[i], "--help")) {
|
2011-04-27 19:39:30 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-05-01 17:26:16 +04:00
|
|
|
if (!strcmp(argv[i], "--nodiffs")) {
|
|
|
|
generateDiffs = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--threshold")) {
|
|
|
|
colorThreshold = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--match")) {
|
|
|
|
matchSubstrings.push(new SkString(argv[++i]));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "--nomatch")) {
|
|
|
|
nomatchSubstrings.push(new SkString(argv[++i]));
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-14 17:15:55 +04:00
|
|
|
if (!strcmp(argv[i], "--sortbymismatch")) {
|
2012-05-07 18:52:12 +04:00
|
|
|
sortProc = SkCastForQSort(compare_diff_mean_mismatches);
|
2011-04-27 19:39:30 +04:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-14 17:15:55 +04:00
|
|
|
if (!strcmp(argv[i], "--sortbymaxmismatch")) {
|
2012-05-07 18:52:12 +04:00
|
|
|
sortProc = SkCastForQSort(compare_diff_max_mismatches);
|
2011-04-27 19:39:30 +04:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-14 17:15:55 +04:00
|
|
|
if (!strcmp(argv[i], "--weighted")) {
|
2012-05-07 18:52:12 +04:00
|
|
|
sortProc = SkCastForQSort(compare_diff_weighted);
|
2011-05-24 23:41:13 +04:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
if (argv[i][0] != '-') {
|
2012-05-01 17:26:16 +04:00
|
|
|
switch (numUnflaggedArguments++) {
|
2011-04-27 19:39:30 +04: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 17:26:16 +04:00
|
|
|
SkDebugf("extra unflagged argument <%s>\n", argv[i]);
|
2011-04-27 19:39:30 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugf("Unrecognized argument <%s>\n", argv[i]);
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-05-01 17:26:16 +04:00
|
|
|
|
|
|
|
if (numUnflaggedArguments == 2) {
|
2011-06-09 19:47:10 +04:00
|
|
|
outputDir = comparisonDir;
|
2012-05-01 17:26:16 +04:00
|
|
|
} else if (numUnflaggedArguments != 3) {
|
2011-06-09 19:47:10 +04:00
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
|
|
|
|
2011-09-23 18:56:37 +04:00
|
|
|
if (!baseDir.endsWith(PATH_DIV_STR)) {
|
|
|
|
baseDir.append(PATH_DIV_STR);
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2012-05-01 17:26:16 +04:00
|
|
|
printf("baseDir is [%s]\n", baseDir.c_str());
|
|
|
|
|
2011-09-23 18:56:37 +04:00
|
|
|
if (!comparisonDir.endsWith(PATH_DIV_STR)) {
|
|
|
|
comparisonDir.append(PATH_DIV_STR);
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2012-05-01 17:26:16 +04:00
|
|
|
printf("comparisonDir is [%s]\n", comparisonDir.c_str());
|
|
|
|
|
2011-09-23 18:56:37 +04:00
|
|
|
if (!outputDir.endsWith(PATH_DIV_STR)) {
|
|
|
|
outputDir.append(PATH_DIV_STR);
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|
2012-05-01 17:26:16 +04:00
|
|
|
if (generateDiffs) {
|
|
|
|
printf("writing diffs to outputDir is [%s]\n", outputDir.c_str());
|
|
|
|
} else {
|
|
|
|
printf("not writing any diffs to outputDir [%s]\n", outputDir.c_str());
|
|
|
|
outputDir.set("");
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:45:50 +04:00
|
|
|
// If no matchSubstrings were specified, match ALL strings
|
|
|
|
// (except for whatever nomatchSubstrings were specified, if any).
|
2012-05-01 17:26:16 +04:00
|
|
|
if (matchSubstrings.isEmpty()) {
|
|
|
|
matchSubstrings.push(new SkString(""));
|
|
|
|
}
|
2011-04-27 19:39:30 +04:00
|
|
|
|
2012-05-19 00:10:06 +04:00
|
|
|
create_diff_images(diffProc, colorThreshold, &differences,
|
|
|
|
baseDir, comparisonDir, outputDir,
|
|
|
|
matchSubstrings, nomatchSubstrings, &summary);
|
2011-06-09 19:47:10 +04:00
|
|
|
summary.print();
|
2011-07-14 17:15:55 +04:00
|
|
|
|
|
|
|
if (differences.count()) {
|
2012-05-07 18:52:12 +04:00
|
|
|
qsort(differences.begin(), differences.count(),
|
|
|
|
sizeof(DiffRecord*), sortProc);
|
2011-07-14 17:15:55 +04:00
|
|
|
}
|
2012-05-16 21:40:57 +04:00
|
|
|
|
2012-05-01 17:26:16 +04:00
|
|
|
if (generateDiffs) {
|
|
|
|
print_diff_page(summary.fNumMatches, colorThreshold, differences,
|
|
|
|
baseDir, comparisonDir, outputDir);
|
|
|
|
}
|
2012-05-31 19:12:09 +04:00
|
|
|
|
2011-04-27 19:39:30 +04:00
|
|
|
for (i = 0; i < differences.count(); i++) {
|
|
|
|
delete differences[i];
|
|
|
|
}
|
2012-05-01 17:26:16 +04:00
|
|
|
matchSubstrings.deleteAll();
|
|
|
|
nomatchSubstrings.deleteAll();
|
2012-05-31 19:13:45 +04:00
|
|
|
|
|
|
|
return summary.fNumMismatches;
|
2011-04-27 19:39:30 +04:00
|
|
|
}
|