| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmap.h" |
| 8 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
| 9 #include "SkCommonFlags.h" | 10 #include "SkCommonFlags.h" |
| 10 #include "SkImageDecoder.h" | 11 #include "SkData.h" |
| 12 #include "SkForceLinking.h" |
| 13 #include "SkImage.h" |
| 11 #include "SkStream.h" | 14 #include "SkStream.h" |
| 12 #include "SkTypes.h" | 15 #include "SkTypes.h" |
| 13 | 16 |
| 14 #include "sk_tool_utils.h" | 17 #include "sk_tool_utils.h" |
| 15 | 18 |
| 19 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 20 |
| 16 DEFINE_string(in, "input.png", "Input image"); | 21 DEFINE_string(in, "input.png", "Input image"); |
| 17 DEFINE_string(out, "blurred.png", "Output image"); | 22 DEFINE_string(out, "blurred.png", "Output image"); |
| 18 DEFINE_double(sigma, 1, "Sigma to be used for blur (> 0.0f)"); | 23 DEFINE_double(sigma, 1, "Sigma to be used for blur (> 0.0f)"); |
| 19 | 24 |
| 20 | 25 |
| 21 // This tool just performs a blur on an input image | 26 // This tool just performs a blur on an input image |
| 22 // Return codes: | 27 // Return codes: |
| 23 static const int kSuccess = 0; | 28 static const int kSuccess = 0; |
| 24 static const int kError = 1; | 29 static const int kError = 1; |
| 25 | 30 |
| 26 int tool_main(int argc, char** argv); | 31 int tool_main(int argc, char** argv); |
| 27 int tool_main(int argc, char** argv) { | 32 int tool_main(int argc, char** argv) { |
| 28 SkCommandLineFlags::SetUsage("Brute force blur of an image."); | 33 SkCommandLineFlags::SetUsage("Brute force blur of an image."); |
| 29 SkCommandLineFlags::Parse(argc, argv); | 34 SkCommandLineFlags::Parse(argc, argv); |
| 30 | 35 |
| 31 if (FLAGS_sigma <= 0) { | 36 if (FLAGS_sigma <= 0) { |
| 32 if (!FLAGS_quiet) { | 37 if (!FLAGS_quiet) { |
| 33 SkDebugf("Sigma must be greater than zero (it is %f).\n", FLAGS_sigm
a); | 38 SkDebugf("Sigma must be greater than zero (it is %f).\n", FLAGS_sigm
a); |
| 34 } | 39 } |
| 35 return kError; | 40 return kError; |
| 36 } | 41 } |
| 37 | 42 |
| 38 SkFILEStream inputStream(FLAGS_in[0]); | 43 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_in[0])); |
| 39 if (!inputStream.isValid()) { | 44 if (nullptr == data) { |
| 40 if (!FLAGS_quiet) { | 45 if (!FLAGS_quiet) { |
| 41 SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]); | 46 SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]); |
| 42 } | 47 } |
| 43 return kError; | 48 return kError; |
| 44 } | 49 } |
| 45 | 50 |
| 46 SkAutoTDelete<SkImageDecoder> codec(SkImageDecoder::Factory(&inputStream)); | 51 SkAutoTDelete<SkImage> image(SkImage::NewFromEncoded(data)); |
| 47 if (!codec) { | 52 if (!image) { |
| 48 if (!FLAGS_quiet) { | 53 if (!FLAGS_quiet) { |
| 49 SkDebugf("Couldn't create codec for: %s.\n", FLAGS_in[0]); | 54 SkDebugf("Couldn't create image for: %s.\n", FLAGS_in[0]); |
| 50 } | 55 } |
| 51 return kError; | 56 return kError; |
| 52 } | 57 } |
| 53 | 58 |
| 54 SkBitmap src; | 59 SkBitmap src; |
| 55 | 60 if (!image->asLegacyBitmap(&src, SkImage::kRW_LegacyBitmapMode)) { |
| 56 inputStream.rewind(); | |
| 57 SkImageDecoder::Result res = codec->decode(&inputStream, &src, | |
| 58 kN32_SkColorType, | |
| 59 SkImageDecoder::kDecodePixels_Mod
e); | |
| 60 if (SkImageDecoder::kSuccess != res) { | |
| 61 if (!FLAGS_quiet) { | 61 if (!FLAGS_quiet) { |
| 62 SkDebugf("Couldn't decode image: %s.\n", FLAGS_in[0]); | 62 SkDebugf("Couldn't create bitmap for: %s.\n", FLAGS_in[0]); |
| 63 } | 63 } |
| 64 return kError; | 64 return kError; |
| 65 } | 65 } |
| 66 | 66 |
| 67 SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma); | 67 SkBitmap dst = sk_tool_utils::slow_blur(src, (float) FLAGS_sigma); |
| 68 | 68 |
| 69 if (!SkImageEncoder::EncodeFile(FLAGS_out[0], dst, SkImageEncoder::kPNG_Type
, 100)) { | 69 if (!SkImageEncoder::EncodeFile(FLAGS_out[0], dst, SkImageEncoder::kPNG_Type
, 100)) { |
| 70 if (!FLAGS_quiet) { | 70 if (!FLAGS_quiet) { |
| 71 SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]); | 71 SkDebugf("Couldn't write to file: %s\n", FLAGS_out[0]); |
| 72 } | 72 } |
| 73 return kError; | 73 return kError; |
| 74 } | 74 } |
| 75 | 75 |
| 76 return kSuccess; | 76 return kSuccess; |
| 77 } | 77 } |
| 78 | 78 |
| 79 #if !defined SK_BUILD_FOR_IOS | 79 #if !defined SK_BUILD_FOR_IOS |
| 80 int main(int argc, char * const argv[]) { | 80 int main(int argc, char * const argv[]) { |
| 81 return tool_main(argc, (char**) argv); | 81 return tool_main(argc, (char**) argv); |
| 82 } | 82 } |
| 83 #endif | 83 #endif |
| OLD | NEW |