Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tools/skpdiff/SkDiffContext.cpp

Issue 457203003: Modify skpdiff to write diffs directly to provided directories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkImageDecoder.h" 9 #include "SkImageDecoder.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
11 #include "SkRunnable.h" 11 #include "SkRunnable.h"
12 #include "SkSize.h" 12 #include "SkSize.h"
13 #include "SkStream.h" 13 #include "SkStream.h"
14 #include "SkTDict.h" 14 #include "SkTDict.h"
15 #include "SkThreadPool.h" 15 #include "SkThreadPool.h"
16 16
17 #include "SkDiffContext.h" 17 #include "SkDiffContext.h"
18 #include "SkImageDiffer.h" 18 #include "SkImageDiffer.h"
19 #include "skpdiff_util.h" 19 #include "skpdiff_util.h"
20 20
21 #include <string>
22 #include <algorithm>
23
21 SkDiffContext::SkDiffContext() { 24 SkDiffContext::SkDiffContext() {
22 fDiffers = NULL; 25 fDiffers = NULL;
23 fDifferCount = 0; 26 fDifferCount = 0;
24 fThreadCount = SkThreadPool::kThreadPerCore; 27 fThreadCount = SkThreadPool::kThreadPerCore;
25 } 28 }
26 29
27 SkDiffContext::~SkDiffContext() { 30 SkDiffContext::~SkDiffContext() {
28 if (NULL != fDiffers) { 31 if (NULL != fDiffers) {
29 SkDELETE_ARRAY(fDiffers); 32 SkDELETE_ARRAY(fDiffers);
30 } 33 }
(...skipping 10 matching lines...) Expand all
41 fRgbDiffDir = path; 44 fRgbDiffDir = path;
42 } 45 }
43 } 46 }
44 47
45 void SkDiffContext::setWhiteDiffDir(const SkString& path) { 48 void SkDiffContext::setWhiteDiffDir(const SkString& path) {
46 if (!path.isEmpty() && sk_mkdir(path.c_str())) { 49 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
47 fWhiteDiffDir = path; 50 fWhiteDiffDir = path;
48 } 51 }
49 } 52 }
50 53
54 void SkDiffContext::setLongNames(const bool useLongNames) {
55 longNames = useLongNames;
56 }
57
51 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { 58 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) {
52 // Delete whatever the last array of differs was 59 // Delete whatever the last array of differs was
53 if (NULL != fDiffers) { 60 if (NULL != fDiffers) {
54 SkDELETE_ARRAY(fDiffers); 61 SkDELETE_ARRAY(fDiffers);
55 fDiffers = NULL; 62 fDiffers = NULL;
56 fDifferCount = 0; 63 fDifferCount = 0;
57 } 64 }
58 65
59 // Copy over the new differs 66 // Copy over the new differs
60 fDifferCount = differs.count(); 67 fDifferCount = differs.count();
(...skipping 11 matching lines...) Expand all
72 return result; 79 return result;
73 } 80 }
74 } 81 }
75 if (a.size() > b.size()) { 82 if (a.size() > b.size()) {
76 return b; 83 return b;
77 } else { 84 } else {
78 return a; 85 return a;
79 } 86 }
80 } 87 }
81 88
89 static SkString sanitize_name(const SkString& str) {
90 std::string result = std::string(str.c_str());
91 std::replace(result.begin(), result.end(), '.', '_');
92
93 return SkString(result.c_str());
94 }
95
96 static SkString get_combined_name(const SkString& a, const SkString& b) {
97 SkString result = a;
98 result.append("-vs-");
epoger 2014/08/11 19:33:28 Looking at _get_difference_locator() in imagediffd
stephana 2014/08/11 20:03:57 Yes, I just realized that it breaks the front-end
99 result.append(b);
100 return sanitize_name(result);
101 }
stephana 2014/08/11 14:58:31 This uses the <string> and <algorithm> headers inc
epoger 2014/08/11 19:33:28 A fine question... in my experience, within the Sk
stephana 2014/08/11 20:03:57 Make sense, I'll consult with Mike about this. O
102
82 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) { 103 void SkDiffContext::addDiff(const char* baselinePath, const char* testPath) {
83 // Load the images at the paths 104 // Load the images at the paths
84 SkBitmap baselineBitmap; 105 SkBitmap baselineBitmap;
85 SkBitmap testBitmap; 106 SkBitmap testBitmap;
86 if (!SkImageDecoder::DecodeFile(baselinePath, &baselineBitmap)) { 107 if (!SkImageDecoder::DecodeFile(baselinePath, &baselineBitmap)) {
87 SkDebugf("Failed to load bitmap \"%s\"\n", baselinePath); 108 SkDebugf("Failed to load bitmap \"%s\"\n", baselinePath);
88 return; 109 return;
89 } 110 }
90 if (!SkImageDecoder::DecodeFile(testPath, &testBitmap)) { 111 if (!SkImageDecoder::DecodeFile(testPath, &testBitmap)) {
91 SkDebugf("Failed to load bitmap \"%s\"\n", testPath); 112 SkDebugf("Failed to load bitmap \"%s\"\n", testPath);
92 return; 113 return;
93 } 114 }
94 115
95 // Setup a record for this diff 116 // Setup a record for this diff
96 fRecordMutex.acquire(); 117 fRecordMutex.acquire();
97 DiffRecord* newRecord = fRecords.addToHead(DiffRecord()); 118 DiffRecord* newRecord = fRecords.addToHead(DiffRecord());
98 fRecordMutex.release(); 119 fRecordMutex.release();
99 120
100 // compute the common name 121 // compute the common name
101 SkString baseName = SkOSPath::Basename(baselinePath); 122 SkString baseName = SkOSPath::Basename(baselinePath);
102 SkString testName = SkOSPath::Basename(testPath); 123 SkString testName = SkOSPath::Basename(testPath);
103 newRecord->fCommonName = get_common_prefix(baseName, testName); 124
125 if (longNames) {
126 newRecord->fCommonName = get_combined_name(baseName, testName);
127 } else {
128 newRecord->fCommonName = get_common_prefix(baseName, testName);
129 }
130 newRecord->fCommonName.append(".png");
104 131
105 newRecord->fBaselinePath = baselinePath; 132 newRecord->fBaselinePath = baselinePath;
106 newRecord->fTestPath = testPath; 133 newRecord->fTestPath = testPath;
107 newRecord->fSize = SkISize::Make(baselineBitmap.width(), baselineBitmap.heig ht()); 134 newRecord->fSize = SkISize::Make(baselineBitmap.width(), baselineBitmap.heig ht());
108 135
109 // only generate diff images if we have a place to store them 136 // only generate diff images if we have a place to store them
110 SkImageDiffer::BitmapsToCreate bitmapsToCreate; 137 SkImageDiffer::BitmapsToCreate bitmapsToCreate;
111 bitmapsToCreate.alphaMask = !fAlphaMaskDir.isEmpty(); 138 bitmapsToCreate.alphaMask = !fAlphaMaskDir.isEmpty();
112 bitmapsToCreate.rgbDiff = !fRgbDiffDir.isEmpty(); 139 bitmapsToCreate.rgbDiff = !fRgbDiffDir.isEmpty();
113 bitmapsToCreate.whiteDiff = !fWhiteDiffDir.isEmpty(); 140 bitmapsToCreate.whiteDiff = !fWhiteDiffDir.isEmpty();
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 for (int i = 0; i < cntColumns; i++) { 460 for (int i = 0; i < cntColumns; i++) {
434 SkString str; 461 SkString str;
435 str.printf(", %f", values[i]); 462 str.printf(", %f", values[i]);
436 stream.writeText(str.c_str()); 463 stream.writeText(str.c_str());
437 } 464 }
438 stream.writeText("\n"); 465 stream.writeText("\n");
439 466
440 currentRecord = iter2.next(); 467 currentRecord = iter2.next();
441 } 468 }
442 } 469 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698