diff --git a/tools/skdiff_main.cpp b/tools/skdiff_main.cpp index d9bcc5920..090a2a54b 100644 --- a/tools/skdiff_main.cpp +++ b/tools/skdiff_main.cpp @@ -22,8 +22,12 @@ */ struct DiffRecord { - DiffRecord (const SkString filename) + DiffRecord (const SkString filename, + const SkString basePath, + const SkString comparisonPath) : fFilename (filename) + , fBasePath (basePath) + , fComparisonPath (comparisonPath) , fFractionDifference (0) , fWeightedFraction (0) , fAverageMismatchR (0) @@ -31,9 +35,14 @@ struct DiffRecord { , fAverageMismatchB (0) , fMaxMismatchR (0) , fMaxMismatchG (0) - , fMaxMismatchB (0) { }; + , fMaxMismatchB (0) { + SkASSERT(basePath.endsWith(filename.c_str())); + SkASSERT(comparisonPath.endsWith(filename.c_str())); + }; SkString fFilename; + SkString fBasePath; + SkString fComparisonPath; SkBitmap fBaseBitmap; SkBitmap fComparisonBitmap; @@ -162,31 +171,25 @@ static int compare_diff_max_mismatches (DiffRecord** lhs, DiffRecord** rhs) { /// Parameterized routine to compute the color of a pixel in a difference image. typedef SkPMColor (*DiffMetricProc)(SkPMColor, SkPMColor); -static bool get_bitmaps (DiffRecord* diffRecord, - const SkString& baseDir, - const SkString& comparisonDir) { - SkString comparePath (comparisonDir); - comparePath.append(diffRecord->fFilename); - SkFILEStream compareStream(comparePath.c_str()); +static bool get_bitmaps (DiffRecord* diffRecord) { + SkFILEStream compareStream(diffRecord->fComparisonPath.c_str()); if (!compareStream.isValid()) { SkDebugf("WARNING: couldn't open comparison file <%s>\n", - comparePath.c_str()); + diffRecord->fComparisonPath.c_str()); return false; } - SkString basePath (baseDir); - basePath.append(diffRecord->fFilename); - SkFILEStream baseStream(basePath.c_str()); + SkFILEStream baseStream(diffRecord->fBasePath.c_str()); if (!baseStream.isValid()) { SkDebugf("ERROR: couldn't open base file <%s>\n", - basePath.c_str()); + diffRecord->fBasePath.c_str()); return false; } SkImageDecoder* codec = SkImageDecoder::Factory(&baseStream); if (NULL == codec) { SkDebugf("ERROR: no codec found for <%s>\n", - basePath.c_str()); + diffRecord->fBasePath.c_str()); return false; } @@ -197,7 +200,7 @@ static bool get_bitmaps (DiffRecord* diffRecord, SkBitmap::kARGB_8888_Config, SkImageDecoder::kDecodePixels_Mode)) { SkDebugf("ERROR: codec failed for <%s>\n", - basePath.c_str()); + diffRecord->fBasePath.c_str()); return false; } @@ -205,7 +208,7 @@ static bool get_bitmaps (DiffRecord* diffRecord, SkBitmap::kARGB_8888_Config, SkImageDecoder::kDecodePixels_Mode)) { SkDebugf("ERROR: codec failed for <%s>\n", - comparePath.c_str()); + diffRecord->fComparisonPath.c_str()); return false; } @@ -326,6 +329,16 @@ static SkString filename_to_diff_filename (const SkString& filename) { return diffName; } +static void create_diff_image(DiffRecord* drp, + DiffMetricProc dmp, + const int colorThreshold) { + const int w = drp->fBaseBitmap.width(); + const int h = drp->fBaseBitmap.height(); + drp->fDifferenceBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); + drp->fDifferenceBitmap.allocPixels(); + compute_diff(drp, dmp, colorThreshold); +} + /// Creates difference images, returns the number that have a 0 metric. static void create_diff_images (DiffMetricProc dmp, SkQSortCompareProc scp, @@ -349,16 +362,16 @@ static void create_diff_images (DiffMetricProc dmp, if (filename.endsWith(".pdf")) { continue; } - DiffRecord * drp = new DiffRecord (filename); - if (!get_bitmaps(drp, baseDir, comparisonDir)) { + SkString basePath (baseDir); + SkString comparisonPath (comparisonDir); + basePath.append(filename); + comparisonPath.append(filename); + DiffRecord * drp = new DiffRecord (filename, basePath, comparisonPath); + if (!get_bitmaps(drp)) { continue; } - const int w = drp->fBaseBitmap.width(); - const int h = drp->fBaseBitmap.height(); - drp->fDifferenceBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); - drp->fDifferenceBitmap.allocPixels(); - compute_diff(drp, dmp, colorThreshold); + create_diff_image(drp, dmp, colorThreshold); SkString outPath (outputDir); outPath.append(filename_to_diff_filename(filename)); @@ -465,15 +478,12 @@ static void print_label_cell (SkFILEWStream* stream, } static void print_image_cell (SkFILEWStream* stream, - const SkString& directory, - const SkString& filename, + const SkString& path, int height) { stream->writeText("