Chromium Code Reviews| Index: tools/skpdiff/SkDiffContext.cpp |
| diff --git a/tools/skpdiff/SkDiffContext.cpp b/tools/skpdiff/SkDiffContext.cpp |
| index 6f0b09f0822e70c7d8d78626b945e0d9d45248ce..2b1f5f205ed245a815a6a31fa361a76eee4c9018 100644 |
| --- a/tools/skpdiff/SkDiffContext.cpp |
| +++ b/tools/skpdiff/SkDiffContext.cpp |
| @@ -28,9 +28,21 @@ SkDiffContext::~SkDiffContext() { |
| } |
| } |
| -void SkDiffContext::setDifferenceDir(const SkString& path) { |
| +void SkDiffContext::setAlphaMaskDir(const SkString& path) { |
| if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
| - fDifferenceDir = path; |
| + fAlphaMaskDir = path; |
| + } |
| +} |
| + |
| +void SkDiffContext::setRgbDiffDir(const SkString& path) { |
| + if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
| + fRgbDiffDir = path; |
| + } |
| +} |
| + |
| +void SkDiffContext::setWhiteDiffDir(const SkString& path) { |
| + if (!path.isEmpty() && sk_mkdir(path.c_str())) { |
| + fWhiteDiffDir = path; |
| } |
| } |
| @@ -90,13 +102,13 @@ void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
| newRecord->fBaselinePath = baselinePath; |
| newRecord->fTestPath = testPath; |
| + newRecord->fWidth = baselineBitmap.width(); |
| + newRecord->fHeight = baselineBitmap.height(); |
| - bool alphaMaskPending = false; |
| - |
| - // only enable alpha masks if a difference dir has been provided |
| - if (!fDifferenceDir.isEmpty()) { |
| - alphaMaskPending = true; |
| - } |
| + // only generate diff images if we have a place to store them |
| + bool alphaMaskPending = !fAlphaMaskDir.isEmpty(); |
| + bool rgbDiffPending = !fRgbDiffDir.isEmpty(); |
| + bool whiteDiffPending = !fWhiteDiffDir.isEmpty(); |
| // Perform each diff |
| for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { |
| @@ -106,8 +118,9 @@ void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
| DiffData& diffData = newRecord->fDiffs.push_back(); |
| diffData.fDiffName = differ->getName(); |
| - if (!differ->diff(&baselineBitmap, &testBitmap, alphaMaskPending, &diffData.fResult)) { |
| - // if the diff failed record -1 as the result |
| + if (!differ->diff(&baselineBitmap, &testBitmap, alphaMaskPending, rgbDiffPending, |
| + whiteDiffPending, &diffData.fResult)) { |
| + // if the diff failed, record -1 as the result |
| diffData.fResult.result = -1; |
| continue; |
| } |
| @@ -117,13 +130,13 @@ void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
| && !diffData.fResult.poiAlphaMask.empty() |
| && !newRecord->fCommonName.isEmpty()) { |
| - newRecord->fDifferencePath = SkOSPath::SkPathJoin(fDifferenceDir.c_str(), |
| - newRecord->fCommonName.c_str()); |
| + newRecord->fAlphaMaskPath = SkOSPath::SkPathJoin(fAlphaMaskDir.c_str(), |
| + newRecord->fCommonName.c_str()); |
| // compute the image diff and output it |
| SkBitmap copy; |
| diffData.fResult.poiAlphaMask.copyTo(©, kN32_SkColorType); |
| - SkImageEncoder::EncodeFile(newRecord->fDifferencePath.c_str(), copy, |
| + SkImageEncoder::EncodeFile(newRecord->fAlphaMaskPath.c_str(), copy, |
| SkImageEncoder::kPNG_Type, 100); |
| // cleanup the existing bitmap to free up resources; |
| @@ -131,6 +144,39 @@ void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { |
| alphaMaskPending = false; |
| } |
| + |
| + if (rgbDiffPending |
| + && SkImageDiffer::RESULT_CORRECT != diffData.fResult.result |
| + && !diffData.fResult.rgbDiffBitmap.empty() |
| + && !newRecord->fCommonName.isEmpty()) { |
| + // EPOGER: This is a hack, based on the knowledge that the same |
| + // differ which gives us rgbDiffBitmap will also give us the |
| + // max r/g/b diffs. |
| + newRecord->fMaxRedDiff = diffData.fResult.maxRedDiff; |
| + newRecord->fMaxGreenDiff = diffData.fResult.maxGreenDiff; |
| + newRecord->fMaxBlueDiff = diffData.fResult.maxBlueDiff; |
| + |
| + newRecord->fRgbDiffPath = SkOSPath::SkPathJoin(fRgbDiffDir.c_str(), |
| + newRecord->fCommonName.c_str()); |
| + SkImageEncoder::EncodeFile(newRecord->fRgbDiffPath.c_str(), |
| + diffData.fResult.rgbDiffBitmap, |
| + SkImageEncoder::kPNG_Type, 100); |
| + diffData.fResult.rgbDiffBitmap.reset(); |
| + rgbDiffPending = false; |
| + } |
| + |
| + if (whiteDiffPending |
| + && SkImageDiffer::RESULT_CORRECT != diffData.fResult.result |
| + && !diffData.fResult.whiteDiffBitmap.empty() |
| + && !newRecord->fCommonName.isEmpty()) { |
| + newRecord->fWhiteDiffPath = SkOSPath::SkPathJoin(fWhiteDiffDir.c_str(), |
| + newRecord->fCommonName.c_str()); |
| + SkImageEncoder::EncodeFile(newRecord->fWhiteDiffPath.c_str(), |
| + diffData.fResult.whiteDiffBitmap, |
| + SkImageEncoder::kPNG_Type, 100); |
| + diffData.fResult.whiteDiffBitmap.reset(); |
| + whiteDiffPending = false; |
| + } |
| } |
| } |
| @@ -229,11 +275,13 @@ void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { |
| } else { |
| stream.writeText("{\n"); |
| } |
| + |
| + // TODO: Would it be better to use the jsoncpp library to write out the JSON? |
| + // This manual approach is probably more efficient, but it sure is ugly. |
| stream.writeText(" \"records\": [\n"); |
| while (NULL != currentRecord) { |
| stream.writeText(" {\n"); |
| - SkString differenceAbsPath = get_absolute_path(currentRecord->fDifferencePath); |
| SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselinePath); |
| SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); |
| @@ -242,7 +290,15 @@ void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { |
| stream.writeText("\",\n"); |
| stream.writeText(" \"differencePath\": \""); |
| - stream.writeText(differenceAbsPath.c_str()); |
| + stream.writeText(get_absolute_path(currentRecord->fAlphaMaskPath).c_str()); |
| + stream.writeText("\",\n"); |
| + |
| + stream.writeText(" \"rgbDiffPath\": \""); |
| + stream.writeText(get_absolute_path(currentRecord->fRgbDiffPath).c_str()); |
| + stream.writeText("\",\n"); |
| + |
| + stream.writeText(" \"whiteDiffPath\": \""); |
| + stream.writeText(get_absolute_path(currentRecord->fWhiteDiffPath).c_str()); |
| stream.writeText("\",\n"); |
| stream.writeText(" \"baselinePath\": \""); |
| @@ -253,6 +309,23 @@ void SkDiffContext::outputRecords(SkWStream& stream, bool useJSONP) { |
| stream.writeText(testAbsPath.c_str()); |
| stream.writeText("\",\n"); |
| + stream.writeText(" \"width\": "); |
| + stream.writeDecAsText(currentRecord->fWidth); |
| + stream.writeText(",\n"); |
| + stream.writeText(" \"height\": "); |
| + stream.writeDecAsText(currentRecord->fHeight); |
| + stream.writeText(",\n"); |
| + |
| + stream.writeText(" \"maxRedDiff\": "); |
|
epoger
2014/06/12 07:02:07
Here I jammed in the various parameters that I had
|
| + stream.writeDecAsText(currentRecord->fMaxRedDiff); |
| + stream.writeText(",\n"); |
| + stream.writeText(" \"maxGreenDiff\": "); |
| + stream.writeDecAsText(currentRecord->fMaxGreenDiff); |
| + stream.writeText(",\n"); |
| + stream.writeText(" \"maxBlueDiff\": "); |
| + stream.writeDecAsText(currentRecord->fMaxBlueDiff); |
| + stream.writeText(",\n"); |
| + |
| stream.writeText(" \"diffs\": [\n"); |
| for (int diffIndex = 0; diffIndex < currentRecord->fDiffs.count(); diffIndex++) { |
| DiffData& data = currentRecord->fDiffs[diffIndex]; |