OLD | NEW |
---|---|
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 "SkCommandLineFlags.h" | |
9 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
10 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
11 #include "SkStream.h" | 12 #include "SkStream.h" |
12 | 13 |
13 #include "SkDiffContext.h" | 14 #include "SkDiffContext.h" |
14 #include "SkImageDiffer.h" | 15 #include "SkImageDiffer.h" |
15 #include "skpdiff_util.h" | 16 #include "skpdiff_util.h" |
16 | 17 |
18 DECLARE_string(csv); | |
19 | |
17 SkDiffContext::SkDiffContext() { | 20 SkDiffContext::SkDiffContext() { |
18 fRecords = NULL; | 21 fRecords = NULL; |
19 fDiffers = NULL; | 22 fDiffers = NULL; |
20 fDifferCount = 0; | 23 fDifferCount = 0; |
21 } | 24 } |
22 | 25 |
23 SkDiffContext::~SkDiffContext() { | 26 SkDiffContext::~SkDiffContext() { |
24 // Delete the record linked list | 27 // Delete the record linked list |
25 DiffRecord* currentRecord = fRecords; | 28 DiffRecord* currentRecord = fRecords; |
26 while (NULL != currentRecord) { | 29 while (NULL != currentRecord) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 return; | 64 return; |
62 } | 65 } |
63 | 66 |
64 // Setup a record for this diff | 67 // Setup a record for this diff |
65 DiffRecord* newRecord = SkNEW(DiffRecord); | 68 DiffRecord* newRecord = SkNEW(DiffRecord); |
66 newRecord->fBaselinePath = baselinePath; | 69 newRecord->fBaselinePath = baselinePath; |
67 newRecord->fTestPath = testPath; | 70 newRecord->fTestPath = testPath; |
68 newRecord->fNext = fRecords; | 71 newRecord->fNext = fRecords; |
69 fRecords = newRecord; | 72 fRecords = newRecord; |
70 | 73 |
74 FILE* csvFile = NULL; | |
Zach Reizner
2013/07/19 18:35:08
Output of CSV should be done in a similar manner a
edisonn
2013/07/19 20:27:23
Done.
| |
75 if (!FLAGS_csv.isEmpty()) { | |
76 csvFile = fopen(FLAGS_csv[0], "a"); | |
77 SkASSERT(csvFile); | |
78 if (ftell(csvFile) == 0) { | |
79 fprintf(csvFile, "%s", "skp"); | |
80 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { | |
81 SkImageDiffer* differ = fDiffers[differIndex]; | |
82 fprintf(csvFile, ", %s", differ->getName()); | |
83 } | |
84 fprintf(csvFile, "\n"); | |
85 } | |
86 } | |
87 | |
88 if (csvFile) { | |
89 const char* filename = baselinePath + strlen(baselinePath) - 1; | |
90 while (filename > baselinePath && *(filename - 1) != '/') { | |
91 filename--; | |
92 } | |
93 fprintf(csvFile, "%s", filename); | |
94 } | |
95 | |
71 // Perform each diff | 96 // Perform each diff |
72 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { | 97 for (int differIndex = 0; differIndex < fDifferCount; differIndex++) { |
73 SkImageDiffer* differ = fDiffers[differIndex]; | 98 SkImageDiffer* differ = fDiffers[differIndex]; |
74 int diffID = differ->queueDiff(&baselineBitmap, &testBitmap); | 99 int diffID = differ->queueDiff(&baselineBitmap, &testBitmap); |
75 if (diffID >= 0) { | 100 if (diffID >= 0) { |
76 | 101 |
77 // Copy the results into data for this record | 102 // Copy the results into data for this record |
78 DiffData& diffData = newRecord->fDiffs.push_back(); | 103 DiffData& diffData = newRecord->fDiffs.push_back(); |
79 | 104 |
80 diffData.fDiffName = differ->getName(); | 105 diffData.fDiffName = differ->getName(); |
81 diffData.fResult = differ->getResult(diffID); | 106 diffData.fResult = differ->getResult(diffID); |
82 | 107 |
108 if (csvFile) { | |
109 fprintf(csvFile, ", %f", diffData.fResult); | |
110 } | |
111 | |
83 int poiCount = differ->getPointsOfInterestCount(diffID); | 112 int poiCount = differ->getPointsOfInterestCount(diffID); |
84 SkIPoint* poi = differ->getPointsOfInterest(diffID); | 113 SkIPoint* poi = differ->getPointsOfInterest(diffID); |
85 diffData.fPointsOfInterest.append(poiCount, poi); | 114 diffData.fPointsOfInterest.append(poiCount, poi); |
86 | 115 |
87 // Because we are doing everything synchronously for now, we are don e with the diff | 116 // Because we are doing everything synchronously for now, we are don e with the diff |
88 // after reading it. | 117 // after reading it. |
89 differ->deleteDiff(diffID); | 118 differ->deleteDiff(diffID); |
119 } else { | |
120 if (csvFile) { | |
121 fprintf(csvFile, ", -1"); | |
122 } | |
90 } | 123 } |
91 } | 124 } |
125 | |
126 if (csvFile) { | |
127 fprintf(csvFile, "\n"); | |
128 fclose(csvFile); | |
129 } | |
92 } | 130 } |
93 | 131 |
94 | 132 |
95 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa th[]) { | 133 void SkDiffContext::diffDirectories(const char baselinePath[], const char testPa th[]) { |
96 // Get the files in the baseline, we will then look for those inside the tes t path | 134 // Get the files in the baseline, we will then look for those inside the tes t path |
97 SkTArray<SkString> baselineEntries; | 135 SkTArray<SkString> baselineEntries; |
98 if (!get_directory(baselinePath, &baselineEntries)) { | 136 if (!get_directory(baselinePath, &baselineEntries)) { |
99 SkDebugf("Unable to open path \"%s\"\n", baselinePath); | 137 SkDebugf("Unable to open path \"%s\"\n", baselinePath); |
100 return; | 138 return; |
101 } | 139 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 } | 261 } |
224 stream.writeText(" ]\n"); | 262 stream.writeText(" ]\n"); |
225 if (useJSONP) { | 263 if (useJSONP) { |
226 stream.writeText("};\n"); | 264 stream.writeText("};\n"); |
227 } | 265 } |
228 else | 266 else |
229 { | 267 { |
230 stream.writeText("}\n"); | 268 stream.writeText("}\n"); |
231 } | 269 } |
232 } | 270 } |
OLD | NEW |