Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: tools/render_pdfs_main.cpp

Issue 25054002: Use SkPicture::ExtractBitmap callback in pdf too. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix return on another funtion with signature change Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/PdfRenderer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkForceLinking.h" 10 #include "SkForceLinking.h"
11 #include "SkGraphics.h" 11 #include "SkGraphics.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkPicture.h" 14 #include "SkPicture.h"
15 #include "SkPixelRef.h"
15 #include "SkStream.h" 16 #include "SkStream.h"
16 #include "SkTArray.h" 17 #include "SkTArray.h"
17 #include "PdfRenderer.h" 18 #include "PdfRenderer.h"
18 #include "picture_utils.h" 19 #include "picture_utils.h"
19 20
20 __SK_FORCE_IMAGE_DECODER_LINKING; 21 __SK_FORCE_IMAGE_DECODER_LINKING;
21 22
22 #ifdef SK_USE_CDB 23 #ifdef SK_USE_CDB
23 #include "win_dbghelp.h" 24 #include "win_dbghelp.h"
24 #endif 25 #endif
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!path->endsWith(".")) { 75 if (!path->endsWith(".")) {
75 return false; 76 return false;
76 } 77 }
77 path->append(new_extension); 78 path->append(new_extension);
78 return true; 79 return true;
79 } 80 }
80 return false; 81 return false;
81 } 82 }
82 83
83 int gJpegQuality = 100; 84 int gJpegQuality = 100;
84 static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, cons t SkIRect& rect) { 85 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap ) {
85 if (gJpegQuality == -1) return false; 86 if (gJpegQuality == -1) {
87 return NULL;
88 }
86 89
87 SkIRect bitmapBounds; 90 SkBitmap bm = bitmap;
88 SkBitmap subset;
89 const SkBitmap* bitmapToUse = &bitmap;
90 bitmap.getBounds(&bitmapBounds);
91 if (rect != bitmapBounds) {
92 SkAssertResult(bitmap.extractSubset(&subset, rect));
93 bitmapToUse = ⊂
94 }
95
96 #if defined(SK_BUILD_FOR_MAC) 91 #if defined(SK_BUILD_FOR_MAC)
97 // Workaround bug #1043 where bitmaps with referenced pixels cause 92 // Workaround bug #1043 where bitmaps with referenced pixels cause
98 // CGImageDestinationFinalize to crash 93 // CGImageDestinationFinalize to crash
99 SkBitmap copy; 94 SkBitmap copy;
100 bitmapToUse->deepCopyTo(&copy, bitmapToUse->config()); 95 bitmap.deepCopyTo(&copy, bitmap.config());
101 bitmapToUse = © 96 bm = copy;
102 #endif 97 #endif
103 98
104 return SkImageEncoder::EncodeStream(stream, 99 SkPixelRef* pr = bm.pixelRef();
105 *bitmapToUse, 100 if (pr != NULL) {
106 SkImageEncoder::kJPEG_Type, 101 SkData* data = pr->refEncodedData();
107 gJpegQuality); 102 if (data != NULL) {
103 *pixelRefOffset = bm.pixelRefOffset();
104 return data;
105 }
106 }
107
108 *pixelRefOffset = 0;
109 return SkImageEncoder::EncodeData(bm,
110 SkImageEncoder::kJPEG_Type,
111 gJpegQuality);
108 } 112 }
109 113
110 /** Builds the output filename. path = dir/name, and it replaces expected 114 /** Builds the output filename. path = dir/name, and it replaces expected
111 * .skp extension with .pdf extention. 115 * .skp extension with .pdf extention.
112 * @param path Output filename. 116 * @param path Output filename.
113 * @param name The name of the file. 117 * @param name The name of the file.
114 * @returns false if the file did not has the expected extension. 118 * @returns false if the file did not has the expected extension.
115 * if false is returned, contents of path are undefined. 119 * if false is returned, contents of path are undefined.
116 */ 120 */
117 static bool make_output_filepath(SkString* path, const SkString& dir, 121 static bool make_output_filepath(SkString* path, const SkString& dir,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 exit(-1); 261 exit(-1);
258 } 262 }
259 } 263 }
260 264
261 int tool_main_core(int argc, char** argv); 265 int tool_main_core(int argc, char** argv);
262 int tool_main_core(int argc, char** argv) { 266 int tool_main_core(int argc, char** argv) {
263 SkAutoGraphics ag; 267 SkAutoGraphics ag;
264 SkTArray<SkString> inputs; 268 SkTArray<SkString> inputs;
265 269
266 SkAutoTUnref<sk_tools::PdfRenderer> 270 SkAutoTUnref<sk_tools::PdfRenderer>
267 renderer(SkNEW_ARGS(sk_tools::SimplePdfRenderer, (encode_to_dct_stream)) ); 271 renderer(SkNEW_ARGS(sk_tools::SimplePdfRenderer, (encode_to_dct_data)));
268 SkASSERT(renderer.get()); 272 SkASSERT(renderer.get());
269 273
270 SkString outputDir; 274 SkString outputDir;
271 parse_commandline(argc, argv, &inputs, &outputDir); 275 parse_commandline(argc, argv, &inputs, &outputDir);
272 276
273 int failures = 0; 277 int failures = 0;
274 for (int i = 0; i < inputs.count(); i ++) { 278 for (int i = 0; i < inputs.count(); i ++) {
275 failures += process_input(inputs[i], outputDir, *renderer); 279 failures += process_input(inputs[i], outputDir, *renderer);
276 } 280 }
277 281
(...skipping 20 matching lines...) Expand all
298 } 302 }
299 #endif 303 #endif
300 return 0; 304 return 0;
301 } 305 }
302 306
303 #if !defined SK_BUILD_FOR_IOS 307 #if !defined SK_BUILD_FOR_IOS
304 int main(int argc, char * const argv[]) { 308 int main(int argc, char * const argv[]) {
305 return tool_main(argc, (char**) argv); 309 return tool_main(argc, (char**) argv);
306 } 310 }
307 #endif 311 #endif
OLDNEW
« no previous file with comments | « tools/PdfRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698