OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
| 12 #include "SkEncodedFormat.h" |
12 #include "SkForceLinking.h" | 13 #include "SkForceLinking.h" |
13 #include "SkGraphics.h" | 14 #include "SkGraphics.h" |
14 #include "SkImageDecoder.h" | 15 #include "SkImageDecoder.h" |
15 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
16 #include "SkOSFile.h" | 17 #include "SkOSFile.h" |
17 #include "SkRandom.h" | 18 #include "SkRandom.h" |
18 #include "SkStream.h" | 19 #include "SkStream.h" |
19 #include "SkTArray.h" | 20 #include "SkTArray.h" |
20 #include "SkTemplates.h" | 21 #include "SkTemplates.h" |
21 | 22 |
22 __SK_FORCE_IMAGE_DECODER_LINKING; | 23 __SK_FORCE_IMAGE_DECODER_LINKING; |
23 | 24 |
24 DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.
"); | 25 DEFINE_string2(readPath, r, "", "Folder(s) and files to decode images. Required.
"); |
25 | 26 |
26 struct Format { | |
27 SkImageEncoder::Type fType; | |
28 SkImageDecoder::Format fFormat; | |
29 const char* fSuffix; | |
30 }; | |
31 | |
32 /* | |
33 static const Format gFormats[] = { | |
34 { SkImageEncoder::kBMP_Type, SkImageDecoder::kBMP_Format, ".bmp" }, | |
35 { SkImageEncoder::kGIF_Type, SkImageDecoder::kGIF_Format, ".gif" }, | |
36 { SkImageEncoder::kICO_Type, SkImageDecoder::kICO_Format, ".ico" }, | |
37 { SkImageEncoder::kJPEG_Type, SkImageDecoder::kJPEG_Format, ".jpg" }, | |
38 { SkImageEncoder::kPNG_Type, SkImageDecoder::kPNG_Format, ".png" }, | |
39 { SkImageEncoder::kWBMP_Type, SkImageDecoder::kWBMP_Format, ".wbmp" }, | |
40 { SkImageEncoder::kWEBP_Type, SkImageDecoder::kWEBP_Format, ".webp" } | |
41 }; | |
42 */ | |
43 | |
44 static SkISize opaqueSize(const SkBitmap& bm) { | 27 static SkISize opaqueSize(const SkBitmap& bm) { |
45 int width = 1; | 28 int width = 1; |
46 int height = 1; | 29 int height = 1; |
47 for (int y = 0 ; y < bm.height(); y++) { | 30 for (int y = 0 ; y < bm.height(); y++) { |
48 for (int x = 0 ; x < bm.width(); x++) { | 31 for (int x = 0 ; x < bm.width(); x++) { |
49 SkColor color = bm.getColor(x, y); | 32 SkColor color = bm.getColor(x, y); |
50 if (SkColorGetA(color) != 0) { | 33 if (SkColorGetA(color) != 0) { |
51 height = y + 1; | 34 height = y + 1; |
52 width = width > (x + 1) ? width : x + 1; | 35 width = width > (x + 1) ? width : x + 1; |
53 } | 36 } |
(...skipping 28 matching lines...) Expand all Loading... |
82 g = (g * a) / 255; | 65 g = (g * a) / 255; |
83 b = (b * a) / 255; | 66 b = (b * a) / 255; |
84 a = 255; | 67 a = 255; |
85 } | 68 } |
86 color = SkColorSetARGB((U8CPU)a, (U8CPU)r, (U8CPU)g, (U8CPU)b); | 69 color = SkColorSetARGB((U8CPU)a, (U8CPU)r, (U8CPU)g, (U8CPU)b); |
87 } | 70 } |
88 *dst.getAddr32(x, y) = color; | 71 *dst.getAddr32(x, y) = color; |
89 } | 72 } |
90 } | 73 } |
91 | 74 |
92 return SkImageEncoder::EncodeFile(outName, dst, SkImageEncoder::kPNG_Type, 1
00); | 75 return SkImageEncoder::EncodeFile(outName, dst, kPNG_SkEncodedFormat, 100); |
93 } | 76 } |
94 | 77 |
95 static void decodeFileAndWrite(const char srcPath[]) { | 78 static void decodeFileAndWrite(const char srcPath[]) { |
96 SkBitmap bitmap; | 79 SkBitmap bitmap; |
97 SkFILEStream stream(srcPath); | 80 SkFILEStream stream(srcPath); |
98 if (!stream.isValid()) { | 81 if (!stream.isValid()) { |
99 return; | 82 return; |
100 } | 83 } |
101 | 84 |
102 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); | 85 SkImageDecoder* codec = SkImageDecoder::Factory(&stream); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 149 } |
167 | 150 |
168 return 0; | 151 return 0; |
169 } | 152 } |
170 | 153 |
171 #if !defined SK_BUILD_FOR_IOS | 154 #if !defined SK_BUILD_FOR_IOS |
172 int main(int argc, char * const argv[]) { | 155 int main(int argc, char * const argv[]) { |
173 return tool_main(argc, (char**) argv); | 156 return tool_main(argc, (char**) argv); |
174 } | 157 } |
175 #endif | 158 #endif |
OLD | NEW |