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

Unified Diff: experimental/skpdiff/main.cpp

Issue 16284007: add skpdiff tool to compare bitmaps (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: experimental/skpdiff/main.cpp
diff --git a/experimental/skpdiff/main.cpp b/experimental/skpdiff/main.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6470c0ff4604a0191fdd0c747a168ee17a57f1c1
--- /dev/null
+++ b/experimental/skpdiff/main.cpp
@@ -0,0 +1,107 @@
+#include <iostream>
+#include <vector>
+#include <CL/cl.hpp>
+
+#include "SkBitmap.h"
+#include "SkImageDecoder.h"
+#include "SkImageEncoder.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
+
+#include "SkImageDiffer.h"
+#include "skpdiff_util.h"
+
+/// A callback for any OpenCL errors
+CL_CALLBACK void error_notify(const char* errorInfo, const void* privateInfoSize, ::size_t cb, void* userData) {
+ std::cerr << "OpenCL error notify: " << errorInfo << std::endl;
+ exit(1);
+}
+
+/// Creates a device and context with OpenCL
+static bool init_device_and_context(cl::Device* device, cl::Context* context) {
+ // Query for a platform
+ 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.
+ cl::Platform::get(&platformList);
+ std::cerr << "The number of platforms is " << platformList.size() << std::endl;
+
+ // Print some information about the platform for debugging
+ cl::Platform& platform = platformList[0];
+ std::string platformName;
+ platform.getInfo(CL_PLATFORM_NAME, &platformName);
+ std::cerr << "Platform index 0 is named " << platformName << std::endl;
+
+ // Query for a device
+ std::vector<cl::Device> deviceList;
+ platform.getDevices(CL_DEVICE_TYPE_GPU, &deviceList);
+ std::cerr << "The number of GPU devices is " << deviceList.size() << std::endl;
+
+ // Print some information about the device for debugging
+ *device = deviceList[0];
+ std::string deviceName;
+ device->getInfo(CL_DEVICE_NAME, &deviceName);
+ std::cerr << "Device index 0 is named " << deviceName << std::endl;
+
+ // Create a CL context and check for all errors
+ cl_int contextErr = CL_SUCCESS;
+ *context = cl::Context(deviceList, NULL, error_notify, NULL, &contextErr);
+ if (contextErr != CL_SUCCESS) {
+ std::cerr << "Context creation failed: " << cl_error_to_string(contextErr) << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+/// Compares two directories of images with the given differ
+static void diff_directories(const char baselinePath[], const char testPath[], ImageDiffer* differ) {
+ // Get the files in the baseline, we will then look for those inside the test path
+ std::vector<std::string> baselineEntries;
+ if (!get_directory(baselinePath, &baselineEntries)) {
+ std::cerr << "Unable to open path \"" << baselinePath << "\"" << std::endl;
+ return;
+ }
+
+ std::vector<int> queuedDiffIDs;
+ for (unsigned baselineIndex = 0; baselineIndex < baselineEntries.size(); baselineIndex++) {
+
+ const char* baseFilename = baselineEntries[baselineIndex].c_str();
+ std::cerr << baseFilename << std::endl;
+
+ // Find the real location of each file to compare
+ SkString baselineFile = SkOSPath::SkPathJoin(baselinePath, baseFilename);
+ SkString testFile = SkOSPath::SkPathJoin(testPath, baseFilename);
+
+ // Check that the test file exists and is a file
+ if (sk_exists(testFile.c_str()) && !sk_isdir(testFile.c_str())) {
+ // Queue up the comparison with the differ
+ int diffID = differ->queueDiffOfFile(baselineFile.c_str(), testFile.c_str());
+ if (diffID >= 0) {
+ queuedDiffIDs.push_back(diffID);
+ std::cerr << "Result: " << differ->getResult(diffID) << std::endl;
+ }
+ } else {
+ std::cerr << "Baseline file \"" << baselineFile.c_str() << "\" has no corresponding test file" << std::endl;
+ }
+ }
+}
+
+int main(int argc, char** argv) {
+ // Setup OpenCL
+ cl::Device device;
+ cl::Context context;
+ if (!init_device_and_context(&device, &context)) {
+ return 1;
+ }
+
+ // Setup our differ of choice
+ CLImageDiffer* differ = new DifferentPixelsImageDiffer();
bsalomon 2013/06/12 13:55:11 SkNEW(DifferentPixelsImageDiffer)
Zach Reizner 2013/06/12 21:57:47 Done.
+ 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
+ return 1;
+ }
+
+ // Diff our folders
+ diff_directories("/usr/local/google/home/zachr/Downloads/diffs/baseline",
+ "/usr/local/google/home/zachr/Downloads/diffs/test", differ);
+
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698