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

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

Issue 29103005: update skpdiff visualization (image magnification with alpha mask) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tools/skpdiff/SkDiffContext.h ('k') | tools/skpdiff/SkDifferentPixelsMetric.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 23 matching lines...) Expand all
34 DiffRecord* nextRecord = currentRecord->fNext; 34 DiffRecord* nextRecord = currentRecord->fNext;
35 SkDELETE(currentRecord); 35 SkDELETE(currentRecord);
36 currentRecord = nextRecord; 36 currentRecord = nextRecord;
37 } 37 }
38 38
39 if (NULL != fDiffers) { 39 if (NULL != fDiffers) {
40 SkDELETE_ARRAY(fDiffers); 40 SkDELETE_ARRAY(fDiffers);
41 } 41 }
42 } 42 }
43 43
44 void SkDiffContext::setDifferenceDir(const SkString& path) {
45 if (!path.isEmpty() && sk_mkdir(path.c_str())) {
46 fDifferenceDir = path;
47 }
48 }
49
44 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) { 50 void SkDiffContext::setDiffers(const SkTDArray<SkImageDiffer*>& differs) {
45 // Delete whatever the last array of differs was 51 // Delete whatever the last array of differs was
46 if (NULL != fDiffers) { 52 if (NULL != fDiffers) {
47 SkDELETE_ARRAY(fDiffers); 53 SkDELETE_ARRAY(fDiffers);
48 fDiffers = NULL; 54 fDiffers = NULL;
49 fDifferCount = 0; 55 fDifferCount = 0;
50 } 56 }
51 57
52 // Copy over the new differs 58 // Copy over the new differs
53 fDifferCount = differs.count(); 59 fDifferCount = differs.count();
(...skipping 14 matching lines...) Expand all
68 return; 74 return;
69 } 75 }
70 76
71 // Setup a record for this diff 77 // Setup a record for this diff
72 DiffRecord* newRecord = SkNEW(DiffRecord); 78 DiffRecord* newRecord = SkNEW(DiffRecord);
73 newRecord->fBaselinePath = baselinePath; 79 newRecord->fBaselinePath = baselinePath;
74 newRecord->fTestPath = testPath; 80 newRecord->fTestPath = testPath;
75 newRecord->fNext = fRecords; 81 newRecord->fNext = fRecords;
76 fRecords = newRecord; 82 fRecords = newRecord;
77 83
84 // compute the common name
85 SkString baseName = SkOSPath::SkBasename(baselinePath);
86 SkString testName = SkOSPath::SkBasename(testPath);
87 const size_t maxNameLength = SkTMin(baseName.size(), testName.size());
epoger 2013/11/06 18:35:14 Please encapsulate this within a new method, somet
djsollen 2013/11/07 19:04:57 Done.
88 SkASSERT(maxNameLength > 0);
89 for (size_t x = 0; x < maxNameLength; ++x) {
90 if (baseName[x] != testName[x]) {
91 baseName.insertUnichar(x, '\n');
92 break;
93 }
94 }
95 newRecord->fCommonName = baseName;
96
97 bool alphaMaskPending = false;
98 bool alphaMaskCreated = false;
99
78 // Perform each diff 100 // Perform each diff
79 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { 101 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) {
80 SkImageDiffer* differ = fDiffers[differIndex]; 102 SkImageDiffer* differ = fDiffers[differIndex];
103 // TODO only enable for one differ
104 if (!alphaMaskCreated && !fDifferenceDir.isEmpty()) {
105 alphaMaskPending = differ->enablePOIAlphaMask();
106 }
81 int diffID = differ->queueDiff(&baselineBitmap, &testBitmap); 107 int diffID = differ->queueDiff(&baselineBitmap, &testBitmap);
82 if (diffID >= 0) { 108 if (diffID >= 0) {
83 109
84 // Copy the results into data for this record 110 // Copy the results into data for this record
85 DiffData& diffData = newRecord->fDiffs.push_back(); 111 DiffData& diffData = newRecord->fDiffs.push_back();
86 112
87 diffData.fDiffName = differ->getName(); 113 diffData.fDiffName = differ->getName();
88 diffData.fResult = differ->getResult(diffID); 114 diffData.fResult = differ->getResult(diffID);
89 115
90 int poiCount = differ->getPointsOfInterestCount(diffID); 116 int poiCount = differ->getPointsOfInterestCount(diffID);
91 SkIPoint* poi = differ->getPointsOfInterest(diffID); 117 SkIPoint* poi = differ->getPointsOfInterest(diffID);
92 diffData.fPointsOfInterest.append(poiCount, poi); 118 diffData.fPointsOfInterest.append(poiCount, poi);
93 119
120 if (alphaMaskPending
121 && SkImageDiffer::RESULT_CORRECT != diffData.fResult
122 && newRecord->fDifferencePath.isEmpty()) {
123 newRecord->fDifferencePath = SkOSPath::SkPathJoin(fDifferenceDir .c_str(),
124 newRecord->fCo mmonName.c_str());
125
126 // compute the image diff and output it
127 SkBitmap* alphaMask = differ->getPointsOfInterestAlphaMask(diffI D);
128 SkBitmap copy;
129 alphaMask->copyTo(&copy, SkBitmap::kARGB_8888_Config);
130 SkImageEncoder::EncodeFile(newRecord->fDifferencePath.c_str(), c opy,
131 SkImageEncoder::kPNG_Type, 100);
132 }
133
134 if (alphaMaskPending) {
135 alphaMaskPending = false;
136 alphaMaskCreated = true;
137 }
138
94 // Because we are doing everything synchronously for now, we are don e with the diff 139 // Because we are doing everything synchronously for now, we are don e with the diff
95 // after reading it. 140 // after reading it.
96 differ->deleteDiff(diffID); 141 differ->deleteDiff(diffID);
97 } 142 }
98 } 143 }
99 144
100 // if we get a difference and we want the alpha mask then compute it here. 145 // if we get a difference and we want the alpha mask then compute it here.
101 } 146 }
102 147
103 class SkThreadedDiff : public SkRunnable { 148 class SkThreadedDiff : public SkRunnable {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 stream.writeText("{\n"); 239 stream.writeText("{\n");
195 } 240 }
196 stream.writeText(" \"records\": [\n"); 241 stream.writeText(" \"records\": [\n");
197 while (NULL != currentRecord) { 242 while (NULL != currentRecord) {
198 stream.writeText(" {\n"); 243 stream.writeText(" {\n");
199 244
200 SkString differenceAbsPath = get_absolute_path(currentRecord->fDiffe rencePath); 245 SkString differenceAbsPath = get_absolute_path(currentRecord->fDiffe rencePath);
201 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselin ePath); 246 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselin ePath);
202 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); 247 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath);
203 248
204 // strip off directory structure and find the common part of the fil ename
205 SkString baseName = SkOSPath::SkBasename(baselineAbsPath.c_str());
206 SkString testName = SkOSPath::SkBasename(testAbsPath.c_str());
207 for (size_t x = 0; x < baseName.size(); ++x) {
208 if (baseName[x] != testName[x]) {
209 baseName.insertUnichar(x, '\n');
210 break;
211 }
212 }
213
214 stream.writeText(" \"commonName\": \""); 249 stream.writeText(" \"commonName\": \"");
215 stream.writeText(baseName.c_str()); 250 stream.writeText(currentRecord->fCommonName.c_str());
216 stream.writeText("\",\n"); 251 stream.writeText("\",\n");
217 252
218 stream.writeText(" \"differencePath\": \""); 253 stream.writeText(" \"differencePath\": \"");
219 stream.writeText(differenceAbsPath.c_str()); 254 stream.writeText(differenceAbsPath.c_str());
220 stream.writeText("\",\n"); 255 stream.writeText("\",\n");
221 256
222 stream.writeText(" \"baselinePath\": \""); 257 stream.writeText(" \"baselinePath\": \"");
223 stream.writeText(baselineAbsPath.c_str()); 258 stream.writeText(baselineAbsPath.c_str());
224 stream.writeText("\",\n"); 259 stream.writeText("\",\n");
225 260
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 for (int i = 0; i < cntColumns; i++) { 371 for (int i = 0; i < cntColumns; i++) {
337 SkString str; 372 SkString str;
338 str.printf(", %f", values[i]); 373 str.printf(", %f", values[i]);
339 stream.writeText(str.c_str()); 374 stream.writeText(str.c_str());
340 } 375 }
341 stream.writeText("\n"); 376 stream.writeText("\n");
342 377
343 currentRecord = currentRecord->fNext; 378 currentRecord = currentRecord->fNext;
344 } 379 }
345 } 380 }
OLDNEW
« no previous file with comments | « tools/skpdiff/SkDiffContext.h ('k') | tools/skpdiff/SkDifferentPixelsMetric.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698