OLD | NEW |
---|---|
(Empty) | |
1 #include <iostream> | |
2 #include <vector> | |
3 #include <CL/cl.hpp> | |
4 | |
5 #include "SkBitmap.h" | |
6 #include "SkImageDecoder.h" | |
7 #include "SkImageEncoder.h" | |
8 #include "SkOSFile.h" | |
9 #include "SkStream.h" | |
10 | |
11 #include "SkImageDiffer.h" | |
12 #include "skpdiff_util.h" | |
13 | |
14 /// A callback for any OpenCL errors | |
15 CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize , ::size_t cb, void* userData) { | |
16 std::cerr << "OpenCL error notify: " << errorInfo << std::endl; | |
17 exit(1); | |
18 } | |
19 | |
20 /// Creates a device and context with OpenCL | |
21 static bool init_device_and_context(cl::Device* device, cl::Context* context) { | |
22 // Query for a platform | |
23 std::vector<cl::Platform> platformList; | |
djsollen
2013/06/12 13:32:04
looks like you can also use cl::vector< cl::Platfo
Zach Reizner
2013/06/12 21:57:47
Done.
| |
24 cl::Platform::get(&platformList); | |
25 std::cerr << "The number of platforms is " << platformList.size() << std::en dl; | |
26 | |
27 // Print some information about the platform for debugging | |
28 cl::Platform& platform = platformList[0]; | |
29 std::string platformName; | |
30 platform.getInfo(CL_PLATFORM_NAME, &platformName); | |
31 std::cerr << "Platform index 0 is named " << platformName << std::endl; | |
32 | |
33 // Query for a device | |
34 std::vector<cl::Device> deviceList; | |
35 platform.getDevices(CL_DEVICE_TYPE_GPU, &deviceList); | |
36 std::cerr << "The number of GPU devices is " << deviceList.size() << std::en dl; | |
37 | |
38 // Print some information about the device for debugging | |
39 *device = deviceList[0]; | |
40 std::string deviceName; | |
41 device->getInfo(CL_DEVICE_NAME, &deviceName); | |
42 std::cerr << "Device index 0 is named " << deviceName << std::endl; | |
43 | |
44 // Create a CL context and check for all errors | |
45 cl_int contextErr = CL_SUCCESS; | |
46 *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr); | |
47 if (contextErr != CL_SUCCESS) { | |
48 std::cerr << "Context creation failed: " << cl_error_to_string(contextEr r) << std::endl; | |
49 return false; | |
50 } | |
51 | |
52 return true; | |
53 } | |
54 | |
55 /// Compares two directories of images with the given differ | |
56 static void diff_directories(const char baselinePath[], const char testPath[], I mageDiffer* differ) { | |
57 // Get the files in the baseline, we will then look for those inside the tes t path | |
58 std::vector<std::string> baselineEntries; | |
59 if (!get_directory(baselinePath, &baselineEntries)) { | |
60 std::cerr << "Unable to open path \"" << baselinePath << "\"" << std::en dl; | |
61 return; | |
62 } | |
63 | |
64 std::vector<int> queuedDiffIDs; | |
65 for (unsigned baselineIndex = 0; baselineIndex < baselineEntries.size(); bas elineIndex++) { | |
66 | |
67 const char* baseFilename = baselineEntries[baselineIndex].c_str(); | |
68 std::cerr << baseFilename << std::endl; | |
69 | |
70 // Find the real location of each file to compare | |
71 SkString baselineFile = SkOSPath::SkPathJoin(baselinePath, baseFilename) ; | |
72 SkString testFile = SkOSPath::SkPathJoin(testPath, baseFilename); | |
73 | |
74 // Check that the test file exists and is a file | |
75 if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) { | |
76 // Queue up the comparison with the differ | |
77 int diffID = differ->queueDiffOfFile(baselineFile.c_str(), testFile. c_str()); | |
78 if (diffID >= 0) { | |
79 queuedDiffIDs.push_back(diffID); | |
80 std::cerr << "Result: " << differ->getResult(diffID) << std::end l; | |
81 } | |
82 } else { | |
83 std::cerr << "Baseline file \"" << baselineFile.c_str() << "\" has n o corresponding test file" << std::endl; | |
84 } | |
85 } | |
86 } | |
87 | |
88 int main(int argc, char** argv) { | |
89 // Setup OpenCL | |
90 cl::Device device; | |
91 cl::Context context; | |
92 if (!init_device_and_context(&device, &context)) { | |
93 return 1; | |
94 } | |
95 | |
96 // Setup our differ of choice | |
97 CLImageDiffer* differ = new DifferentPixelsImageDiffer(); | |
bsalomon
2013/06/12 13:55:11
SkNEW(DifferentPixelsImageDiffer)
Zach Reizner
2013/06/12 21:57:47
Done.
| |
98 if (!differ->init(device(), context())) { | |
djsollen
2013/06/12 13:32:04
why do you need an init method if you can just pas
Zach Reizner
2013/06/12 21:57:47
I plan to make it so that all differs can be const
| |
99 return 1; | |
100 } | |
101 | |
102 // Diff our folders | |
103 diff_directories("/usr/local/google/home/zachr/Downloads/diffs/baseline", | |
104 "/usr/local/google/home/zachr/Downloads/diffs/test", differ) ; | |
105 | |
106 return 0; | |
107 } | |
OLD | NEW |