robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 8 | #include "SkBitmap.h" |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 9 | #include "SkCommandLineFlags.h" |
| 10 | #include "SkCommonFlags.h" |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 11 | #include "SkData.h" |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 12 | #include "SkImage.h" |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 13 | #include "SkStream.h" |
| 14 | #include "SkTypes.h" |
| 15 | |
| 16 | #include "sk_tool_utils.h" |
| 17 | |
| 18 | DEFINE_string(in, "input.png", "Input image"); |
| 19 | DEFINE_string(out, "blurred.png", "Output image"); |
| 20 | DEFINE_double(sigma, 1, "Sigma to be used for blur (> 0.0f)"); |
| 21 | |
| 22 | |
| 23 | // This tool just performs a blur on an input image |
| 24 | // Return codes: |
| 25 | static const int kSuccess = 0; |
| 26 | static const int kError = 1; |
| 27 | |
Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 28 | int main(int argc, char** argv) { |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 29 | SkCommandLineFlags::SetUsage("Brute force blur of an image."); |
| 30 | SkCommandLineFlags::Parse(argc, argv); |
| 31 | |
| 32 | if (FLAGS_sigma <= 0) { |
| 33 | if (!FLAGS_quiet) { |
| 34 | SkDebugf("Sigma must be greater than zero (it is %f).\n", FLAGS_sigma); |
| 35 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 36 | return kError; |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 37 | } |
| 38 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 39 | sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_in[0])); |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 40 | if (nullptr == data) { |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 41 | if (!FLAGS_quiet) { |
| 42 | SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]); |
| 43 | } |
| 44 | return kError; |
| 45 | } |
| 46 | |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 47 | sk_sp<SkImage> image(SkImage::MakeFromEncoded(data)); |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 48 | if (!image) { |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 49 | if (!FLAGS_quiet) { |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 50 | SkDebugf("Couldn't create image for: %s.\n", FLAGS_in[0]); |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 51 | } |
| 52 | return kError; |
| 53 | } |
| 54 | |
| 55 | SkBitmap src; |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 56 | if (!image->asLegacyBitmap(&src, SkImage::kRW_LegacyBitmapMode)) { |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 57 | if (!FLAGS_quiet) { |
msarett | f7a840a | 2016-03-09 10:09:02 -0800 | [diff] [blame] | 58 | SkDebugf("Couldn't create bitmap for: %s.\n", FLAGS_in[0]); |
| 59 | } |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 60 | return kError; |
| 61 | } |
| 62 | |
| 63 | SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma); |
| 64 | |
Hal Canary | db68301 | 2016-11-23 08:55:18 -0700 | [diff] [blame] | 65 | if (!sk_tool_utils::EncodeImageToFile(FLAGS_out[0], dst, SkEncodedImageFormat::kPNG, 100)) { |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 66 | if (!FLAGS_quiet) { |
| 67 | SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]); |
| 68 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 69 | return kError; |
robertphillips | 9c4909b | 2015-10-19 06:39:17 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | return kSuccess; |
| 73 | } |