2015-10-19 13:39:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-03-09 18:09:02 +00:00
|
|
|
#include "SkBitmap.h"
|
2015-10-19 13:39:17 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkCommonFlags.h"
|
2016-03-09 18:09:02 +00:00
|
|
|
#include "SkData.h"
|
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkImage.h"
|
2015-10-19 13:39:17 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include "sk_tool_utils.h"
|
|
|
|
|
2016-03-09 18:09:02 +00:00
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
2015-10-19 13:39:17 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
return kError;
|
2015-10-19 13:39:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeFromFileName(FLAGS_in[0]));
|
2016-03-09 18:09:02 +00:00
|
|
|
if (nullptr == data) {
|
2015-10-19 13:39:17 +00:00
|
|
|
if (!FLAGS_quiet) {
|
|
|
|
SkDebugf("Couldn't open file: %s\n", FLAGS_in[0]);
|
|
|
|
}
|
|
|
|
return kError;
|
|
|
|
}
|
|
|
|
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(SkImage::MakeFromEncoded(data));
|
2016-03-09 18:09:02 +00:00
|
|
|
if (!image) {
|
2015-10-19 13:39:17 +00:00
|
|
|
if (!FLAGS_quiet) {
|
2016-03-09 18:09:02 +00:00
|
|
|
SkDebugf("Couldn't create image for: %s.\n", FLAGS_in[0]);
|
2015-10-19 13:39:17 +00:00
|
|
|
}
|
|
|
|
return kError;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap src;
|
2016-03-09 18:09:02 +00:00
|
|
|
if (!image->asLegacyBitmap(&src, SkImage::kRW_LegacyBitmapMode)) {
|
2015-10-19 13:39:17 +00:00
|
|
|
if (!FLAGS_quiet) {
|
2016-03-09 18:09:02 +00:00
|
|
|
SkDebugf("Couldn't create bitmap for: %s.\n", FLAGS_in[0]);
|
|
|
|
}
|
2015-10-19 13:39:17 +00:00
|
|
|
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]);
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
return kError;
|
2015-10-19 13:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|