Chromium Code Reviews| 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" | |
| 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 Loading... | |
| 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 // List here every differ | |
| 158 SkDifferentPixelsImageDiffer gDiffPixel; | |
|
djsollen
2013/06/27 12:43:50
why does this or the 2 arrays below need to be glo
| |
| 159 | |
| 160 /// A null terminated array of pointer to every differ declared above | |
| 161 SkImageDiffer* gDiffers[] = { &gDiffPixel, NULL }; | |
| 162 | |
| 163 /// A parallel array of functions to initialize the above differs | |
| 164 bool (*gDiffInits[])(SkImageDiffer*) = { init_cl_diff, NULL }; | |
| 165 | |
| 166 | |
| 167 int main(int argc, char** argv) { | |
| 168 // Setup command line parsing | |
| 169 SkCommandLineFlags::SetUsage("Compare images using various metrics."); | |
| 170 SkCommandLineFlags::Parse(argc, argv); | |
| 171 | |
| 172 // Needed by various Skia components | |
| 173 SkAutoGraphics ag; | |
| 174 | |
| 175 if (FLAGS_list) { | |
| 176 SkDebugf("Differs:\n"); | |
|
djsollen
2013/06/27 12:43:50
"available metrics" as the user facing way to desc
| |
| 121 } | 177 } |
| 122 | 178 |
| 123 // Diff our folders | 179 // Figure which differs the user chose, and optionally print them if the use r requests it |
| 124 diff_directories(argv[1], argv[2], differ); | 180 SkTDArray<int> chosenDiffers; |
| 181 for (int differIndex = 0; NULL != gDiffers[differIndex]; differIndex++) { | |
| 182 if (FLAGS_list) { | |
| 183 SkDebugf(" %s", gDiffers[differIndex]->getName()); | |
| 184 SkDebugf("\n"); | |
| 185 } | |
| 186 | |
| 187 // Check if this differ was chosen by any of the flags | |
| 188 if (FLAGS_differs.isEmpty()) { | |
| 189 // If no differs were chosen, they all get added | |
| 190 chosenDiffers.push(differIndex); | |
| 191 } else { | |
| 192 for (int flagIndex = 0; flagIndex < FLAGS_differs.count(); flagIndex ++) { | |
| 193 if (SkString(FLAGS_differs[flagIndex]).equals(gDiffers[differInd ex]->getName())) { | |
| 194 chosenDiffers.push(differIndex); | |
| 195 break; | |
| 196 } | |
| 197 } | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 // Don't attempt to initialize the differ if we aren't going to use it | |
| 202 if (FLAGS_folders.isEmpty() && FLAGS_patterns.isEmpty()) { | |
| 203 return 0; | |
| 204 } | |
| 205 | |
| 206 // Validate command line flags | |
| 207 if (!FLAGS_folders.isEmpty()) { | |
| 208 if (2 != FLAGS_folders.count()) { | |
| 209 SkDebugf("Folders flag expects two arguments: <baseline folder> <tes t folder>\n"); | |
| 210 return 1; | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 if (!FLAGS_patterns.isEmpty()) { | |
| 215 if (2 != FLAGS_patterns.count()) { | |
| 216 SkDebugf("Patterns flag expects two arguments: <baseline pattern> <t est pattern>\n"); | |
| 217 return 1; | |
| 218 } | |
| 219 } | |
| 220 | |
| 221 // Perform each requested diff | |
| 222 for (int differIndex = 0; differIndex < chosenDiffers.count(); differIndex++ ) { | |
|
djsollen
2013/06/27 12:43:50
This is going to be a pretty inefficient method of
| |
| 223 // Get the chosen differ and say which one they chose | |
| 224 SkImageDiffer * differ = gDiffers[differIndex]; | |
| 225 SkDebugf("Using differ \"%s\"\n", differ->getName()); | |
| 226 | |
| 227 // Initialize the differ using the global list of init functions that ma tch the list of differs | |
|
djsollen
2013/06/27 12:43:50
exceeds 100 char
| |
| 228 gDiffInits[differIndex](differ); | |
| 229 | |
| 230 // Perform a folder diff if one is requested | |
| 231 if (!FLAGS_folders.isEmpty()) { | |
| 232 diff_directories(FLAGS_folders[0], FLAGS_folders[1], differ); | |
| 233 } | |
| 234 | |
| 235 // Perform a pattern diff if one is requested | |
| 236 if (!FLAGS_patterns.isEmpty()) { | |
| 237 diff_patterns(FLAGS_patterns[0], FLAGS_patterns[1], differ); | |
| 238 } | |
| 239 } | |
| 125 | 240 |
| 126 return 0; | 241 return 0; |
| 127 } | 242 } |
| OLD | NEW |