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

Side by Side Diff: experimental/skpdiff/main.cpp

Issue 17885003: add command line flags (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add TODOs Created 7 years, 5 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
« no previous file with comments | « experimental/skpdiff/SkCLImageDiffer.cpp ('k') | experimental/skpdiff/skpdiff.gyp » ('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 #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"
13 #include "SkGraphics.h"
12 #include "SkOSFile.h" 14 #include "SkOSFile.h"
13 #include "SkStream.h"
14 #include "SkString.h" 15 #include "SkString.h"
15 #include "SkTArray.h" 16 #include "SkTArray.h"
16 #include "SkTDArray.h" 17 #include "SkTDArray.h"
17 18
18 #include "SkImageDiffer.h" 19 #include "SkImageDiffer.h"
19 #include "SkCLImageDiffer.h" 20 #include "SkCLImageDiffer.h"
20 #include "skpdiff_util.h" 21 #include "skpdiff_util.h"
21 22
23 #include "SkForceLinking.h"
24 __SK_FORCE_IMAGE_DECODER_LINKING;
25
26 // Command line argument definitions go here
27 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(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
22 /// A callback for any OpenCL errors 32 /// A callback for any OpenCL errors
23 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) { 33 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) {
24 SkDebugf("OpenCL error notify: %s\n", errorInfo); 34 SkDebugf("OpenCL error notify: %s\n", errorInfo);
25 exit(1); 35 exit(1);
26 } 36 }
27 37
28 /// Creates a device and context with OpenCL 38 /// Creates a device and context with OpenCL
29 static bool init_device_and_context(cl::Device* device, cl::Context* context) { 39 static bool init_device_and_context(cl::Device* device, cl::Context* context) {
30 // Query for a platform 40 // Query for a platform
31 cl::vector<cl::Platform> platformList; 41 cl::vector<cl::Platform> platformList;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (diffID >= 0) { 95 if (diffID >= 0) {
86 queuedDiffIDs.push(diffID); 96 queuedDiffIDs.push(diffID);
87 SkDebugf("Result: %f\n", differ->getResult(diffID)); 97 SkDebugf("Result: %f\n", differ->getResult(diffID));
88 } 98 }
89 } else { 99 } else {
90 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba selineFile.c_str()); 100 SkDebugf("Baseline file \"%s\" has no corresponding test file\n", ba selineFile.c_str());
91 } 101 }
92 } 102 }
93 } 103 }
94 104
95 static void print_help() 105
96 { 106 /// Compares two sets of images identified by glob style patterns with the given differ
97 SkDebugf( 107 static void diff_patterns(const char baselinePattern[], const char testPattern[] , SkImageDiffer* differ) {
98 "Usage:\n" \ 108 // Get the files in the baseline and test patterns. Because they are in sort ed order, it's easy
99 "skpdiff <baseline directory> <test directory>\n\n" 109 // to find corresponding images by matching entry indices.
100 ); 110 //
111 SkTArray<SkString> baselineEntries;
112 if (!glob_files(baselinePattern, &baselineEntries)) {
113 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern);
114 return;
115 }
116
117 SkTArray<SkString> testEntries;
118 if (!glob_files(testPattern, &testEntries)) {
119 SkDebugf("Unable to get pattern \"%s\"\n", testPattern);
120 return;
121 }
122
123 if (baselineEntries.count() != testEntries.count()) {
124 SkDebugf("Baseline and test patterns do not yield corresponding number o f files\n");
125 return;
126 }
127
128 SkTDArray<int> queuedDiffIDs;
129 for (int entryIndex = 0; entryIndex < baselineEntries.count(); entryIndex++) {
130 const char* baselineFilename = baselineEntries[entryIndex].c_str();
131 const char* testFilename = testEntries [entryIndex].c_str();
132 SkDebugf("%s %s\n", baselineFilename, testFilename);
133
134 int diffID = differ->queueDiffOfFile(baselineFilename, testFilename);
135 if (diffID >= 0) {
136 queuedDiffIDs.push(diffID);
137 SkDebugf("Result: %f\n", differ->getResult(diffID));
138 }
139 }
101 } 140 }
102 141
103 int main(int argc, char** argv) {
104 if (argc != 3)
105 {
106 print_help();
107 return 1;
108 }
109 142
143 static bool init_cl_diff(SkImageDiffer* differ)
144 {
110 // Setup OpenCL 145 // Setup OpenCL
111 cl::Device device; 146 cl::Device device;
112 cl::Context context; 147 cl::Context context;
113 if (!init_device_and_context(&device, &context)) { 148 if (!init_device_and_context(&device, &context)) {
114 return 1; 149 return false;
115 } 150 }
116 151
117 // Setup our differ of choice 152 // Setup our differ of choice
118 SkCLImageDiffer* differ = SkNEW(SkDifferentPixelsImageDiffer); 153 SkCLImageDiffer* clDiffer = (SkCLImageDiffer*)differ;
119 if (!differ->init(device(), context())) { 154 return clDiffer->init(device(), context());
120 return 1; 155 }
156
157 // TODO Find a better home for the diff registry. One possibility is to have the differs self
158 // register.
159
160 // List here every differ
161 SkDifferentPixelsImageDiffer gDiffPixel;
162
163 /// A null terminated array of pointer to every differ declared above
164 SkImageDiffer* gDiffers[] = { &gDiffPixel, NULL };
165
166 /// A parallel array of functions to initialize the above differs
167 bool (*gDiffInits[])(SkImageDiffer*) = { init_cl_diff, NULL };
168
169
170 int main(int argc, char** argv) {
171 // Setup command line parsing
172 SkCommandLineFlags::SetUsage("Compare images using various metrics.");
173 SkCommandLineFlags::Parse(argc, argv);
174
175 // Needed by various Skia components
176 SkAutoGraphics ag;
177
178 if (FLAGS_list) {
179 SkDebugf("Available Metrics:\n");
121 } 180 }
122 181
123 // Diff our folders 182 // Figure which differs the user chose, and optionally print them if the use r requests it
124 diff_directories(argv[1], argv[2], differ); 183 SkTDArray<int> chosenDiffers;
184 for (int differIndex = 0; NULL != gDiffers[differIndex]; differIndex++) {
185 if (FLAGS_list) {
186 SkDebugf(" %s", gDiffers[differIndex]->getName());
187 SkDebugf("\n");
188 }
189
190 // Check if this differ was chosen by any of the flags
191 if (FLAGS_differs.isEmpty()) {
192 // If no differs were chosen, they all get added
193 chosenDiffers.push(differIndex);
194 } else {
195 for (int flagIndex = 0; flagIndex < FLAGS_differs.count(); flagIndex ++) {
196 if (SkString(FLAGS_differs[flagIndex]).equals(gDiffers[differInd ex]->getName())) {
197 chosenDiffers.push(differIndex);
198 break;
199 }
200 }
201 }
202 }
203
204 // Don't attempt to initialize the differ if we aren't going to use it
205 if (FLAGS_folders.isEmpty() && FLAGS_patterns.isEmpty()) {
206 return 0;
207 }
208
209 // Validate command line flags
210 if (!FLAGS_folders.isEmpty()) {
211 if (2 != FLAGS_folders.count()) {
212 SkDebugf("Folders flag expects two arguments: <baseline folder> <tes t folder>\n");
213 return 1;
214 }
215 }
216
217 if (!FLAGS_patterns.isEmpty()) {
218 if (2 != FLAGS_patterns.count()) {
219 SkDebugf("Patterns flag expects two arguments: <baseline pattern> <t est pattern>\n");
220 return 1;
221 }
222 }
223
224 // 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
226 // be helped.
227
228 // Perform each requested diff
229 for (int differIndex = 0; differIndex < chosenDiffers.count(); differIndex++ ) {
230 // Get the chosen differ and say which one they chose
231 SkImageDiffer * differ = gDiffers[differIndex];
232 SkDebugf("Using differ \"%s\"\n", differ->getName());
233
234 // Initialize the differ using the global list of init functions that ma tch the list of
235 // differs
236 gDiffInits[differIndex](differ);
237
238 // Perform a folder diff if one is requested
239 if (!FLAGS_folders.isEmpty()) {
240 diff_directories(FLAGS_folders[0], FLAGS_folders[1], differ);
241 }
242
243 // Perform a pattern diff if one is requested
244 if (!FLAGS_patterns.isEmpty()) {
245 diff_patterns(FLAGS_patterns[0], FLAGS_patterns[1], differ);
246 }
247 }
125 248
126 return 0; 249 return 0;
127 } 250 }
OLDNEW
« no previous file with comments | « experimental/skpdiff/SkCLImageDiffer.cpp ('k') | experimental/skpdiff/skpdiff.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698