| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
| 10 #include "SkDocument.h" | 10 #include "SkDocument.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DEFINE_string2(match, m, "", | 49 DEFINE_string2(match, m, "", |
| 50 "[~][^]substring[$] [...] of filenames to run.\n" | 50 "[~][^]substring[$] [...] of filenames to run.\n" |
| 51 "Multiple matches may be separated by spaces.\n" | 51 "Multiple matches may be separated by spaces.\n" |
| 52 "~ causes a matching file to always be skipped\n" | 52 "~ causes a matching file to always be skipped\n" |
| 53 "^ requires the start of the file to match\n" | 53 "^ requires the start of the file to match\n" |
| 54 "$ requires the end of the file to match\n" | 54 "$ requires the end of the file to match\n" |
| 55 "^ and $ requires an exact match\n" | 55 "^ and $ requires an exact match\n" |
| 56 "If a file does not match any list entry,\n" | 56 "If a file does not match any list entry,\n" |
| 57 "it is skipped unless some list entry starts with ~"); | 57 "it is skipped unless some list entry starts with ~"); |
| 58 | 58 |
| 59 DEFINE_int32(jpegQuality, 100, | |
| 60 "Encodes images in JPEG at quality level N, which can be in " | |
| 61 "range 0-100). N = -1 will disable JPEG compression. " | |
| 62 "Default is N = 100, maximum quality."); | |
| 63 | |
| 64 /** Replaces the extension of a file. | 59 /** Replaces the extension of a file. |
| 65 * @param path File name whose extension will be changed. | 60 * @param path File name whose extension will be changed. |
| 66 * @param old_extension The old extension. | 61 * @param old_extension The old extension. |
| 67 * @param new_extension The new extension. | 62 * @param new_extension The new extension. |
| 68 * @returns false if the file did not has the expected extension. | 63 * @returns false if the file did not has the expected extension. |
| 69 * if false is returned, contents of path are undefined. | 64 * if false is returned, contents of path are undefined. |
| 70 */ | 65 */ |
| 71 static bool replace_filename_extension(SkString* path, | 66 static bool replace_filename_extension(SkString* path, |
| 72 const char old_extension[], | 67 const char old_extension[], |
| 73 const char new_extension[]) { | 68 const char new_extension[]) { |
| 74 if (path->endsWith(old_extension)) { | 69 if (path->endsWith(old_extension)) { |
| 75 path->remove(path->size() - strlen(old_extension), | 70 path->remove(path->size() - strlen(old_extension), |
| 76 strlen(old_extension)); | 71 strlen(old_extension)); |
| 77 if (!path->endsWith(".")) { | 72 if (!path->endsWith(".")) { |
| 78 return false; | 73 return false; |
| 79 } | 74 } |
| 80 path->append(new_extension); | 75 path->append(new_extension); |
| 81 return true; | 76 return true; |
| 82 } | 77 } |
| 83 return false; | 78 return false; |
| 84 } | 79 } |
| 85 | 80 |
| 86 // the size_t* parameter is deprecated, so we ignore it | |
| 87 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { | |
| 88 if (FLAGS_jpegQuality == -1) { | |
| 89 return NULL; | |
| 90 } | |
| 91 | |
| 92 SkBitmap bm = bitmap; | |
| 93 #if defined(SK_BUILD_FOR_MAC) | |
| 94 // Workaround bug #1043 where bitmaps with referenced pixels cause | |
| 95 // CGImageDestinationFinalize to crash | |
| 96 SkBitmap copy; | |
| 97 bitmap.deepCopyTo(©); | |
| 98 bm = copy; | |
| 99 #endif | |
| 100 | |
| 101 return SkImageEncoder::EncodeData( | |
| 102 bm, SkImageEncoder::kJPEG_Type, FLAGS_jpegQuality); | |
| 103 } | |
| 104 | |
| 105 /** Builds the output filename. path = dir/name, and it replaces expected | 81 /** Builds the output filename. path = dir/name, and it replaces expected |
| 106 * .skp extension with .pdf extention. | 82 * .skp extension with .pdf extention. |
| 107 * @param path Output filename. | 83 * @param path Output filename. |
| 108 * @param name The name of the file. | 84 * @param name The name of the file. |
| 109 * @returns false if the file did not has the expected extension. | 85 * @returns false if the file did not has the expected extension. |
| 110 * if false is returned, contents of path are undefined. | 86 * if false is returned, contents of path are undefined. |
| 111 */ | 87 */ |
| 112 static bool make_output_filepath(SkString* path, const SkString& dir, | 88 static bool make_output_filepath(SkString* path, const SkString& dir, |
| 113 const SkString& name) { | 89 const SkString& name) { |
| 114 *path = SkOSPath::Join(dir.c_str(), name.c_str()); | 90 *path = SkOSPath::Join(dir.c_str(), name.c_str()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 131 } |
| 156 | 132 |
| 157 return stream.detach(); | 133 return stream.detach(); |
| 158 } | 134 } |
| 159 | 135 |
| 160 /** | 136 /** |
| 161 * Given a SkPicture, write a one-page PDF document to the given | 137 * Given a SkPicture, write a one-page PDF document to the given |
| 162 * output, using the provided encoder. | 138 * output, using the provided encoder. |
| 163 */ | 139 */ |
| 164 static bool pdf_to_stream(SkPicture* picture, | 140 static bool pdf_to_stream(SkPicture* picture, |
| 165 SkWStream* output, | 141 SkWStream* output) { |
| 166 SkPicture::EncodeBitmap encoder) { | |
| 167 SkAutoTUnref<SkDocument> pdfDocument( | 142 SkAutoTUnref<SkDocument> pdfDocument( |
| 168 SkDocument::CreatePDF(output, NULL, encoder)); | 143 SkDocument::CreatePDF(output)); |
| 169 SkCanvas* canvas = pdfDocument->beginPage(picture->cullRect().width(), | 144 SkCanvas* canvas = pdfDocument->beginPage(picture->cullRect().width(), |
| 170 picture->cullRect().height()); | 145 picture->cullRect().height()); |
| 171 canvas->drawPicture(picture); | 146 canvas->drawPicture(picture); |
| 172 canvas->flush(); | 147 canvas->flush(); |
| 173 return pdfDocument->close(); | 148 return pdfDocument->close(); |
| 174 } | 149 } |
| 175 | 150 |
| 176 static bool operator<(const SkString& a, const SkString& b) { | 151 static bool operator<(const SkString& a, const SkString& b) { |
| 177 return strcmp(a.c_str(), b.c_str()) < 0; | 152 return strcmp(a.c_str(), b.c_str()) < 0; |
| 178 } | 153 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 SkDebugf("[%6g %6g %6g %6g] %-*s", | 232 SkDebugf("[%6g %6g %6g %6g] %-*s", |
| 258 picture->cullRect().fLeft, picture->cullRect().fTop, | 233 picture->cullRect().fLeft, picture->cullRect().fTop, |
| 259 picture->cullRect().fRight, picture->cullRect().fBottom, | 234 picture->cullRect().fRight, picture->cullRect().fBottom, |
| 260 maximumPathLength, basename.c_str()); | 235 maximumPathLength, basename.c_str()); |
| 261 | 236 |
| 262 SkAutoTDelete<SkWStream> stream(open_stream(outputDir, files[i])); | 237 SkAutoTDelete<SkWStream> stream(open_stream(outputDir, files[i])); |
| 263 if (!stream.get()) { | 238 if (!stream.get()) { |
| 264 ++failures; | 239 ++failures; |
| 265 continue; | 240 continue; |
| 266 } | 241 } |
| 267 if (!pdf_to_stream(picture, stream.get(), encode_to_dct_data)) { | 242 if (!pdf_to_stream(picture, stream.get())) { |
| 268 SkDebugf("Error in PDF Serialization."); | 243 SkDebugf("Error in PDF Serialization."); |
| 269 ++failures; | 244 ++failures; |
| 270 } | 245 } |
| 271 | 246 |
| 272 int max_rss_mb = sk_tools::getMaxResidentSetSizeMB(); | 247 int max_rss_mb = sk_tools::getMaxResidentSetSizeMB(); |
| 273 if (max_rss_mb >= 0) { | 248 if (max_rss_mb >= 0) { |
| 274 SkDebugf(" %4dM peak rss", max_rss_mb); | 249 SkDebugf(" %4dM peak rss", max_rss_mb); |
| 275 } | 250 } |
| 276 | 251 |
| 277 SkDebugf("\n"); | 252 SkDebugf("\n"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 298 return -1; | 273 return -1; |
| 299 } | 274 } |
| 300 #endif | 275 #endif |
| 301 return 0; | 276 return 0; |
| 302 } | 277 } |
| 303 #if !defined SK_BUILD_FOR_IOS | 278 #if !defined SK_BUILD_FOR_IOS |
| 304 int main(int argc, char * const argv[]) { | 279 int main(int argc, char * const argv[]) { |
| 305 return tool_main(argc, (char**) argv); | 280 return tool_main(argc, (char**) argv); |
| 306 } | 281 } |
| 307 #endif | 282 #endif |
| OLD | NEW |