2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkCommandLineFlags.h"
9 #include "SkCommonFlags.h"
10 #include "SkImageDecoder.h"
14 #include "sk_tool_utils.h"
16 DEFINE_string(in, "input.png", "Input image");
17 DEFINE_string(out, "blurred.png", "Output image");
18 DEFINE_double(sigma, 1, "Sigma to be used for blur (> 0.0f)");
21 // This tool just performs a blur on an input image
23 static const int kSuccess = 0;
24 static const int kError = 1;
26 int tool_main(int argc, char** argv);
27 int tool_main(int argc, char** argv) {
28 SkCommandLineFlags::SetUsage("Brute force blur of an image.");
29 SkCommandLineFlags::Parse(argc, argv);
31 if (FLAGS_sigma <= 0) {
33 SkDebugf("Sigma must be greater than zero (it is %f).\n", FLAGS_sigma);
38 SkFILEStream inputStream(FLAGS_in[0]);
39 if (!inputStream.isValid()) {
41 SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]);
46 SkAutoTDelete<SkImageDecoder> codec(SkImageDecoder::Factory(&inputStream));
49 SkDebugf("Couldn't create codec for: %s.\n", FLAGS_in[0]);
57 SkImageDecoder::Result res = codec->decode(&inputStream, &src,
59 SkImageDecoder::kDecodePixels_Mode);
60 if (SkImageDecoder::kSuccess != res) {
62 SkDebugf("Couldn't decode image: %s.\n", FLAGS_in[0]);
67 SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma);
69 if (!SkImageEncoder::EncodeFile(FLAGS_out[0], dst, SkImageEncoder::kPNG_Type, 100)) {
71 SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]);
79 #if !defined SK_BUILD_FOR_IOS
80 int main(int argc, char * const argv[]) {
81 return tool_main(argc, (char**) argv);