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

Unified Diff: tools/imgblur.cpp

Issue 1384203002: Add imgblur tool to assist BlurMaskFilter debugging (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 5 years, 2 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
« no previous file with comments | « gyp/tools.gyp ('k') | tools/sk_tool_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/imgblur.cpp
diff --git a/tools/imgblur.cpp b/tools/imgblur.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5ee8b123707d8a652c6a901789da1a956bc19354
--- /dev/null
+++ b/tools/imgblur.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCommandLineFlags.h"
+#include "SkCommonFlags.h"
+#include "SkImageDecoder.h"
+#include "SkStream.h"
+#include "SkTypes.h"
+
+#include "sk_tool_utils.h"
+
+DEFINE_string(in, "input.png", "Input image");
+DEFINE_string(out, "blurred.png", "Output image");
+DEFINE_double(sigma, 1, "Sigma to be used for blur (> 0.0f)");
+
+
+// This tool just performs a blur on an input image
+// Return codes:
+static const int kSuccess = 0;
+static const int kError = 1;
+
+int tool_main(int argc, char** argv);
+int tool_main(int argc, char** argv) {
+ SkCommandLineFlags::SetUsage("Brute force blur of an image.");
+ SkCommandLineFlags::Parse(argc, argv);
+
+ if (FLAGS_sigma <= 0) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Sigma must be greater than zero (it is %f).\n", FLAGS_sigma);
+ }
+ return kError;
+ }
+
+ SkFILEStream inputStream(FLAGS_in[0]);
+ if (!inputStream.isValid()) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]);
+ }
+ return kError;
+ }
+
+ SkAutoTDelete<SkImageDecoder> codec(SkImageDecoder::Factory(&inputStream));
+ if (!codec) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Couldn't create codec for: %s.\n", FLAGS_in[0]);
+ }
+ return kError;
+ }
+
+ SkBitmap src;
+
+ inputStream.rewind();
+ SkImageDecoder::Result res = codec->decode(&inputStream, &src,
+ kN32_SkColorType,
+ SkImageDecoder::kDecodePixels_Mode);
+ if (SkImageDecoder::kSuccess != res) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Couldn't decode image: %s.\n", FLAGS_in[0]);
+ }
+ return kError;
+ }
+
+ SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma);
+
+ if (!SkImageEncoder::EncodeFile(FLAGS_out[0], dst, SkImageEncoder::kPNG_Type, 100)) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]);
+ }
+ return kError;
+ }
+
+ return kSuccess;
+}
+
+#if !defined SK_BUILD_FOR_IOS
+int main(int argc, char * const argv[]) {
+ return tool_main(argc, (char**) argv);
+}
+#endif
« no previous file with comments | « gyp/tools.gyp ('k') | tools/sk_tool_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698