diff options
author | reed <reed@google.com> | 2014-12-17 13:08:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-17 13:08:17 -0800 |
commit | a816d95b1eef414262fdc2e78c7be515402aec8b (patch) | |
tree | bf8c6b30d790b98faa775288abbec621bbf3c75a | |
parent | 41bc28843a3ff32a969b5ef12688fa44545ee200 (diff) |
version 0 of imgconv tool
BUG=skia:
Review URL: https://codereview.chromium.org/809143002
-rw-r--r-- | gyp/tools.gyp | 12 | ||||
-rw-r--r-- | tools/imgconv.cpp | 43 |
2 files changed, 55 insertions, 0 deletions
diff --git a/gyp/tools.gyp b/gyp/tools.gyp index ffd5676a75..3b1d2f5ae0 100644 --- a/gyp/tools.gyp +++ b/gyp/tools.gyp @@ -20,6 +20,7 @@ 'gpuveto', 'lua_app', 'lua_pictures', + 'imgconv', 'pinspect', 'render_pdfs', 'render_pictures', @@ -545,6 +546,17 @@ ], }, { + 'target_name': 'imgconv', + 'type': 'executable', + 'sources': [ + '../tools/imgconv.cpp', + ], + 'dependencies': [ + 'flags.gyp:flags', + 'skia_lib.gyp:skia_lib', + ], + }, + { 'target_name': 'bbh_shootout', 'type': 'executable', 'include_dirs': [ diff --git a/tools/imgconv.cpp b/tools/imgconv.cpp new file mode 100644 index 0000000000..4c9fb600bb --- /dev/null +++ b/tools/imgconv.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkBitmap.h" +#include "SkGraphics.h" +#include "SkImageDecoder.h" +#include "SkImageEncoder.h" +#include "SkString.h" + +int tool_main(int argc, char** argv); +int tool_main(int argc, char** argv) { + SkAutoGraphics ag; + + for (int i = 1; i < argc; ++i) { + SkString src(argv[i]); + if (src.endsWith(".png")) { + SkString dst(src.c_str(), src.size() - 4); + dst.append(".jpg"); + + SkBitmap bm; + if (SkImageDecoder::DecodeFile(src.c_str(), &bm)) { + if (SkImageEncoder::EncodeFile(dst.c_str(), bm, SkImageEncoder::kJPEG_Type, 100)) { + SkDebugf("converted %s to %s\n", src.c_str(), dst.c_str()); + } else { + SkDebugf("failed to encode %s\n", src.c_str()); + } + } else { + SkDebugf("failed to decode %s\n", src.c_str()); + } + } + } + return 0; +} + +#if !defined SK_BUILD_FOR_IOS +int main(int argc, char * const argv[]) { + return tool_main(argc, (char**) argv); +} +#endif |