OLD | NEW |
1 #include "SkCanvas.h" | 1 #include "SkCanvas.h" |
2 #include "SkCommandLineFlags.h" | 2 #include "SkCommandLineFlags.h" |
3 #include "SkDevice.h" | 3 #include "SkDevice.h" |
4 #include "SkGraphics.h" | 4 #include "SkGraphics.h" |
5 #include "SkImageDecoder.h" | 5 #include "SkImageDecoder.h" |
6 #include "SkImageEncoder.h" | 6 #include "SkImageEncoder.h" |
7 #include "SkOSFile.h" | 7 #include "SkOSFile.h" |
8 #include "SkPicture.h" | 8 #include "SkPicture.h" |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 #include "SkTypeface.h" | 10 #include "SkTypeface.h" |
11 #include "SkTArray.h" | 11 #include "SkTArray.h" |
12 #include "picture_utils.h" | 12 #include "picture_utils.h" |
13 | 13 |
14 #include "SkPdfRenderer.h" | 14 #include "SkPdfRenderer.h" |
15 | 15 |
16 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces
s."); | 16 DEFINE_string2(readPath, r, "", "pdf files or directories of pdf files to proces
s."); |
17 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages."); | 17 DEFINE_string2(writePath, w, "", "Directory to write the rendered pages."); |
18 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one
page."); | 18 DEFINE_bool2(noExtensionForOnePagePdf, n, false, "No page extension if only one
page."); |
19 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); | 19 DEFINE_bool2(showMemoryUsage, m, false, "Show Memory usage."); |
20 DEFINE_string2(pages, p, "all", "What pages to render and how:\n" | 20 DEFINE_string2(pages, p, "all", "What pages to render and how:\n" |
21 "\tall - all pages\n" | 21 "\tall - all pages\n" |
22 "\treverse - all pages, in reverse order\n" | 22 "\treverse - all pages, in reverse order\n" |
23 "\tfirst - first page\n" | 23 "\tfirst - first page\n" |
24 "\tlast - last page\n" | 24 "\tlast - last page\n" |
25 "\tnumber - a specific page number\n" | 25 "\tnumber - a specific page number\n" |
26 ); | 26 ); |
27 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); | 27 DEFINE_double(DPI, 72, "DPI to be used for rendering (scale)."); |
| 28 DEFINE_int32(benchLoad, 0, "Load the pdf file minimally N times, without any ren
dering and \n" |
| 29 "\tminimal parsing to ensure correctness. Default 0 (disabled)."); |
| 30 DEFINE_int32(benchRender, 0, "Render the pdf content N times. Default 0 (disable
d)"); |
| 31 |
| 32 |
28 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not
to render at all | 33 // TODO(edisonn): add config for device target(gpu, raster, pdf), + ability not
to render at all |
29 // TODO(edisonn): add ability to do the op N times, bench (either load N times,
render n times or load + render n times) | |
30 | 34 |
31 /** | 35 /** |
32 * Given list of directories and files to use as input, expects to find .pdf | 36 * Given list of directories and files to use as input, expects to find .pdf |
33 * files and it will convert them to .png files writing them in the same directo
ry | 37 * files and it will convert them to .png files writing them in the same directo
ry |
34 * one file for each page. | 38 * one file for each page. |
35 * | 39 * |
36 * Returns zero exit code if all .pdf files were converted successfully, | 40 * Returns zero exit code if all .pdf files were converted successfully, |
37 * otherwise returns error code 1. | 41 * otherwise returns error code 1. |
38 */ | 42 */ |
39 | 43 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 SkFILEStream inputStream; | 157 SkFILEStream inputStream; |
154 inputStream.setPath(inputPath.c_str()); | 158 inputStream.setPath(inputPath.c_str()); |
155 if (!inputStream.isValid()) { | 159 if (!inputStream.isValid()) { |
156 SkDebugf("Could not open file %s\n", inputPath.c_str()); | 160 SkDebugf("Could not open file %s\n", inputPath.c_str()); |
157 return false; | 161 return false; |
158 } | 162 } |
159 | 163 |
160 bool success = false; | 164 bool success = false; |
161 | 165 |
162 success = renderer.load(inputPath); | 166 success = renderer.load(inputPath); |
| 167 if (FLAGS_showMemoryUsage) { |
| 168 SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.bytesUs
ed()); |
| 169 } |
| 170 |
| 171 // TODO(edisonn): bench timers |
| 172 if (FLAGS_benchLoad > 0) { |
| 173 for (int i = 0 ; i < FLAGS_benchLoad; i++) { |
| 174 success = renderer.load(inputPath); |
| 175 if (FLAGS_showMemoryUsage) { |
| 176 SkDebugf("Memory usage after load %i number : %u\n", i, (unsigne
d int)renderer.bytesUsed()); |
| 177 } |
| 178 } |
| 179 } |
163 | 180 |
164 if (success) { | 181 if (success) { |
165 if (FLAGS_showMemoryUsage) { | |
166 SkDebugf("Memory usage after load: %u\n", (unsigned int)renderer.byt
esUsed()); | |
167 } | |
168 if (!renderer.pages()) | 182 if (!renderer.pages()) |
169 { | 183 { |
170 SkDebugf("ERROR: Empty PDF Document %s\n", inputPath.c_str()); | 184 SkDebugf("ERROR: Empty PDF Document %s\n", inputPath.c_str()); |
171 return false; | 185 return false; |
172 } else { | 186 } else { |
173 if (strcmp(FLAGS_pages[0], "all") == 0) { | 187 for (int i = 0; i < FLAGS_benchRender + 1; i++) { |
174 for (int pn = 0; pn < renderer.pages(); ++pn) { | 188 // TODO(edisonn) if (i == 1) start timer |
175 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; | 189 if (strcmp(FLAGS_pages[0], "all") == 0) { |
| 190 for (int pn = 0; pn < renderer.pages(); ++pn) { |
| 191 success = render_page(outputDir, inputFilename, renderer
, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
| 192 } |
| 193 } else if (strcmp(FLAGS_pages[0], "reverse") == 0) { |
| 194 for (int pn = renderer.pages() - 1; pn >= 0; --pn) { |
| 195 success = render_page(outputDir, inputFilename, renderer
, FLAGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; |
| 196 } |
| 197 } else if (strcmp(FLAGS_pages[0], "first") == 0) { |
| 198 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success; |
| 199 } else if (strcmp(FLAGS_pages[0], "last") == 0) { |
| 200 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() -
1) && success; |
| 201 } else { |
| 202 int pn = atoi(FLAGS_pages[0]); |
| 203 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() -
1) && pn; |
176 } | 204 } |
177 } else if (strcmp(FLAGS_pages[0], "reverse") == 0) { | |
178 for (int pn = renderer.pages() - 1; pn >= 0; --pn) { | |
179 success = render_page(outputDir, inputFilename, renderer, FL
AGS_noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : pn) && success; | |
180 } | |
181 } else if (strcmp(FLAGS_pages[0], "first") == 0) { | |
182 success = render_page(outputDir, inputFilename, renderer, FLAGS_
noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : 0) && success; | |
183 } else if (strcmp(FLAGS_pages[0], "last") == 0) { | |
184 success = render_page(outputDir, inputFilename, renderer, FLAGS_
noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) &
& success; | |
185 } else { | |
186 int pn = atoi(FLAGS_pages[0]); | |
187 success = render_page(outputDir, inputFilename, renderer, FLAGS_
noExtensionForOnePagePdf && renderer.pages() == 1 ? -1 : renderer.pages() - 1) &
& pn; | |
188 } | 205 } |
189 } | 206 } |
190 } | 207 } |
191 | 208 |
192 return success; | 209 return success; |
193 } | 210 } |
194 | 211 |
195 /** For each file in the directory or for the file passed in input, call | 212 /** For each file in the directory or for the file passed in input, call |
196 * parse_pdf. | 213 * parse_pdf. |
197 * @param input A directory or an pdf file. | 214 * @param input A directory or an pdf file. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 } | 270 } |
254 | 271 |
255 return 0; | 272 return 0; |
256 } | 273 } |
257 | 274 |
258 #if !defined SK_BUILD_FOR_IOS | 275 #if !defined SK_BUILD_FOR_IOS |
259 int main(int argc, char * const argv[]) { | 276 int main(int argc, char * const argv[]) { |
260 return tool_main(argc, (char**) argv); | 277 return tool_main(argc, (char**) argv); |
261 } | 278 } |
262 #endif | 279 #endif |
OLD | NEW |