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 |
| 19 | |
|
djsollen
2013/06/26 14:34:02
remove
| |
| 18 #include "SkImageDiffer.h" | 20 #include "SkImageDiffer.h" |
| 19 #include "SkCLImageDiffer.h" | 21 #include "SkCLImageDiffer.h" |
| 20 #include "skpdiff_util.h" | 22 #include "skpdiff_util.h" |
| 21 | 23 |
| 24 #include "SkForceLinking.h" | |
| 25 __SK_FORCE_IMAGE_DECODER_LINKING; | |
| 26 | |
| 27 // Command line argument definitions go here | |
| 28 DEFINE_bool2(list, l, false, "List out available differs"); | |
| 29 DEFINE_int32(differ, 0, "The index of the differ to use. Uses 0 if not given."); | |
|
djsollen
2013/06/26 14:34:02
instead of using an index it will be much clearer
| |
| 30 DEFINE_string2(folders, f, "", "Compare two folders with identical subfile names : <baseline folder> <test folder>"); | |
| 31 DEFINE_string2(patterns, p, "", "Use two patterns to compare images: <baseline> <test>"); | |
| 32 | |
| 22 /// A callback for any OpenCL errors | 33 /// A callback for any OpenCL errors |
| 23 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) { | 34 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) { |
| 24 SkDebugf("OpenCL error notify: %s\n", errorInfo); | 35 SkDebugf("OpenCL error notify: %s\n", errorInfo); |
| 25 exit(1); | 36 exit(1); |
| 26 } | 37 } |
| 27 | 38 |
| 28 /// Creates a device and context with OpenCL | 39 /// Creates a device and context with OpenCL |
| 29 static bool init_device_and_context(cl::Device* device, cl::Context* context) { | 40 static bool init_device_and_context(cl::Device* device, cl::Context* context) { |
| 30 // Query for a platform | 41 // Query for a platform |
| 31 cl::vector<cl::Platform> platformList; | 42 cl::vector<cl::Platform> platformList; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 if (diffID >= 0) { | 96 if (diffID >= 0) { |
| 86 queuedDiffIDs.push(diffID); | 97 queuedDiffIDs.push(diffID); |
| 87 SkDebugf("Result: %f\n", differ->getResult(diffID)); | 98 SkDebugf("Result: %f\n", differ->getResult(diffID)); |
| 88 } | 99 } |
| 89 } else { | 100 } else { |
| 90 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()); |
| 91 } | 102 } |
| 92 } | 103 } |
| 93 } | 104 } |
| 94 | 105 |
| 95 static void print_help() | 106 |
| 96 { | 107 /// Compares two sets of images identified by glob style patterns with the given differ |
| 97 SkDebugf( | 108 static void diff_patterns(const char baselinePattern[], const char testPattern[] , SkImageDiffer* differ) { |
| 98 "Usage:\n" \ | 109 // 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" | 110 // to find corresponding images by matching entry indices. |
| 100 ); | 111 // |
| 112 SkTArray<SkString> baselineEntries; | |
| 113 if (!glob_files(baselinePattern, &baselineEntries)) { | |
| 114 SkDebugf("Unable to get pattern \"%s\"\n", baselinePattern); | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 SkTArray<SkString> testEntries; | |
| 119 if (!glob_files(testPattern, &testEntries)) { | |
| 120 SkDebugf("Unable to get pattern \"%s\"\n", testPattern); | |
| 121 return; | |
| 122 } | |
| 123 | |
| 124 if (baselineEntries.count() != testEntries.count()) { | |
| 125 SkDebugf("Baseline and test patterns do not yield corresponding number o f files\n"); | |
| 126 return; | |
| 127 } | |
| 128 | |
| 129 SkTDArray<int> queuedDiffIDs; | |
| 130 for (int entryIndex = 0; entryIndex < baselineEntries.count(); entryIndex++) { | |
| 131 const char* baselineFilename = baselineEntries[entryIndex].c_str(); | |
| 132 const char* testFilename = testEntries [entryIndex].c_str(); | |
| 133 SkDebugf("%s %s\n", baselineFilename, testFilename); | |
| 134 | |
| 135 int diffID = differ->queueDiffOfFile(baselineFilename, testFilename); | |
| 136 if (diffID >= 0) { | |
| 137 queuedDiffIDs.push(diffID); | |
| 138 SkDebugf("Result: %f\n", differ->getResult(diffID)); | |
| 139 } | |
| 140 } | |
| 101 } | 141 } |
| 102 | 142 |
| 103 int main(int argc, char** argv) { | |
| 104 if (argc != 3) | |
| 105 { | |
| 106 print_help(); | |
| 107 return 1; | |
| 108 } | |
| 109 | 143 |
| 144 static bool init_cl_diff(SkImageDiffer* differ) | |
| 145 { | |
| 110 // Setup OpenCL | 146 // Setup OpenCL |
| 111 cl::Device device; | 147 cl::Device device; |
| 112 cl::Context context; | 148 cl::Context context; |
| 113 if (!init_device_and_context(&device, &context)) { | 149 if (!init_device_and_context(&device, &context)) { |
| 150 return false; | |
| 151 } | |
| 152 | |
| 153 // Setup our differ of choice | |
| 154 SkCLImageDiffer* clDiffer = (SkCLImageDiffer*)differ; | |
| 155 return clDiffer->init(device(), context()); | |
| 156 } | |
| 157 | |
| 158 // List here every differ | |
| 159 SkDifferentPixelsImageDiffer gDiffPixel; | |
| 160 | |
| 161 /// A null terminated array of pointer to every differ declared above | |
| 162 SkImageDiffer* gDiffers[] = { &gDiffPixel, NULL }; | |
| 163 | |
| 164 /// A parallel array of functions to initialize the above differs | |
| 165 bool (*gDiffInits[])(SkImageDiffer*) = { init_cl_diff, NULL }; | |
| 166 | |
| 167 | |
| 168 int main(int argc, char** argv) { | |
| 169 // Setup command line parsing | |
| 170 SkCommandLineFlags::SetUsage("Compare images using various metrics."); | |
| 171 SkCommandLineFlags::Parse(argc, argv); | |
| 172 | |
| 173 // Needed by various Skia components | |
| 174 SkAutoGraphics ag; | |
| 175 | |
| 176 // Calculate the number of differs, and optionally print them if the user re quests it | |
| 177 int numDiffers; | |
| 178 int differIndex; | |
| 179 for (differIndex = 0; NULL != gDiffers[differIndex]; differIndex++) { | |
| 180 if (FLAGS_list) { | |
| 181 SkDebugf("%i) %s", differIndex, gDiffers[differIndex]->getName()); | |
| 182 // The first differ in the list is the default one | |
| 183 if (0 == differIndex) { | |
| 184 SkDebugf(" (default)"); | |
| 185 } | |
| 186 SkDebugf("\n"); | |
| 187 } | |
| 188 } | |
| 189 numDiffers = differIndex; | |
| 190 | |
| 191 | |
| 192 // Don't attempt to initialize the differ if we aren't going to use it | |
| 193 if (FLAGS_folders.isEmpty() && FLAGS_patterns.isEmpty()) { | |
| 194 return 0; | |
| 195 } | |
| 196 | |
| 197 // Check that the chosen differ is real | |
| 198 if (FLAGS_differ < 0 || FLAGS_differ >= numDiffers) { | |
| 199 SkDebugf("The differ index given is invalid.\n"); | |
| 114 return 1; | 200 return 1; |
| 115 } | 201 } |
| 116 | 202 |
| 117 // Setup our differ of choice | 203 // Get the chosen differ and say which one they chose |
| 118 SkCLImageDiffer* differ = SkNEW(SkDifferentPixelsImageDiffer); | 204 SkImageDiffer * differ = gDiffers[FLAGS_differ]; |
| 119 if (!differ->init(device(), context())) { | 205 SkDebugf("Using differ \"%s\"\n", differ->getName()); |
| 120 return 1; | 206 |
| 207 // Initialize the differ using the global list of init functions that match the list of differs | |
| 208 gDiffInits[FLAGS_differ](differ); | |
| 209 | |
| 210 // Perform a folder diff if one is requested | |
| 211 if (!FLAGS_folders.isEmpty()) { | |
| 212 if (2 == FLAGS_folders.count()) { | |
| 213 diff_directories(FLAGS_folders[0], FLAGS_folders[1], differ); | |
| 214 } else { | |
| 215 SkDebugf("Folders flag expects two arguments: <baseline folder> <tes t folder>\n"); | |
| 216 } | |
| 121 } | 217 } |
| 122 | 218 |
| 123 // Diff our folders | 219 // Perform a pattern diff if one is requested |
| 124 diff_directories(argv[1], argv[2], differ); | 220 if (!FLAGS_patterns.isEmpty()) { |
| 221 if (2 == FLAGS_patterns.count()) { | |
| 222 diff_patterns(FLAGS_patterns[0], FLAGS_patterns[1], differ); | |
| 223 } else { | |
| 224 SkDebugf("Patterns flag expects two arguments: <baseline pattern> <t est pattern>\n"); | |
| 225 } | |
| 226 } | |
| 125 | 227 |
| 126 return 0; | 228 return 0; |
| 127 } | 229 } |
| OLD | NEW |