1 /* 2 * Copyright 2014 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 8 #include "SkBitmap.h" 9 #include "SkGraphics.h" 10 #include "SkImageDecoder.h" 11 #include "SkImageEncoder.h" 12 #include "SkString.h" 13 14 int tool_main(int argc, char** argv); 15 int tool_main(int argc, char** argv) { 16 SkAutoGraphics ag; 17 18 for (int i = 1; i < argc; ++i) { 19 SkString src(argv[i]); 20 if (src.endsWith(".png")) { 21 SkString dst(src.c_str(), src.size() - 4); 22 dst.append(".jpg"); 23 24 SkBitmap bm; 25 if (SkImageDecoder::DecodeFile(src.c_str(), &bm)) { 26 if (SkImageEncoder::EncodeFile(dst.c_str(), bm, SkImageEncoder::kJPEG_Type, 100)) { 27 SkDebugf("converted %s to %s\n", src.c_str(), dst.c_str()); 28 } else { 29 SkDebugf("failed to encode %s\n", src.c_str()); 30 } 31 } else { 32 SkDebugf("failed to decode %s\n", src.c_str()); 33 } 34 } 35 } 36 return 0; 37 } 38 39 #if !defined SK_BUILD_FOR_IOS 40 int main(int argc, char * const argv[]) { 41 return tool_main(argc, (char**) argv); 42 } 43 #endif 44