| epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 8 | #include "SkColorPriv.h" |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 9 | #include "SkData.h" |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 10 | #include "SkImageDecoder.h" |
| 11 | #include "SkImageEncoder.h" |
| 12 | #include "SkOSFile.h" |
| 13 | #include "SkStream.h" |
| 14 | #include "SkTDArray.h" |
| 15 | #include "SkTemplates.h" |
| 16 | #include "SkTime.h" |
| 17 | #include "SkTSearch.h" |
| 18 | #include "SkTypes.h" |
| 19 | |
| 20 | /** |
| 21 | * skdiff |
| 22 | * |
| 23 | * Given three directory names, expects to find identically-named files in |
| 24 | * each of the first two; the first are treated as a set of baseline, |
| 25 | * the second a set of variant images, and a diff image is written into the |
| 26 | * third directory for each pair. |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 27 | * Creates an index.html in the current third directory to compare each |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 28 | * pair that does not match exactly. |
| 29 | * Does *not* recursively descend directories. |
| epoger@google.com | be6188d | 2012-05-31 15:13:45 +0000 | [diff] [blame] | 30 | * |
| 31 | * Returns zero exit code if all images match across baseDir and comparisonDir. |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 32 | */ |
| 33 | |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 34 | #if SK_BUILD_FOR_WIN32 |
| 35 | #define PATH_DIV_STR "\\" |
| 36 | #define PATH_DIV_CHAR '\\' |
| 37 | #else |
| 38 | #define PATH_DIV_STR "/" |
| 39 | #define PATH_DIV_CHAR '/' |
| 40 | #endif |
| 41 | |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 42 | // Result of comparison for each pair of files. |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 43 | // Listed from "better" to "worse", for sorting of results. |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 44 | enum Result { |
| 45 | kEqualBits, // both files in the pair contain exactly the same bits |
| 46 | kEqualPixels, // not bitwise equal, but their pixels are exactly the same |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 47 | kDifferentPixels,// both are images we can parse, but with different pixels |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 48 | kDifferentSizes, // both are images we can parse, but of different sizes |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 49 | kDifferentOther, // files have different bits but are not parsable images |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 50 | kComparisonMissing,// missing from comparisonDir |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 51 | kBaseMissing, // missing from baseDir |
| epoger@google.com | 76222c0 | 2012-05-31 15:12:09 +0000 | [diff] [blame] | 52 | kUnknown, // not compared yet |
| 53 | // |
| 54 | kNumResultTypes // NOT A VALID VALUE--used to set up arrays. Must be last. |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 57 | struct DiffRecord { |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 58 | DiffRecord (const SkString filename, |
| 59 | const SkString basePath, |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 60 | const SkString comparisonPath, |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 61 | const Result result = kUnknown) |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 62 | : fFilename (filename) |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 63 | , fBasePath (basePath) |
| 64 | , fComparisonPath (comparisonPath) |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 65 | , fBaseBitmap (new SkBitmap ()) |
| 66 | , fComparisonBitmap (new SkBitmap ()) |
| 67 | , fDifferenceBitmap (new SkBitmap ()) |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 68 | , fWhiteBitmap (new SkBitmap ()) |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 69 | , fBaseHeight (0) |
| 70 | , fBaseWidth (0) |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 71 | , fFractionDifference (0) |
| 72 | , fWeightedFraction (0) |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 73 | , fAverageMismatchR (0) |
| 74 | , fAverageMismatchG (0) |
| 75 | , fAverageMismatchB (0) |
| 76 | , fMaxMismatchR (0) |
| 77 | , fMaxMismatchG (0) |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 78 | , fMaxMismatchB (0) |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 79 | , fResult(result) { |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 80 | }; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 81 | |
| 82 | SkString fFilename; |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 83 | SkString fBasePath; |
| 84 | SkString fComparisonPath; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 85 | |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 86 | SkBitmap* fBaseBitmap; |
| 87 | SkBitmap* fComparisonBitmap; |
| 88 | SkBitmap* fDifferenceBitmap; |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 89 | SkBitmap* fWhiteBitmap; |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 90 | |
| 91 | int fBaseHeight; |
| 92 | int fBaseWidth; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 93 | |
| 94 | /// Arbitrary floating-point metric to be used to sort images from most |
| 95 | /// to least different from baseline; values of 0 will be omitted from the |
| 96 | /// summary webpage. |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 97 | float fFractionDifference; |
| 98 | float fWeightedFraction; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 99 | |
| 100 | float fAverageMismatchR; |
| 101 | float fAverageMismatchG; |
| 102 | float fAverageMismatchB; |
| 103 | |
| 104 | uint32_t fMaxMismatchR; |
| 105 | uint32_t fMaxMismatchG; |
| 106 | uint32_t fMaxMismatchB; |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 107 | |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 108 | /// Which category of diff result. |
| 109 | Result fResult; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 112 | #define MAX2(a,b) (((b) < (a)) ? (a) : (b)) |
| 113 | #define MAX3(a,b,c) (((b) < (a)) ? MAX2((a), (c)) : MAX2((b), (c))) |
| 114 | |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 115 | const SkPMColor PMCOLOR_WHITE = SkPreMultiplyColor(SK_ColorWHITE); |
| 116 | const SkPMColor PMCOLOR_BLACK = SkPreMultiplyColor(SK_ColorBLACK); |
| 117 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 118 | typedef SkTDArray<SkString*> StringArray; |
| 119 | typedef StringArray FileArray; |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 120 | |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 121 | struct DiffSummary { |
| 122 | DiffSummary () |
| 123 | : fNumMatches (0) |
| 124 | , fNumMismatches (0) |
| 125 | , fMaxMismatchV (0) |
| 126 | , fMaxMismatchPercent (0) { }; |
| 127 | |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 128 | ~DiffSummary() { |
| epoger@google.com | 76222c0 | 2012-05-31 15:12:09 +0000 | [diff] [blame] | 129 | for (int i = 0; i < kNumResultTypes; i++) { |
| 130 | fResultsOfType[i].deleteAll(); |
| 131 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 134 | uint32_t fNumMatches; |
| 135 | uint32_t fNumMismatches; |
| 136 | uint32_t fMaxMismatchV; |
| 137 | float fMaxMismatchPercent; |
| 138 | |
| epoger@google.com | 76222c0 | 2012-05-31 15:12:09 +0000 | [diff] [blame] | 139 | FileArray fResultsOfType[kNumResultTypes]; |
| 140 | |
| 141 | // Print the contents of this FileArray, if any, to stdout. |
| 142 | // (If the FileArray is empty, print nothing.) |
| 143 | void printContents(const FileArray& fileArray, const char* headerText) { |
| 144 | int n = fileArray.count(); |
| 145 | if (n > 0) { |
| 146 | printf("%s:\n", headerText); |
| 147 | for (int i = 0; i < n; ++i) { |
| 148 | printf("\t%s\n", fileArray[i]->c_str()); |
| 149 | } |
| 150 | } |
| 151 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 152 | |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 153 | void print () { |
| epoger@google.com | 76222c0 | 2012-05-31 15:12:09 +0000 | [diff] [blame] | 154 | printContents(fResultsOfType[kBaseMissing], |
| 155 | "Missing in baseDir"); |
| 156 | printContents(fResultsOfType[kComparisonMissing], |
| 157 | "Missing in comparisonDir"); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 158 | printf("%d of %d images matched.\n", fNumMatches, |
| 159 | fNumMatches + fNumMismatches); |
| 160 | if (fNumMismatches > 0) { |
| 161 | printf("Maximum pixel intensity mismatch %d\n", fMaxMismatchV); |
| 162 | printf("Largest area mismatch was %.2f%% of pixels\n", |
| 163 | fMaxMismatchPercent); |
| 164 | } |
| 165 | |
| 166 | } |
| 167 | |
| 168 | void add (DiffRecord* drp) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 169 | uint32_t mismatchValue; |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 170 | |
| epoger@google.com | 76222c0 | 2012-05-31 15:12:09 +0000 | [diff] [blame] | 171 | fResultsOfType[drp->fResult].push(new SkString(drp->fFilename)); |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 172 | switch (drp->fResult) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 173 | case kEqualBits: |
| 174 | fNumMatches++; |
| 175 | break; |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 176 | case kEqualPixels: |
| 177 | fNumMatches++; |
| 178 | break; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 179 | case kDifferentSizes: |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 180 | fNumMismatches++; |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 181 | break; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 182 | case kDifferentPixels: |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 183 | fNumMismatches++; |
| 184 | if (drp->fFractionDifference * 100 > fMaxMismatchPercent) { |
| 185 | fMaxMismatchPercent = drp->fFractionDifference * 100; |
| 186 | } |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 187 | mismatchValue = MAX3(drp->fMaxMismatchR, drp->fMaxMismatchG, |
| 188 | drp->fMaxMismatchB); |
| 189 | if (mismatchValue > fMaxMismatchV) { |
| 190 | fMaxMismatchV = mismatchValue; |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 191 | } |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 192 | break; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 193 | case kDifferentOther: |
| 194 | fNumMismatches++; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 195 | break; |
| 196 | case kBaseMissing: |
| 197 | fNumMismatches++; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 198 | break; |
| 199 | case kComparisonMissing: |
| 200 | fNumMismatches++; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 201 | break; |
| 202 | case kUnknown: |
| 203 | SkDEBUGFAIL("adding uncategorized DiffRecord"); |
| 204 | break; |
| 205 | default: |
| 206 | SkDEBUGFAIL("adding DiffRecord with unhandled fResult value"); |
| 207 | break; |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | }; |
| 211 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 212 | typedef SkTDArray<DiffRecord*> RecordArray; |
| 213 | |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 214 | /// A wrapper for any sortProc (comparison routine) which applies a first-order |
| 215 | /// sort beforehand, and a tiebreaker if the sortProc returns 0. |
| 216 | template<typename T> |
| 217 | static int compare(const void* untyped_lhs, const void* untyped_rhs) { |
| 218 | const DiffRecord* lhs = *reinterpret_cast<DiffRecord* const*>(untyped_lhs); |
| 219 | const DiffRecord* rhs = *reinterpret_cast<DiffRecord* const*>(untyped_rhs); |
| 220 | |
| 221 | // First-order sort... these comparisons should be applied before comparing |
| 222 | // pixel values, no matter what. |
| 223 | if (lhs->fResult != rhs->fResult) { |
| 224 | return (lhs->fResult < rhs->fResult) ? 1 : -1; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 225 | } |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 226 | |
| 227 | // Passed first-order sort, so call the pixel comparison routine. |
| 228 | int result = T::comparePixels(lhs, rhs); |
| 229 | if (result != 0) { |
| 230 | return result; |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 231 | } |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 232 | |
| 233 | // Tiebreaker... if we got to this point, we don't really care |
| 234 | // which order they are sorted in, but let's at least be consistent. |
| 235 | return strcmp(lhs->fFilename.c_str(), rhs->fFilename.c_str()); |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 238 | /// Comparison routine for qsort; sorts by fFractionDifference |
| 239 | /// from largest to smallest. |
| 240 | class CompareDiffMetrics { |
| 241 | public: |
| 242 | static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) { |
| 243 | if (lhs->fFractionDifference < rhs->fFractionDifference) { |
| 244 | return 1; |
| 245 | } |
| 246 | if (rhs->fFractionDifference < lhs->fFractionDifference) { |
| 247 | return -1; |
| 248 | } |
| 249 | return 0; |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 250 | } |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | class CompareDiffWeighted { |
| 254 | public: |
| 255 | static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) { |
| 256 | if (lhs->fWeightedFraction < rhs->fWeightedFraction) { |
| 257 | return 1; |
| 258 | } |
| 259 | if (lhs->fWeightedFraction > rhs->fWeightedFraction) { |
| 260 | return -1; |
| 261 | } |
| 262 | return 0; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 263 | } |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 264 | }; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 265 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 266 | /// Comparison routine for qsort; sorts by max(fAverageMismatch{RGB}) |
| 267 | /// from largest to smallest. |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 268 | class CompareDiffMeanMismatches { |
| 269 | public: |
| 270 | static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) { |
| 271 | float leftValue = MAX3(lhs->fAverageMismatchR, |
| 272 | lhs->fAverageMismatchG, |
| 273 | lhs->fAverageMismatchB); |
| 274 | float rightValue = MAX3(rhs->fAverageMismatchR, |
| 275 | rhs->fAverageMismatchG, |
| 276 | rhs->fAverageMismatchB); |
| 277 | if (leftValue < rightValue) { |
| 278 | return 1; |
| 279 | } |
| 280 | if (rightValue < leftValue) { |
| 281 | return -1; |
| 282 | } |
| 283 | return 0; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 284 | } |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 285 | }; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 286 | |
| 287 | /// Comparison routine for qsort; sorts by max(fMaxMismatch{RGB}) |
| 288 | /// from largest to smallest. |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 289 | class CompareDiffMaxMismatches { |
| 290 | public: |
| 291 | static int comparePixels(const DiffRecord* lhs, const DiffRecord* rhs) { |
| 292 | uint32_t leftValue = MAX3(lhs->fMaxMismatchR, |
| 293 | lhs->fMaxMismatchG, |
| 294 | lhs->fMaxMismatchB); |
| 295 | uint32_t rightValue = MAX3(rhs->fMaxMismatchR, |
| 296 | rhs->fMaxMismatchG, |
| 297 | rhs->fMaxMismatchB); |
| 298 | if (leftValue < rightValue) { |
| 299 | return 1; |
| 300 | } |
| 301 | if (rightValue < leftValue) { |
| 302 | return -1; |
| 303 | } |
| 304 | |
| 305 | return CompareDiffMeanMismatches::comparePixels(lhs, rhs); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 306 | } |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 307 | }; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 308 | |
| 309 | |
| 310 | |
| 311 | /// Parameterized routine to compute the color of a pixel in a difference image. |
| 312 | typedef SkPMColor (*DiffMetricProc)(SkPMColor, SkPMColor); |
| 313 | |
| caryclark@google.com | 3dd4591 | 2012-06-06 12:11:10 +0000 | [diff] [blame] | 314 | #if 0 // UNUSED |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 315 | static void expand_and_copy (int width, int height, SkBitmap** dest) { |
| 316 | SkBitmap* temp = new SkBitmap (); |
| 317 | temp->reset(); |
| 318 | temp->setConfig((*dest)->config(), width, height); |
| 319 | temp->allocPixels(); |
| 320 | (*dest)->copyPixelsTo(temp->getPixels(), temp->getSize(), |
| 321 | temp->rowBytes()); |
| 322 | *dest = temp; |
| 323 | } |
| caryclark@google.com | 3dd4591 | 2012-06-06 12:11:10 +0000 | [diff] [blame] | 324 | #endif |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 325 | |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 326 | /// Returns true if the two buffers passed in are both non-NULL, and include |
| 327 | /// exactly the same byte values (and identical lengths). |
| 328 | static bool are_buffers_equal(SkData* skdata1, SkData* skdata2) { |
| 329 | if ((NULL == skdata1) || (NULL == skdata2)) { |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 330 | return false; |
| 331 | } |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 332 | if (skdata1->size() != skdata2->size()) { |
| 333 | return false; |
| 334 | } |
| 335 | return (0 == memcmp(skdata1->data(), skdata2->data(), skdata1->size())); |
| 336 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 337 | |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 338 | /// Reads the file at the given path and returns its complete contents as an |
| 339 | /// SkData object (or returns NULL on error). |
| 340 | static SkData* read_file(const char* file_path) { |
| 341 | SkFILEStream fileStream(file_path); |
| 342 | if (!fileStream.isValid()) { |
| 343 | SkDebugf("WARNING: could not open file <%s> for reading\n", file_path); |
| 344 | return NULL; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 345 | } |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 346 | size_t bytesInFile = fileStream.getLength(); |
| 347 | size_t bytesLeftToRead = bytesInFile; |
| 348 | |
| 349 | void* bufferStart = sk_malloc_throw(bytesInFile); |
| 350 | char* bufferPointer = (char*)bufferStart; |
| 351 | while (bytesLeftToRead > 0) { |
| 352 | size_t bytesReadThisTime = fileStream.read( |
| 353 | bufferPointer, bytesLeftToRead); |
| 354 | if (0 == bytesReadThisTime) { |
| 355 | SkDebugf("WARNING: error reading from <%s>\n", file_path); |
| 356 | sk_free(bufferStart); |
| 357 | return NULL; |
| 358 | } |
| 359 | bytesLeftToRead -= bytesReadThisTime; |
| 360 | bufferPointer += bytesReadThisTime; |
| 361 | } |
| 362 | return SkData::NewFromMalloc(bufferStart, bytesInFile); |
| 363 | } |
| 364 | |
| 365 | /// Decodes binary contents of baseFile and comparisonFile into |
| 366 | /// diffRecord->fBaseBitmap and diffRecord->fComparisonBitmap. |
| 367 | /// Returns true if that succeeds. |
| 368 | static bool get_bitmaps (SkData* baseFileContents, |
| 369 | SkData* comparisonFileContents, |
| 370 | DiffRecord* diffRecord) { |
| 371 | SkMemoryStream compareStream(comparisonFileContents->data(), |
| 372 | comparisonFileContents->size()); |
| 373 | SkMemoryStream baseStream(baseFileContents->data(), |
| 374 | baseFileContents->size()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 375 | |
| 376 | SkImageDecoder* codec = SkImageDecoder::Factory(&baseStream); |
| 377 | if (NULL == codec) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 378 | SkDebugf("ERROR: no codec found for basePath <%s>\n", |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 379 | diffRecord->fBasePath.c_str()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 380 | return false; |
| 381 | } |
| 382 | |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 383 | // In debug, the DLL will automatically be unloaded when this is deleted, |
| 384 | // but that shouldn't be a problem in release mode. |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 385 | SkAutoTDelete<SkImageDecoder> ad(codec); |
| 386 | |
| 387 | baseStream.rewind(); |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 388 | if (!codec->decode(&baseStream, diffRecord->fBaseBitmap, |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 389 | SkBitmap::kARGB_8888_Config, |
| 390 | SkImageDecoder::kDecodePixels_Mode)) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 391 | SkDebugf("ERROR: codec failed for basePath <%s>\n", |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 392 | diffRecord->fBasePath.c_str()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 393 | return false; |
| 394 | } |
| 395 | |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 396 | diffRecord->fBaseWidth = diffRecord->fBaseBitmap->width(); |
| 397 | diffRecord->fBaseHeight = diffRecord->fBaseBitmap->height(); |
| 398 | |
| 399 | if (!codec->decode(&compareStream, diffRecord->fComparisonBitmap, |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 400 | SkBitmap::kARGB_8888_Config, |
| 401 | SkImageDecoder::kDecodePixels_Mode)) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 402 | SkDebugf("ERROR: codec failed for comparisonPath <%s>\n", |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 403 | diffRecord->fComparisonPath.c_str()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 404 | return false; |
| 405 | } |
| 406 | |
| 407 | return true; |
| 408 | } |
| 409 | |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 410 | static bool get_bitmap_height_width(const SkString& path, |
| 411 | int *height, int *width) { |
| 412 | SkFILEStream stream(path.c_str()); |
| 413 | if (!stream.isValid()) { |
| 414 | SkDebugf("ERROR: couldn't open file <%s>\n", |
| 415 | path.c_str()); |
| 416 | return false; |
| 417 | } |
| 418 | |
| 419 | SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
| 420 | if (NULL == codec) { |
| 421 | SkDebugf("ERROR: no codec found for <%s>\n", |
| 422 | path.c_str()); |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | SkAutoTDelete<SkImageDecoder> ad(codec); |
| 427 | SkBitmap bm; |
| 428 | |
| 429 | stream.rewind(); |
| 430 | if (!codec->decode(&stream, &bm, |
| 431 | SkBitmap::kARGB_8888_Config, |
| 432 | SkImageDecoder::kDecodePixels_Mode)) { |
| 433 | SkDebugf("ERROR: codec failed for <%s>\n", |
| 434 | path.c_str()); |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | *height = bm.height(); |
| 439 | *width = bm.width(); |
| 440 | |
| 441 | return true; |
| 442 | } |
| 443 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 444 | // from gm - thanks to PNG, we need to force all pixels 100% opaque |
| 445 | static void force_all_opaque(const SkBitmap& bitmap) { |
| 446 | SkAutoLockPixels lock(bitmap); |
| 447 | for (int y = 0; y < bitmap.height(); y++) { |
| 448 | for (int x = 0; x < bitmap.width(); x++) { |
| 449 | *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | // from gm |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 455 | static bool write_bitmap(const SkString& path, const SkBitmap* bitmap) { |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 456 | SkBitmap copy; |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 457 | bitmap->copyTo(©, SkBitmap::kARGB_8888_Config); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 458 | force_all_opaque(copy); |
| 459 | return SkImageEncoder::EncodeFile(path.c_str(), copy, |
| 460 | SkImageEncoder::kPNG_Type, 100); |
| 461 | } |
| 462 | |
| 463 | // from gm |
| 464 | static inline SkPMColor compute_diff_pmcolor(SkPMColor c0, SkPMColor c1) { |
| 465 | int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1); |
| 466 | int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1); |
| 467 | int db = SkGetPackedB32(c0) - SkGetPackedB32(c1); |
| 468 | |
| 469 | return SkPackARGB32(0xFF, SkAbs32(dr), SkAbs32(dg), SkAbs32(db)); |
| 470 | } |
| 471 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 472 | static inline bool colors_match_thresholded(SkPMColor c0, SkPMColor c1, |
| 473 | const int threshold) { |
| 474 | int da = SkGetPackedA32(c0) - SkGetPackedA32(c1); |
| 475 | int dr = SkGetPackedR32(c0) - SkGetPackedR32(c1); |
| 476 | int dg = SkGetPackedG32(c0) - SkGetPackedG32(c1); |
| 477 | int db = SkGetPackedB32(c0) - SkGetPackedB32(c1); |
| 478 | |
| 479 | return ((SkAbs32(da) <= threshold) && |
| 480 | (SkAbs32(dr) <= threshold) && |
| 481 | (SkAbs32(dg) <= threshold) && |
| 482 | (SkAbs32(db) <= threshold)); |
| 483 | } |
| 484 | |
| 485 | // based on gm |
| epoger@google.com | 6600852 | 2012-05-16 17:40:57 +0000 | [diff] [blame] | 486 | // Postcondition: when we exit this method, dr->fResult should have some value |
| 487 | // other than kUnknown. |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 488 | static void compute_diff(DiffRecord* dr, |
| 489 | DiffMetricProc diffFunction, |
| 490 | const int colorThreshold) { |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 491 | SkAutoLockPixels alpDiff(*dr->fDifferenceBitmap); |
| 492 | SkAutoLockPixels alpWhite(*dr->fWhiteBitmap); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 493 | |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 494 | const int w = dr->fComparisonBitmap->width(); |
| 495 | const int h = dr->fComparisonBitmap->height(); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 496 | int mismatchedPixels = 0; |
| 497 | int totalMismatchR = 0; |
| 498 | int totalMismatchG = 0; |
| 499 | int totalMismatchB = 0; |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 500 | |
| 501 | if (w != dr->fBaseWidth || h != dr->fBaseHeight) { |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 502 | dr->fResult = kDifferentSizes; |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 503 | return; |
| 504 | } |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 505 | // Accumulate fractionally different pixels, then divide out |
| 506 | // # of pixels at the end. |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 507 | dr->fWeightedFraction = 0; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 508 | for (int y = 0; y < h; y++) { |
| 509 | for (int x = 0; x < w; x++) { |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 510 | SkPMColor c0 = *dr->fBaseBitmap->getAddr32(x, y); |
| 511 | SkPMColor c1 = *dr->fComparisonBitmap->getAddr32(x, y); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 512 | SkPMColor trueDifference = compute_diff_pmcolor(c0, c1); |
| 513 | SkPMColor outputDifference = diffFunction(c0, c1); |
| 514 | uint32_t thisR = SkGetPackedR32(trueDifference); |
| 515 | uint32_t thisG = SkGetPackedG32(trueDifference); |
| 516 | uint32_t thisB = SkGetPackedB32(trueDifference); |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 517 | totalMismatchR += thisR; |
| 518 | totalMismatchG += thisG; |
| 519 | totalMismatchB += thisB; |
| 520 | // In HSV, value is defined as max RGB component. |
| 521 | int value = MAX3(thisR, thisG, thisB); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 522 | dr->fWeightedFraction += ((float) value) / 255; |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 523 | if (thisR > dr->fMaxMismatchR) { |
| 524 | dr->fMaxMismatchR = thisR; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 525 | } |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 526 | if (thisG > dr->fMaxMismatchG) { |
| 527 | dr->fMaxMismatchG = thisG; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 528 | } |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 529 | if (thisB > dr->fMaxMismatchB) { |
| 530 | dr->fMaxMismatchB = thisB; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 531 | } |
| 532 | if (!colors_match_thresholded(c0, c1, colorThreshold)) { |
| 533 | mismatchedPixels++; |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 534 | *dr->fDifferenceBitmap->getAddr32(x, y) = outputDifference; |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 535 | *dr->fWhiteBitmap->getAddr32(x, y) = PMCOLOR_WHITE; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 536 | } else { |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 537 | *dr->fDifferenceBitmap->getAddr32(x, y) = 0; |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 538 | *dr->fWhiteBitmap->getAddr32(x, y) = PMCOLOR_BLACK; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | } |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 542 | if (0 == mismatchedPixels) { |
| 543 | dr->fResult = kEqualPixels; |
| 544 | return; |
| 545 | } |
| 546 | dr->fResult = kDifferentPixels; |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 547 | int pixelCount = w * h; |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 548 | dr->fFractionDifference = ((float) mismatchedPixels) / pixelCount; |
| 549 | dr->fWeightedFraction /= pixelCount; |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 550 | dr->fAverageMismatchR = ((float) totalMismatchR) / pixelCount; |
| 551 | dr->fAverageMismatchG = ((float) totalMismatchG) / pixelCount; |
| 552 | dr->fAverageMismatchB = ((float) totalMismatchB) / pixelCount; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 555 | static SkString filename_to_derived_filename (const SkString& filename, |
| 556 | const char *suffix) { |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 557 | SkString diffName (filename); |
| 558 | const char* cstring = diffName.c_str(); |
| 559 | int dotOffset = strrchr(cstring, '.') - cstring; |
| 560 | diffName.remove(dotOffset, diffName.size() - dotOffset); |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 561 | diffName.append(suffix); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 562 | return diffName; |
| 563 | } |
| 564 | |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 565 | /// Given a image filename, returns the name of the file containing the |
| 566 | /// associated difference image. |
| 567 | static SkString filename_to_diff_filename (const SkString& filename) { |
| 568 | return filename_to_derived_filename(filename, "-diff.png"); |
| 569 | } |
| 570 | |
| 571 | /// Given a image filename, returns the name of the file containing the |
| 572 | /// "white" difference image. |
| 573 | static SkString filename_to_white_filename (const SkString& filename) { |
| 574 | return filename_to_derived_filename(filename, "-white.png"); |
| 575 | } |
| 576 | |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 577 | static void release_bitmaps(DiffRecord* drp) { |
| 578 | delete drp->fBaseBitmap; |
| 579 | drp->fBaseBitmap = NULL; |
| 580 | delete drp->fComparisonBitmap; |
| 581 | drp->fComparisonBitmap = NULL; |
| 582 | delete drp->fDifferenceBitmap; |
| 583 | drp->fDifferenceBitmap = NULL; |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 584 | delete drp->fWhiteBitmap; |
| 585 | drp->fWhiteBitmap = NULL; |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 588 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 589 | /// If outputDir.isEmpty(), don't write out diff files. |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 590 | static void create_and_write_diff_image(DiffRecord* drp, |
| 591 | DiffMetricProc dmp, |
| 592 | const int colorThreshold, |
| 593 | const SkString& outputDir, |
| 594 | const SkString& filename) { |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 595 | const int w = drp->fBaseWidth; |
| 596 | const int h = drp->fBaseHeight; |
| 597 | drp->fDifferenceBitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 598 | drp->fDifferenceBitmap->allocPixels(); |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 599 | drp->fWhiteBitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 600 | drp->fWhiteBitmap->allocPixels(); |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 601 | |
| epoger@google.com | 6600852 | 2012-05-16 17:40:57 +0000 | [diff] [blame] | 602 | SkASSERT(kUnknown == drp->fResult); |
| 603 | compute_diff(drp, dmp, colorThreshold); |
| 604 | SkASSERT(kUnknown != drp->fResult); |
| 605 | |
| 606 | if ((kDifferentPixels == drp->fResult) && !outputDir.isEmpty()) { |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 607 | SkString differencePath (outputDir); |
| 608 | differencePath.append(filename_to_diff_filename(filename)); |
| 609 | write_bitmap(differencePath, drp->fDifferenceBitmap); |
| 610 | SkString whitePath (outputDir); |
| 611 | whitePath.append(filename_to_white_filename(filename)); |
| 612 | write_bitmap(whitePath, drp->fWhiteBitmap); |
| 613 | } |
| epoger@google.com | 6600852 | 2012-05-16 17:40:57 +0000 | [diff] [blame] | 614 | |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 615 | release_bitmaps(drp); |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 618 | /// Returns true if string contains any of these substrings. |
| 619 | static bool string_contains_any_of(const SkString& string, |
| 620 | const StringArray& substrings) { |
| 621 | for (int i = 0; i < substrings.count(); i++) { |
| 622 | if (string.contains(substrings[i]->c_str())) { |
| 623 | return true; |
| 624 | } |
| 625 | } |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | /// Iterate over dir and get all files that: |
| 630 | /// - match any of the substrings in matchSubstrings, but... |
| 631 | /// - DO NOT match any of the substrings in nomatchSubstrings |
| 632 | /// Returns the list of files in *files. |
| 633 | static void get_file_list(const SkString& dir, |
| 634 | const StringArray& matchSubstrings, |
| 635 | const StringArray& nomatchSubstrings, |
| 636 | FileArray *files) { |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 637 | SkOSFile::Iter it(dir.c_str()); |
| 638 | SkString filename; |
| 639 | while (it.next(&filename)) { |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 640 | if (string_contains_any_of(filename, matchSubstrings) && |
| 641 | !string_contains_any_of(filename, nomatchSubstrings)) { |
| 642 | files->push(new SkString(filename)); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 643 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | static void release_file_list(FileArray *files) { |
| 648 | files->deleteAll(); |
| 649 | } |
| 650 | |
| 651 | /// Comparison routines for qsort, sort by file names. |
| 652 | static int compare_file_name_metrics(SkString **lhs, SkString **rhs) { |
| 653 | return strcmp((*lhs)->c_str(), (*rhs)->c_str()); |
| 654 | } |
| 655 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 656 | /// Creates difference images, returns the number that have a 0 metric. |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 657 | /// If outputDir.isEmpty(), don't write out diff files. |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 658 | static void create_diff_images (DiffMetricProc dmp, |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 659 | const int colorThreshold, |
| 660 | RecordArray* differences, |
| 661 | const SkString& baseDir, |
| 662 | const SkString& comparisonDir, |
| 663 | const SkString& outputDir, |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 664 | const StringArray& matchSubstrings, |
| 665 | const StringArray& nomatchSubstrings, |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 666 | DiffSummary* summary) { |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 667 | SkASSERT(!baseDir.isEmpty()); |
| 668 | SkASSERT(!comparisonDir.isEmpty()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 669 | |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 670 | FileArray baseFiles; |
| 671 | FileArray comparisonFiles; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 672 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 673 | get_file_list(baseDir, matchSubstrings, nomatchSubstrings, &baseFiles); |
| 674 | get_file_list(comparisonDir, matchSubstrings, nomatchSubstrings, |
| 675 | &comparisonFiles); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 676 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 677 | if (!baseFiles.isEmpty()) { |
| reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 678 | qsort(baseFiles.begin(), baseFiles.count(), sizeof(SkString*), |
| 679 | SkCastForQSort(compare_file_name_metrics)); |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 680 | } |
| 681 | if (!comparisonFiles.isEmpty()) { |
| reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 682 | qsort(comparisonFiles.begin(), comparisonFiles.count(), |
| 683 | sizeof(SkString*), SkCastForQSort(compare_file_name_metrics)); |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 684 | } |
| epoger@google.com | 6600852 | 2012-05-16 17:40:57 +0000 | [diff] [blame] | 685 | |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 686 | int i = 0; |
| 687 | int j = 0; |
| 688 | |
| 689 | while (i < baseFiles.count() && |
| 690 | j < comparisonFiles.count()) { |
| 691 | |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 692 | SkString basePath (baseDir); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 693 | basePath.append(*baseFiles[i]); |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 694 | SkString comparisonPath (comparisonDir); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 695 | comparisonPath.append(*comparisonFiles[j]); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 696 | |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 697 | DiffRecord *drp = NULL; |
| 698 | int v = strcmp(baseFiles[i]->c_str(), |
| 699 | comparisonFiles[j]->c_str()); |
| 700 | |
| 701 | if (v < 0) { |
| 702 | // in baseDir, but not in comparisonDir |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 703 | drp = new DiffRecord(*baseFiles[i], basePath, comparisonPath, |
| 704 | kComparisonMissing); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 705 | ++i; |
| 706 | } else if (v > 0) { |
| 707 | // in comparisonDir, but not in baseDir |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 708 | drp = new DiffRecord(*comparisonFiles[j], basePath, comparisonPath, |
| 709 | kBaseMissing); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 710 | ++j; |
| 711 | } else { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 712 | // Found the same filename in both baseDir and comparisonDir. |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 713 | drp = new DiffRecord(*baseFiles[i], basePath, comparisonPath); |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 714 | SkASSERT(kUnknown == drp->fResult); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 715 | |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 716 | SkData* baseFileBits; |
| 717 | SkData* comparisonFileBits; |
| 718 | if (NULL == (baseFileBits = read_file(basePath.c_str()))) { |
| 719 | SkDebugf("WARNING: couldn't read base file <%s>\n", |
| 720 | basePath.c_str()); |
| 721 | drp->fResult = kBaseMissing; |
| 722 | } else if (NULL == (comparisonFileBits = read_file( |
| 723 | comparisonPath.c_str()))) { |
| 724 | SkDebugf("WARNING: couldn't read comparison file <%s>\n", |
| 725 | comparisonPath.c_str()); |
| 726 | drp->fResult = kComparisonMissing; |
| 727 | } else { |
| 728 | if (are_buffers_equal(baseFileBits, comparisonFileBits)) { |
| 729 | drp->fResult = kEqualBits; |
| 730 | } else if (get_bitmaps(baseFileBits, comparisonFileBits, drp)) { |
| 731 | create_and_write_diff_image(drp, dmp, colorThreshold, |
| 732 | outputDir, *baseFiles[i]); |
| 733 | } else { |
| 734 | drp->fResult = kDifferentOther; |
| 735 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 736 | } |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 737 | if (baseFileBits) { |
| 738 | baseFileBits->unref(); |
| 739 | } |
| 740 | if (comparisonFileBits) { |
| 741 | comparisonFileBits->unref(); |
| 742 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 743 | ++i; |
| 744 | ++j; |
| 745 | } |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 746 | SkASSERT(kUnknown != drp->fResult); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 747 | differences->push(drp); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 748 | summary->add(drp); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 749 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 750 | |
| 751 | for (; i < baseFiles.count(); ++i) { |
| 752 | // files only in baseDir |
| 753 | SkString basePath (baseDir); |
| 754 | basePath.append(*baseFiles[i]); |
| 755 | SkString comparisonPath; |
| 756 | DiffRecord *drp = new DiffRecord(*baseFiles[i], basePath, |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 757 | comparisonPath, kComparisonMissing); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 758 | differences->push(drp); |
| 759 | summary->add(drp); |
| 760 | } |
| 761 | |
| 762 | for (; j < comparisonFiles.count(); ++j) { |
| 763 | // files only in comparisonDir |
| 764 | SkString basePath; |
| 765 | SkString comparisonPath(comparisonDir); |
| 766 | comparisonPath.append(*comparisonFiles[j]); |
| 767 | DiffRecord *drp = new DiffRecord(*comparisonFiles[j], basePath, |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 768 | comparisonPath, kBaseMissing); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 769 | differences->push(drp); |
| 770 | summary->add(drp); |
| 771 | } |
| 772 | |
| 773 | release_file_list(&baseFiles); |
| 774 | release_file_list(&comparisonFiles); |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 775 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 776 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 777 | /// Make layout more consistent by scaling image to 240 height, 360 width, |
| 778 | /// or natural size, whichever is smallest. |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 779 | static int compute_image_height (int height, int width) { |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 780 | int retval = 240; |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 781 | if (height < retval) { |
| 782 | retval = height; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 783 | } |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 784 | float scale = (float) retval / height; |
| 785 | if (width * scale > 360) { |
| 786 | scale = (float) 360 / width; |
| bsalomon@google.com | 8e06dab | 2011-10-07 20:03:39 +0000 | [diff] [blame] | 787 | retval = static_cast<int>(height * scale); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 788 | } |
| 789 | return retval; |
| 790 | } |
| 791 | |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 792 | static void print_table_header (SkFILEWStream* stream, |
| 793 | const int matchCount, |
| 794 | const int colorThreshold, |
| 795 | const RecordArray& differences, |
| 796 | const SkString &baseDir, |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 797 | const SkString &comparisonDir, |
| 798 | bool doOutputDate=false) { |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 799 | stream->writeText("<table>\n"); |
| 800 | stream->writeText("<tr><th>"); |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 801 | if (doOutputDate) { |
| 802 | SkTime::DateTime dt; |
| 803 | SkTime::GetDateTime(&dt); |
| 804 | stream->writeText("SkDiff run at "); |
| 805 | stream->writeDecAsText(dt.fHour); |
| 806 | stream->writeText(":"); |
| 807 | if (dt.fMinute < 10) { |
| 808 | stream->writeText("0"); |
| 809 | } |
| 810 | stream->writeDecAsText(dt.fMinute); |
| 811 | stream->writeText(":"); |
| 812 | if (dt.fSecond < 10) { |
| 813 | stream->writeText("0"); |
| 814 | } |
| 815 | stream->writeDecAsText(dt.fSecond); |
| 816 | stream->writeText("<br>"); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 817 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 818 | stream->writeDecAsText(matchCount); |
| 819 | stream->writeText(" of "); |
| 820 | stream->writeDecAsText(differences.count()); |
| 821 | stream->writeText(" images matched "); |
| 822 | if (colorThreshold == 0) { |
| 823 | stream->writeText("exactly"); |
| 824 | } else { |
| 825 | stream->writeText("within "); |
| 826 | stream->writeDecAsText(colorThreshold); |
| 827 | stream->writeText(" color units per component"); |
| 828 | } |
| 829 | stream->writeText(".<br>"); |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 830 | stream->writeText("</th>\n<th>"); |
| 831 | stream->writeText("every different pixel shown in white"); |
| 832 | stream->writeText("</th>\n<th>"); |
| 833 | stream->writeText("color difference at each pixel"); |
| 834 | stream->writeText("</th>\n<th>"); |
| 835 | stream->writeText(baseDir.c_str()); |
| 836 | stream->writeText("</th>\n<th>"); |
| 837 | stream->writeText(comparisonDir.c_str()); |
| 838 | stream->writeText("</th>\n"); |
| 839 | stream->writeText("</tr>\n"); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | static void print_pixel_count (SkFILEWStream* stream, |
| 843 | const DiffRecord& diff) { |
| 844 | stream->writeText("<br>("); |
| bsalomon@google.com | 8e06dab | 2011-10-07 20:03:39 +0000 | [diff] [blame] | 845 | stream->writeDecAsText(static_cast<int>(diff.fFractionDifference * |
| 846 | diff.fBaseWidth * |
| 847 | diff.fBaseHeight)); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 848 | stream->writeText(" pixels)"); |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 849 | /* |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 850 | stream->writeDecAsText(diff.fWeightedFraction * |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 851 | diff.fBaseWidth * |
| 852 | diff.fBaseHeight); |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 853 | stream->writeText(" weighted pixels)"); |
| 854 | */ |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static void print_label_cell (SkFILEWStream* stream, |
| 858 | const DiffRecord& diff) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 859 | char metricBuf [20]; |
| 860 | |
| 861 | stream->writeText("<td><b>"); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 862 | stream->writeText(diff.fFilename.c_str()); |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 863 | stream->writeText("</b><br>"); |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 864 | switch (diff.fResult) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 865 | case kEqualBits: |
| 866 | SkDEBUGFAIL("should not encounter DiffRecord with kEqualBits here"); |
| 867 | return; |
| 868 | case kEqualPixels: |
| 869 | SkDEBUGFAIL("should not encounter DiffRecord with kEqualPixels here"); |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 870 | return; |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 871 | case kDifferentSizes: |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 872 | stream->writeText("Image sizes differ</td>"); |
| 873 | return; |
| 874 | case kDifferentPixels: |
| 875 | sprintf(metricBuf, "%12.4f%%", 100 * diff.fFractionDifference); |
| 876 | stream->writeText(metricBuf); |
| 877 | stream->writeText(" of pixels differ"); |
| 878 | stream->writeText("\n ("); |
| 879 | sprintf(metricBuf, "%12.4f%%", 100 * diff.fWeightedFraction); |
| 880 | stream->writeText(metricBuf); |
| 881 | stream->writeText(" weighted)"); |
| 882 | // Write the actual number of pixels that differ if it's < 1% |
| 883 | if (diff.fFractionDifference < 0.01) { |
| 884 | print_pixel_count(stream, diff); |
| 885 | } |
| 886 | stream->writeText("<br>Average color mismatch "); |
| 887 | stream->writeDecAsText(static_cast<int>(MAX3(diff.fAverageMismatchR, |
| 888 | diff.fAverageMismatchG, |
| 889 | diff.fAverageMismatchB))); |
| 890 | stream->writeText("<br>Max color mismatch "); |
| 891 | stream->writeDecAsText(MAX3(diff.fMaxMismatchR, |
| 892 | diff.fMaxMismatchG, |
| 893 | diff.fMaxMismatchB)); |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 894 | stream->writeText("</td>"); |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 895 | break; |
| 896 | case kDifferentOther: |
| 897 | stream->writeText("Files differ; unable to parse one or both files</td>"); |
| 898 | return; |
| 899 | case kBaseMissing: |
| 900 | stream->writeText("Missing from baseDir</td>"); |
| 901 | return; |
| 902 | case kComparisonMissing: |
| 903 | stream->writeText("Missing from comparisonDir</td>"); |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 904 | return; |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 905 | default: |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 906 | SkDEBUGFAIL("encountered DiffRecord with unknown result type"); |
| 907 | return; |
| tomhudson@google.com | 8b08c3e | 2011-11-30 17:01:00 +0000 | [diff] [blame] | 908 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static void print_image_cell (SkFILEWStream* stream, |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 912 | const SkString& path, |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 913 | int height) { |
| 914 | stream->writeText("<td><a href=\""); |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 915 | stream->writeText(path.c_str()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 916 | stream->writeText("\"><img src=\""); |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 917 | stream->writeText(path.c_str()); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 918 | stream->writeText("\" height=\""); |
| 919 | stream->writeDecAsText(height); |
| 920 | stream->writeText("px\"></a></td>"); |
| 921 | } |
| 922 | |
| caryclark@google.com | 3dd4591 | 2012-06-06 12:11:10 +0000 | [diff] [blame] | 923 | #if 0 // UNUSED |
| epoger@google.com | 01f7870 | 2012-04-12 16:32:04 +0000 | [diff] [blame] | 924 | static void print_text_cell (SkFILEWStream* stream, const char* text) { |
| 925 | stream->writeText("<td align=center>"); |
| 926 | if (NULL != text) { |
| 927 | stream->writeText(text); |
| 928 | } |
| 929 | stream->writeText("</td>"); |
| 930 | } |
| caryclark@google.com | 3dd4591 | 2012-06-06 12:11:10 +0000 | [diff] [blame] | 931 | #endif |
| epoger@google.com | 01f7870 | 2012-04-12 16:32:04 +0000 | [diff] [blame] | 932 | |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 933 | static void print_diff_with_missing_file(SkFILEWStream* stream, |
| 934 | DiffRecord& diff, |
| 935 | const SkString& relativePath) { |
| 936 | stream->writeText("<tr>\n"); |
| 937 | print_label_cell(stream, diff); |
| 938 | stream->writeText("<td>N/A</td>"); |
| 939 | stream->writeText("<td>N/A</td>"); |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 940 | if (kBaseMissing != diff.fResult) { |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 941 | int h, w; |
| 942 | if (!get_bitmap_height_width(diff.fBasePath, &h, &w)) { |
| 943 | stream->writeText("<td>N/A</td>"); |
| 944 | } else { |
| 945 | int height = compute_image_height(h, w); |
| 946 | if (!diff.fBasePath.startsWith(PATH_DIV_STR)) { |
| 947 | diff.fBasePath.prepend(relativePath); |
| 948 | } |
| 949 | print_image_cell(stream, diff.fBasePath, height); |
| 950 | } |
| 951 | } else { |
| 952 | stream->writeText("<td>N/A</td>"); |
| 953 | } |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 954 | if (kComparisonMissing != diff.fResult) { |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 955 | int h, w; |
| 956 | if (!get_bitmap_height_width(diff.fComparisonPath, &h, &w)) { |
| 957 | stream->writeText("<td>N/A</td>"); |
| 958 | } else { |
| 959 | int height = compute_image_height(h, w); |
| 960 | if (!diff.fComparisonPath.startsWith(PATH_DIV_STR)) { |
| 961 | diff.fComparisonPath.prepend(relativePath); |
| 962 | } |
| 963 | print_image_cell(stream, diff.fComparisonPath, height); |
| 964 | } |
| 965 | } else { |
| 966 | stream->writeText("<td>N/A</td>"); |
| 967 | } |
| 968 | stream->writeText("</tr>\n"); |
| 969 | stream->flush(); |
| 970 | } |
| 971 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 972 | static void print_diff_page (const int matchCount, |
| 973 | const int colorThreshold, |
| 974 | const RecordArray& differences, |
| 975 | const SkString& baseDir, |
| 976 | const SkString& comparisonDir, |
| 977 | const SkString& outputDir) { |
| 978 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 979 | SkASSERT(!baseDir.isEmpty()); |
| 980 | SkASSERT(!comparisonDir.isEmpty()); |
| 981 | SkASSERT(!outputDir.isEmpty()); |
| 982 | |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 983 | SkString outputPath (outputDir); |
| 984 | outputPath.append("index.html"); |
| 985 | //SkFILEWStream outputStream ("index.html"); |
| 986 | SkFILEWStream outputStream (outputPath.c_str()); |
| 987 | |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 988 | // Need to convert paths from relative-to-cwd to relative-to-outputDir |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 989 | // FIXME this doesn't work if there are '..' inside the outputDir |
| 990 | unsigned int ui; |
| 991 | SkString relativePath; |
| 992 | for (ui = 0; ui < outputDir.size(); ui++) { |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 993 | if (outputDir[ui] == PATH_DIV_CHAR) { |
| 994 | relativePath.append(".." PATH_DIV_STR); |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 995 | } |
| 996 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 997 | |
| 998 | outputStream.writeText("<html>\n<body>\n"); |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 999 | print_table_header(&outputStream, matchCount, colorThreshold, differences, |
| 1000 | baseDir, comparisonDir); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1001 | int i; |
| 1002 | for (i = 0; i < differences.count(); i++) { |
| 1003 | DiffRecord* diff = differences[i]; |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 1004 | |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 1005 | switch (diff->fResult) { |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 1006 | // Cases in which there is no diff to report. |
| 1007 | case kEqualBits: |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 1008 | case kEqualPixels: |
| 1009 | continue; |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 1010 | // Cases in which we want a detailed pixel diff. |
| 1011 | case kDifferentPixels: |
| 1012 | break; |
| 1013 | // Cases in which the files differed, but we can't display the diff. |
| 1014 | case kDifferentSizes: |
| 1015 | case kDifferentOther: |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 1016 | case kBaseMissing: |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 1017 | case kComparisonMissing: |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 1018 | print_diff_with_missing_file(&outputStream, *diff, relativePath); |
| 1019 | continue; |
| epoger@google.com | 292aff6 | 2012-05-16 14:57:28 +0000 | [diff] [blame] | 1020 | default: |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 1021 | SkDEBUGFAIL("encountered DiffRecord with unknown result type"); |
| 1022 | continue; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1023 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 1024 | |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 1025 | if (!diff->fBasePath.startsWith(PATH_DIV_STR)) { |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 1026 | diff->fBasePath.prepend(relativePath); |
| 1027 | } |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 1028 | if (!diff->fComparisonPath.startsWith(PATH_DIV_STR)) { |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 1029 | diff->fComparisonPath.prepend(relativePath); |
| 1030 | } |
| epoger@google.com | 5fd5385 | 2012-03-22 18:20:06 +0000 | [diff] [blame] | 1031 | |
| tomhudson@google.com | 9b540ce | 2011-08-02 14:10:04 +0000 | [diff] [blame] | 1032 | int height = compute_image_height(diff->fBaseHeight, diff->fBaseWidth); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1033 | outputStream.writeText("<tr>\n"); |
| 1034 | print_label_cell(&outputStream, *diff); |
| epoger@google.com | 46256ea | 2012-05-22 13:45:35 +0000 | [diff] [blame] | 1035 | print_image_cell(&outputStream, |
| 1036 | filename_to_white_filename(diff->fFilename), height); |
| 1037 | print_image_cell(&outputStream, |
| 1038 | filename_to_diff_filename(diff->fFilename), height); |
| epoger@google.com | 25d961c | 2012-02-02 20:50:36 +0000 | [diff] [blame] | 1039 | print_image_cell(&outputStream, diff->fBasePath, height); |
| tomhudson@google.com | 4e30598 | 2011-07-13 17:42:46 +0000 | [diff] [blame] | 1040 | print_image_cell(&outputStream, diff->fComparisonPath, height); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1041 | outputStream.writeText("</tr>\n"); |
| 1042 | outputStream.flush(); |
| 1043 | } |
| 1044 | outputStream.writeText("</table>\n"); |
| 1045 | outputStream.writeText("</body>\n</html>\n"); |
| 1046 | outputStream.flush(); |
| 1047 | } |
| 1048 | |
| 1049 | static void usage (char * argv0) { |
| 1050 | SkDebugf("Skia baseline image diff tool\n"); |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1051 | SkDebugf("\n" |
| 1052 | "Usage: \n" |
| 1053 | " %s <baseDir> <comparisonDir> [outputDir] \n" |
| epoger@google.com | a611c3e | 2012-05-18 20:10:06 +0000 | [diff] [blame] | 1054 | , argv0, argv0); |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1055 | SkDebugf("\n" |
| 1056 | "Arguments: \n" |
| 1057 | " --nodiffs: don't write out image diffs or index.html, just generate \n" |
| 1058 | " report on stdout \n" |
| 1059 | " --threshold <n>: only report differences > n (per color channel) [default 0]\n" |
| 1060 | " --match: compare files whose filenames contain this substring; if \n" |
| 1061 | " unspecified, compare ALL files. \n" |
| 1062 | " this flag may be repeated to add more matching substrings. \n" |
| 1063 | " --nomatch: regardless of --match, DO NOT compare files whose filenames \n" |
| 1064 | " contain this substring. \n" |
| 1065 | " this flag may be repeated to add more forbidden substrings. \n" |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1066 | " --sortbymismatch: sort by average color channel mismatch\n"); |
| 1067 | SkDebugf( |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1068 | " --sortbymaxmismatch: sort by worst color channel mismatch;\n" |
| 1069 | " break ties with -sortbymismatch\n" |
| 1070 | " [default sort is by fraction of pixels mismatching]\n"); |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 1071 | SkDebugf( |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1072 | " --weighted: sort by # pixels different weighted by color difference\n"); |
| 1073 | SkDebugf( |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1074 | " --noprintdirs: do not print the directories used."); |
| 1075 | SkDebugf( |
| epoger@google.com | a611c3e | 2012-05-18 20:10:06 +0000 | [diff] [blame] | 1076 | " baseDir: directory to read baseline images from.\n"); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 1077 | SkDebugf( |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1078 | " comparisonDir: directory to read comparison images from\n"); |
| 1079 | SkDebugf( |
| 1080 | " outputDir: directory to write difference images and index.html to; \n" |
| epoger@google.com | a611c3e | 2012-05-18 20:10:06 +0000 | [diff] [blame] | 1081 | " defaults to comparisonDir \n"); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | int main (int argc, char ** argv) { |
| 1085 | DiffMetricProc diffProc = compute_diff_pmcolor; |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 1086 | int (*sortProc)(const void*, const void*) = compare<CompareDiffMetrics>; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1087 | |
| 1088 | // Maximum error tolerated in any one color channel in any one pixel before |
| 1089 | // a difference is reported. |
| 1090 | int colorThreshold = 0; |
| 1091 | SkString baseDir; |
| 1092 | SkString comparisonDir; |
| 1093 | SkString outputDir; |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1094 | StringArray matchSubstrings; |
| 1095 | StringArray nomatchSubstrings; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1096 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1097 | bool generateDiffs = true; |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1098 | bool printDirs = true; |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1099 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1100 | RecordArray differences; |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 1101 | DiffSummary summary; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1102 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1103 | int i; |
| 1104 | int numUnflaggedArguments = 0; |
| 1105 | for (i = 1; i < argc; i++) { |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1106 | if (!strcmp(argv[i], "--help")) { |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1107 | usage(argv[0]); |
| 1108 | return 0; |
| 1109 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1110 | if (!strcmp(argv[i], "--nodiffs")) { |
| 1111 | generateDiffs = false; |
| 1112 | continue; |
| 1113 | } |
| 1114 | if (!strcmp(argv[i], "--threshold")) { |
| 1115 | colorThreshold = atoi(argv[++i]); |
| 1116 | continue; |
| 1117 | } |
| 1118 | if (!strcmp(argv[i], "--match")) { |
| 1119 | matchSubstrings.push(new SkString(argv[++i])); |
| 1120 | continue; |
| 1121 | } |
| 1122 | if (!strcmp(argv[i], "--nomatch")) { |
| 1123 | nomatchSubstrings.push(new SkString(argv[++i])); |
| 1124 | continue; |
| 1125 | } |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1126 | if (!strcmp(argv[i], "--sortbymismatch")) { |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 1127 | sortProc = compare<CompareDiffMeanMismatches>; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1128 | continue; |
| 1129 | } |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1130 | if (!strcmp(argv[i], "--sortbymaxmismatch")) { |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 1131 | sortProc = compare<CompareDiffMaxMismatches>; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1132 | continue; |
| 1133 | } |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1134 | if (!strcmp(argv[i], "--weighted")) { |
| epoger@google.com | 28060e7 | 2012-06-28 16:47:34 +0000 | [diff] [blame] | 1135 | sortProc = compare<CompareDiffWeighted>; |
| tomhudson@google.com | 5b32529 | 2011-05-24 19:41:13 +0000 | [diff] [blame] | 1136 | continue; |
| 1137 | } |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1138 | if (!strcmp(argv[i], "--noprintdirs")) { |
| 1139 | printDirs = false; |
| 1140 | continue; |
| 1141 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1142 | if (argv[i][0] != '-') { |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1143 | switch (numUnflaggedArguments++) { |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1144 | case 0: |
| 1145 | baseDir.set(argv[i]); |
| 1146 | continue; |
| 1147 | case 1: |
| 1148 | comparisonDir.set(argv[i]); |
| 1149 | continue; |
| 1150 | case 2: |
| 1151 | outputDir.set(argv[i]); |
| 1152 | continue; |
| 1153 | default: |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1154 | SkDebugf("extra unflagged argument <%s>\n", argv[i]); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1155 | usage(argv[0]); |
| 1156 | return 0; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | SkDebugf("Unrecognized argument <%s>\n", argv[i]); |
| 1161 | usage(argv[0]); |
| 1162 | return 0; |
| 1163 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1164 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1165 | if (numUnflaggedArguments == 2) { |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 1166 | outputDir = comparisonDir; |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1167 | } else if (numUnflaggedArguments != 3) { |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 1168 | usage(argv[0]); |
| 1169 | return 0; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 1172 | if (!baseDir.endsWith(PATH_DIV_STR)) { |
| 1173 | baseDir.append(PATH_DIV_STR); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1174 | } |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1175 | if (printDirs) { |
| 1176 | printf("baseDir is [%s]\n", baseDir.c_str()); |
| 1177 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1178 | |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 1179 | if (!comparisonDir.endsWith(PATH_DIV_STR)) { |
| 1180 | comparisonDir.append(PATH_DIV_STR); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1181 | } |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1182 | if (printDirs) { |
| 1183 | printf("comparisonDir is [%s]\n", comparisonDir.c_str()); |
| 1184 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1185 | |
| bsalomon@google.com | 1a315fe | 2011-09-23 14:56:37 +0000 | [diff] [blame] | 1186 | if (!outputDir.endsWith(PATH_DIV_STR)) { |
| 1187 | outputDir.append(PATH_DIV_STR); |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1188 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1189 | if (generateDiffs) { |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1190 | if (printDirs) { |
| 1191 | printf("writing diffs to outputDir is [%s]\n", outputDir.c_str()); |
| 1192 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1193 | } else { |
| keyar@chromium.org | a631819 | 2012-07-09 21:01:50 +0000 | [diff] [blame^] | 1194 | if (printDirs) { |
| 1195 | printf("not writing any diffs to outputDir [%s]\n", outputDir.c_str()); |
| 1196 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1197 | outputDir.set(""); |
| 1198 | } |
| 1199 | |
| epoger@google.com | da4af24 | 2012-06-25 18:45:50 +0000 | [diff] [blame] | 1200 | // If no matchSubstrings were specified, match ALL strings |
| 1201 | // (except for whatever nomatchSubstrings were specified, if any). |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1202 | if (matchSubstrings.isEmpty()) { |
| 1203 | matchSubstrings.push(new SkString("")); |
| 1204 | } |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1205 | |
| epoger@google.com | a611c3e | 2012-05-18 20:10:06 +0000 | [diff] [blame] | 1206 | create_diff_images(diffProc, colorThreshold, &differences, |
| 1207 | baseDir, comparisonDir, outputDir, |
| 1208 | matchSubstrings, nomatchSubstrings, &summary); |
| tomhudson@google.com | 9dc527b | 2011-06-09 15:47:10 +0000 | [diff] [blame] | 1209 | summary.print(); |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1210 | |
| 1211 | if (differences.count()) { |
| reed@google.com | c7a67cb | 2012-05-07 14:52:12 +0000 | [diff] [blame] | 1212 | qsort(differences.begin(), differences.count(), |
| 1213 | sizeof(DiffRecord*), sortProc); |
| tomhudson@google.com | 7d04280 | 2011-07-14 13:15:55 +0000 | [diff] [blame] | 1214 | } |
| epoger@google.com | 6600852 | 2012-05-16 17:40:57 +0000 | [diff] [blame] | 1215 | |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1216 | if (generateDiffs) { |
| 1217 | print_diff_page(summary.fNumMatches, colorThreshold, differences, |
| 1218 | baseDir, comparisonDir, outputDir); |
| 1219 | } |
| epoger@google.com | 76222c0 | 2012-05-31 15:12:09 +0000 | [diff] [blame] | 1220 | |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1221 | for (i = 0; i < differences.count(); i++) { |
| 1222 | delete differences[i]; |
| 1223 | } |
| epoger@google.com | a5f406e | 2012-05-01 13:26:16 +0000 | [diff] [blame] | 1224 | matchSubstrings.deleteAll(); |
| 1225 | nomatchSubstrings.deleteAll(); |
| epoger@google.com | be6188d | 2012-05-31 15:13:45 +0000 | [diff] [blame] | 1226 | |
| 1227 | return summary.fNumMismatches; |
| tomhudson@google.com | 4b33d28 | 2011-04-27 15:39:30 +0000 | [diff] [blame] | 1228 | } |