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

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, 2 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 | Annotate | Revision Log
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
epoger 2013/10/21 15:02:53 What does "common name" mean exactly? Does it mea
djsollen 2013/11/06 16:02:30 Since the input can be two arbitrary files it mean
85 SkString baseName = SkOSPath::SkBasename(baselinePath);
86 SkString testName = SkOSPath::SkBasename(testPath);
87 for (size_t x = 0; x < baseName.size(); ++x) {
88 if (baseName[x] != testName[x]) {
epoger 2013/10/21 15:02:53 Is there the possibility for out-of-bounds referen
djsollen 2013/11/06 16:02:30 Done.
89 baseName.insertUnichar(x, '\n');
epoger 2013/10/21 15:02:53 Why do you insert a newline rather than just trunc
djsollen 2013/11/06 16:02:30 SkString doesn't support realloc so if we were to
epoger 2013/11/06 18:35:14 I don't understand how inserting a newline actuall
90 break;
91 }
92 }
93 newRecord->fCommonName = baseName.c_str();
94
78 // Perform each diff 95 // Perform each diff
79 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { 96 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) {
80 SkImageDiffer* differ = fDiffers[differIndex]; 97 SkImageDiffer* differ = fDiffers[differIndex];
98 // TODO only enable for one differ
99 differ->enablePOIAlphaMask();
81 int diffID = differ->queueDiff(&baselineBitmap, &testBitmap); 100 int diffID = differ->queueDiff(&baselineBitmap, &testBitmap);
82 if (diffID >= 0) { 101 if (diffID >= 0) {
83 102
84 // Copy the results into data for this record 103 // Copy the results into data for this record
85 DiffData& diffData = newRecord->fDiffs.push_back(); 104 DiffData& diffData = newRecord->fDiffs.push_back();
86 105
87 diffData.fDiffName = differ->getName(); 106 diffData.fDiffName = differ->getName();
88 diffData.fResult = differ->getResult(diffID); 107 diffData.fResult = differ->getResult(diffID);
89 108
90 int poiCount = differ->getPointsOfInterestCount(diffID); 109 int poiCount = differ->getPointsOfInterestCount(diffID);
91 SkIPoint* poi = differ->getPointsOfInterest(diffID); 110 SkIPoint* poi = differ->getPointsOfInterest(diffID);
92 diffData.fPointsOfInterest.append(poiCount, poi); 111 diffData.fPointsOfInterest.append(poiCount, poi);
93 112
113 if (!fDifferenceDir.isEmpty()
114 && 1.0f != diffData.fResult
epoger 2013/10/21 15:02:53 Is 1.0 a "magic number" that fResult is assigned i
djsollen 2013/11/06 16:02:30 Done.
115 && newRecord->fDifferencePath.isEmpty()) {
116 newRecord->fDifferencePath = SkOSPath::SkPathJoin(fDifferenceDir .c_str(),
117 newRecord->fCo mmonName.c_str());
epoger 2013/10/21 15:02:53 Is fCommonName an SkString or a const char *? Li
djsollen 2013/11/06 16:02:30 It is an SkString. I updated line 93 for clarity.
118
119 // compute the image diff and output it
120 SkBitmap* alphaMask = differ->getPointsOfInterestAlphaMask(diffI D);
121 SkBitmap copy;
122 alphaMask->copyTo(&copy, SkBitmap::kARGB_8888_Config);
123 SkImageEncoder::EncodeFile(newRecord->fDifferencePath.c_str(), c opy,
124 SkImageEncoder::kPNG_Type, 100);
125 }
126
94 // Because we are doing everything synchronously for now, we are don e with the diff 127 // Because we are doing everything synchronously for now, we are don e with the diff
95 // after reading it. 128 // after reading it.
96 differ->deleteDiff(diffID); 129 differ->deleteDiff(diffID);
97 } 130 }
98 } 131 }
99 132
100 // if we get a difference and we want the alpha mask then compute it here. 133 // if we get a difference and we want the alpha mask then compute it here.
101 } 134 }
102 135
103 class SkThreadedDiff : public SkRunnable { 136 class SkThreadedDiff : public SkRunnable {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 stream.writeText("{\n"); 227 stream.writeText("{\n");
195 } 228 }
196 stream.writeText(" \"records\": [\n"); 229 stream.writeText(" \"records\": [\n");
197 while (NULL != currentRecord) { 230 while (NULL != currentRecord) {
198 stream.writeText(" {\n"); 231 stream.writeText(" {\n");
199 232
200 SkString differenceAbsPath = get_absolute_path(currentRecord->fDiffe rencePath); 233 SkString differenceAbsPath = get_absolute_path(currentRecord->fDiffe rencePath);
201 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselin ePath); 234 SkString baselineAbsPath = get_absolute_path(currentRecord->fBaselin ePath);
202 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath); 235 SkString testAbsPath = get_absolute_path(currentRecord->fTestPath);
203 236
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\": \""); 237 stream.writeText(" \"commonName\": \"");
215 stream.writeText(baseName.c_str()); 238 stream.writeText(currentRecord->fCommonName.c_str());
epoger 2013/10/21 15:02:53 ditto (const char * vs SkString)
216 stream.writeText("\",\n"); 239 stream.writeText("\",\n");
217 240
218 stream.writeText(" \"differencePath\": \""); 241 stream.writeText(" \"differencePath\": \"");
219 stream.writeText(differenceAbsPath.c_str()); 242 stream.writeText(differenceAbsPath.c_str());
220 stream.writeText("\",\n"); 243 stream.writeText("\",\n");
221 244
222 stream.writeText(" \"baselinePath\": \""); 245 stream.writeText(" \"baselinePath\": \"");
223 stream.writeText(baselineAbsPath.c_str()); 246 stream.writeText(baselineAbsPath.c_str());
224 stream.writeText("\",\n"); 247 stream.writeText("\",\n");
225 248
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 for (int i = 0; i < cntColumns; i++) { 359 for (int i = 0; i < cntColumns; i++) {
337 SkString str; 360 SkString str;
338 str.printf(", %f", values[i]); 361 str.printf(", %f", values[i]);
339 stream.writeText(str.c_str()); 362 stream.writeText(str.c_str());
340 } 363 }
341 stream.writeText("\n"); 364 stream.writeText("\n");
342 365
343 currentRecord = currentRecord->fNext; 366 currentRecord = currentRecord->fNext;
344 } 367 }
345 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698