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 #define __NO_STD_VECTOR // Uses cl::vectpr instead of std::vectpr | 8 #define __NO_STD_VECTOR // Uses cl::vectpr instead of std::vectpr |
9 #define __NO_STD_STRING // Uses cl::STRING_CLASS instead of std::string | 9 #define __NO_STD_STRING // Uses cl::STRING_CLASS instead of std::string |
10 #include <CL/cl.hpp> | 10 #include <CL/cl.hpp> |
11 | 11 |
12 #include "SkCommandLineFlags.h" | 12 #include "SkCommandLineFlags.h" |
13 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
15 #include "SkString.h" | 15 #include "SkString.h" |
16 #include "SkTArray.h" | 16 #include "SkTArray.h" |
17 #include "SkTDArray.h" | 17 #include "SkTDArray.h" |
18 | 18 |
19 #include "SkImageDiffer.h" | 19 #include "SkImageDiffer.h" |
20 #include "SkCLImageDiffer.h" | 20 #include "SkCLImageDiffer.h" |
| 21 #include "SkPMetric.h" |
21 #include "skpdiff_util.h" | 22 #include "skpdiff_util.h" |
22 | 23 |
23 #include "SkForceLinking.h" | 24 #include "SkForceLinking.h" |
24 __SK_FORCE_IMAGE_DECODER_LINKING; | 25 __SK_FORCE_IMAGE_DECODER_LINKING; |
25 | 26 |
26 // Command line argument definitions go here | 27 // Command line argument definitions go here |
27 DEFINE_bool2(list, l, false, "List out available differs"); | 28 DEFINE_bool2(list, l, false, "List out available differs"); |
28 DEFINE_string2(differs, d, "", "The names of the differs to use or all of them b
y default"); | 29 DEFINE_string2(differs, d, "", "The names of the differs to use or all of them b
y default"); |
29 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names
: <baseline folder> <test folder>"); | 30 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names
: <baseline folder> <test folder>"); |
30 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline>
<test>"); | 31 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline>
<test>"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba
selineFile.c_str()); | 101 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba
selineFile.c_str()); |
101 } | 102 } |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 | 106 |
106 /// Compares two sets of images identified by glob style patterns with the given
differ | 107 /// Compares two sets of images identified by glob style patterns with the given
differ |
107 static void diff_patterns(const char baselinePattern[], const char testPattern[]
, SkImageDiffer* differ) { | 108 static void diff_patterns(const char baselinePattern[], const char testPattern[]
, SkImageDiffer* differ) { |
108 // Get the files in the baseline and test patterns. Because they are in sort
ed order, it's easy | 109 // Get the files in the baseline and test patterns. Because they are in sort
ed order, it's easy |
109 // to find corresponding images by matching entry indices. | 110 // to find corresponding images by matching entry indices. |
110 // | 111 |
111 SkTArray<SkString> baselineEntries; | 112 SkTArray<SkString> baselineEntries; |
112 if (!glob_files(baselinePattern, &baselineEntries)) { | 113 if (!glob_files(baselinePattern, &baselineEntries)) { |
113 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); | 114 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); |
114 return; | 115 return; |
115 } | 116 } |
116 | 117 |
117 SkTArray<SkString> testEntries; | 118 SkTArray<SkString> testEntries; |
118 if (!glob_files(testPattern, &testEntries)) { | 119 if (!glob_files(testPattern, &testEntries)) { |
119 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); | 120 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); |
120 return; | 121 return; |
(...skipping 12 matching lines...) Expand all Loading... |
133 | 134 |
134 int diffID = differ->queueDiffOfFile(baselineFilename, testFilename); | 135 int diffID = differ->queueDiffOfFile(baselineFilename, testFilename); |
135 if (diffID >= 0) { | 136 if (diffID >= 0) { |
136 queuedDiffIDs.push(diffID); | 137 queuedDiffIDs.push(diffID); |
137 SkDebugf("Result: %f\n", differ->getResult(diffID)); | 138 SkDebugf("Result: %f\n", differ->getResult(diffID)); |
138 } | 139 } |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 | 143 |
143 static bool init_cl_diff(SkImageDiffer* differ) | 144 static bool init_cl_diff(SkImageDiffer* differ) { |
144 { | |
145 // Setup OpenCL | 145 // Setup OpenCL |
146 cl::Device device; | 146 cl::Device device; |
147 cl::Context context; | 147 cl::Context context; |
148 if (!init_device_and_context(&device, &context)) { | 148 if (!init_device_and_context(&device, &context)) { |
149 return false; | 149 return false; |
150 } | 150 } |
151 | 151 |
152 // Setup our differ of choice | 152 // Setup our differ of choice |
153 SkCLImageDiffer* clDiffer = (SkCLImageDiffer*)differ; | 153 SkCLImageDiffer* clDiffer = (SkCLImageDiffer*)differ; |
154 return clDiffer->init(device(), context()); | 154 return clDiffer->init(device(), context()); |
155 } | 155 } |
156 | 156 |
| 157 static bool init_dummy(SkImageDiffer* differ) { |
| 158 return true; |
| 159 } |
| 160 |
| 161 |
157 // TODO Find a better home for the diff registry. One possibility is to have the
differs self | 162 // TODO Find a better home for the diff registry. One possibility is to have the
differs self |
158 // register. | 163 // register. |
159 | 164 |
160 // List here every differ | 165 // List here every differ |
161 SkDifferentPixelsImageDiffer gDiffPixel; | 166 SkDifferentPixelsImageDiffer gDiffPixel; |
| 167 SkPMetric gPDiff; |
162 | 168 |
163 /// A null terminated array of pointer to every differ declared above | 169 // A null terminated array of pointer to every differ declared above |
164 SkImageDiffer* gDiffers[] = { &gDiffPixel, NULL }; | 170 SkImageDiffer* gDiffers[] = { &gDiffPixel, &gPDiff, NULL }; |
165 | 171 |
166 /// A parallel array of functions to initialize the above differs | 172 // A parallel array of functions to initialize the above differs. The reason we
don't initialize |
167 bool (*gDiffInits[])(SkImageDiffer*) = { init_cl_diff, NULL }; | 173 // everything immediately is that certain differs may require special initializa
tion, but we still |
| 174 // want to construct all of them globally so they can be queried for things like
their name and |
| 175 // description. |
| 176 bool (*gDiffInits[])(SkImageDiffer*) = { init_cl_diff, init_dummy, NULL }; |
168 | 177 |
169 | 178 |
170 int main(int argc, char** argv) { | 179 int main(int argc, char** argv) { |
171 // Setup command line parsing | 180 // Setup command line parsing |
172 SkCommandLineFlags::SetUsage("Compare images using various metrics."); | 181 SkCommandLineFlags::SetUsage("Compare images using various metrics."); |
173 SkCommandLineFlags::Parse(argc, argv); | 182 SkCommandLineFlags::Parse(argc, argv); |
174 | 183 |
175 // Needed by various Skia components | 184 // Needed by various Skia components |
176 SkAutoGraphics ag; | 185 SkAutoGraphics ag; |
177 | 186 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 SkDebugf("Patterns flag expects two arguments: <baseline pattern> <t
est pattern>\n"); | 228 SkDebugf("Patterns flag expects two arguments: <baseline pattern> <t
est pattern>\n"); |
220 return 1; | 229 return 1; |
221 } | 230 } |
222 } | 231 } |
223 | 232 |
224 // TODO Move the differ loop to after the bitmaps are decoded and/or uploade
d to the OpenCL | 233 // TODO Move the differ loop to after the bitmaps are decoded and/or uploade
d to the OpenCL |
225 // device. Those are often the slowest processes and should not be done more
than once if it can | 234 // device. Those are often the slowest processes and should not be done more
than once if it can |
226 // be helped. | 235 // be helped. |
227 | 236 |
228 // Perform each requested diff | 237 // Perform each requested diff |
229 for (int differIndex = 0; differIndex < chosenDiffers.count(); differIndex++
) { | 238 for (int chosenDifferIndex = 0; chosenDifferIndex < chosenDiffers.count(); c
hosenDifferIndex++) { |
| 239 int differIndex = chosenDiffers[chosenDifferIndex]; |
| 240 |
230 // Get the chosen differ and say which one they chose | 241 // Get the chosen differ and say which one they chose |
231 SkImageDiffer * differ = gDiffers[differIndex]; | 242 SkImageDiffer * differ = gDiffers[differIndex]; |
232 SkDebugf("Using differ \"%s\"\n", differ->getName()); | 243 SkDebugf("Using metric \"%s\"\n", differ->getName()); |
233 | 244 |
234 // Initialize the differ using the global list of init functions that ma
tch the list of | 245 // Initialize the differ using the global list of init functions that ma
tch the list of |
235 // differs | 246 // differs |
236 gDiffInits[differIndex](differ); | 247 gDiffInits[differIndex](differ); |
237 | 248 |
238 // Perform a folder diff if one is requested | 249 // Perform a folder diff if one is requested |
239 if (!FLAGS_folders.isEmpty()) { | 250 if (!FLAGS_folders.isEmpty()) { |
240 diff_directories(FLAGS_folders[0], FLAGS_folders[1], differ); | 251 diff_directories(FLAGS_folders[0], FLAGS_folders[1], differ); |
241 } | 252 } |
242 | 253 |
243 // Perform a pattern diff if one is requested | 254 // Perform a pattern diff if one is requested |
244 if (!FLAGS_patterns.isEmpty()) { | 255 if (!FLAGS_patterns.isEmpty()) { |
245 diff_patterns(FLAGS_patterns[0], FLAGS_patterns[1], differ); | 256 diff_patterns(FLAGS_patterns[0], FLAGS_patterns[1], differ); |
246 } | 257 } |
247 } | 258 } |
248 | 259 |
249 return 0; | 260 return 0; |
250 } | 261 } |
OLD | NEW |