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

Side by Side Diff: gm/gmmain.cpp

Issue 54913004: Implement DPI for perspective bitmaps in PDF - we save the bitmap at the resolution requested. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: take 2, matrix handling Created 7 years, 1 month 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 | « no previous file | include/pdf/SkPDFDevice.h » ('j') | src/pdf/SkPDFDevice.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 /* 8 /*
9 * Code for the "gm" (Golden Master) rendering comparison tool. 9 * Code for the "gm" (Golden Master) rendering comparison tool.
10 * 10 *
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 }; 191 };
192 192
193 static PipeFlagComboData gPipeWritingFlagCombos[] = { 193 static PipeFlagComboData gPipeWritingFlagCombos[] = {
194 { "", 0 }, 194 { "", 0 },
195 { " cross-process", SkGPipeWriter::kCrossProcess_Flag }, 195 { " cross-process", SkGPipeWriter::kCrossProcess_Flag },
196 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag 196 { " cross-process, shared address", SkGPipeWriter::kCrossProcess_Flag
197 | SkGPipeWriter::kSharedAddressSpace_Flag } 197 | SkGPipeWriter::kSharedAddressSpace_Flag }
198 }; 198 };
199 199
200 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap ); 200 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap );
201 DECLARE_int32(pdfRasterDpi);
201 202
202 const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination() 203 const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
203 .plus(kMissingExpectations_ErrorType) 204 .plus(kMissingExpectations_ErrorType)
204 .plus(kIntentionallySkipped_ErrorType); 205 .plus(kIntentionallySkipped_ErrorType);
205 206
206 class GMMain { 207 class GMMain {
207 public: 208 public:
208 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false), 209 GMMain() : fUseFileHierarchy(false), fWriteChecksumBasedFilenames(false),
209 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes), 210 fIgnorableErrorTypes(kDefaultIgnorableErrorTypes),
210 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0) , 211 fMismatchPath(NULL), fMissingExpectationsPath(NULL), fTestsRun(0) ,
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 canvas.drawPicture(*pict); 630 canvas.drawPicture(*pict);
630 complete_bitmap(bitmap); 631 complete_bitmap(bitmap);
631 } 632 }
632 } 633 }
633 634
634 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { 635 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
635 #ifdef SK_SUPPORT_PDF 636 #ifdef SK_SUPPORT_PDF
636 SkMatrix initialTransform = gm->getInitialTransform(); 637 SkMatrix initialTransform = gm->getInitialTransform();
637 if (FLAGS_useDocumentInsteadOfDevice) { 638 if (FLAGS_useDocumentInsteadOfDevice) {
638 SkISize pageISize = gm->getISize(); 639 SkISize pageISize = gm->getISize();
639 SkAutoTUnref<SkDocument> pdfDoc(SkDocument::CreatePDF(&pdf, NULL, en code_to_dct_data)); 640 SkAutoTUnref<SkDocument> pdfDoc(
641 SkDocument::CreatePDF(&pdf, NULL,
642 encode_to_dct_data,
643 SkIntToScalar(FLAGS_pdfRasterDpi)));
640 644
641 if (!pdfDoc.get()) { 645 if (!pdfDoc.get()) {
642 return false; 646 return false;
643 } 647 }
644 648
645 SkCanvas* canvas = NULL; 649 SkCanvas* canvas = NULL;
646 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()), 650 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
647 SkIntToScalar(pageISize.height())); 651 SkIntToScalar(pageISize.height()));
648 canvas->concat(initialTransform); 652 canvas->concat(initialTransform);
649 653
(...skipping 10 matching lines...) Expand all
660 SkIntToScalar(pageSize.height()) ); 664 SkIntToScalar(pageSize.height()) );
661 initialTransform.mapRect(&content); 665 initialTransform.mapRect(&content);
662 content.intersect(0, 0, SkIntToScalar(pageSize.width()), 666 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
663 SkIntToScalar(pageSize.height())); 667 SkIntToScalar(pageSize.height()));
664 SkISize contentSize = 668 SkISize contentSize =
665 SkISize::Make(SkScalarRoundToInt(content.width()), 669 SkISize::Make(SkScalarRoundToInt(content.width()),
666 SkScalarRoundToInt(content.height())); 670 SkScalarRoundToInt(content.height()));
667 dev = new SkPDFDevice(pageSize, contentSize, initialTransform); 671 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
668 } 672 }
669 dev->setDCTEncoder(encode_to_dct_data); 673 dev->setDCTEncoder(encode_to_dct_data);
674 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
670 SkAutoUnref aur(dev); 675 SkAutoUnref aur(dev);
671 SkCanvas c(dev); 676 SkCanvas c(dev);
672 invokeGM(gm, &c, true, false); 677 invokeGM(gm, &c, true, false);
673 SkPDFDocument doc; 678 SkPDFDocument doc;
674 doc.appendPage(dev); 679 doc.appendPage(dev);
675 doc.emitPDF(&pdf); 680 doc.emitPDF(&pdf);
676 } 681 }
677 #endif // SK_SUPPORT_PDF 682 #endif // SK_SUPPORT_PDF
678 return true; // Do not report failure if pdf is not supported. 683 return true; // Do not report failure if pdf is not supported.
679 } 684 }
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 "which can be in range 0-100). N = -1 will disable JPEG compression . " 1470 "which can be in range 0-100). N = -1 will disable JPEG compression . "
1466 "Default is N = 100, maximum quality."); 1471 "Default is N = 100, maximum quality.");
1467 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix 1472 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1468 // Either the 9 numbers defining the matrix 1473 // Either the 9 numbers defining the matrix
1469 // or probably more readable would be to replace it with a set of a few predicat es 1474 // or probably more readable would be to replace it with a set of a few predicat es
1470 // Like --prerotate 100 200 10 --posttranslate 10, 10 1475 // Like --prerotate 100 200 10 --posttranslate 10, 10
1471 // Probably define spacial names like centerx, centery, top, bottom, left, right 1476 // Probably define spacial names like centerx, centery, top, bottom, left, right
1472 // then we can write something reabable like --rotate centerx centery 90 1477 // then we can write something reabable like --rotate centerx centery 90
1473 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); 1478 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
1474 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea d of SkFooDevice."); 1479 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea d of SkFooDevice.");
1475 1480 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported feature s "
vandebo (ex-Chrome) 2013/11/07 22:44:00 nit: wrap at 80col, so you're already wrapping clo
edisonn 2013/11/11 17:26:56 Done.
1481 "in PDF are rasterized. Must be be in range 0-10000. Default is 72. "
1482 "N = 0 will disable rasterizing features like text shadows or persp ective bitmaps.");
1476 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap ) { 1483 static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap ) {
1477 // Filter output of warnings that JPEG is not available for the image. 1484 // Filter output of warnings that JPEG is not available for the image.
1478 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; 1485 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1479 if (FLAGS_pdfJpegQuality == -1) return NULL; 1486 if (FLAGS_pdfJpegQuality == -1) return NULL;
1480 1487
1481 SkBitmap bm = bitmap; 1488 SkBitmap bm = bitmap;
1482 #if defined(SK_BUILD_FOR_MAC) 1489 #if defined(SK_BUILD_FOR_MAC)
1483 // Workaround bug #1043 where bitmaps with referenced pixels cause 1490 // Workaround bug #1043 where bitmaps with referenced pixels cause
1484 // CGImageDestinationFinalize to crash 1491 // CGImageDestinationFinalize to crash
1485 SkBitmap copy; 1492 SkBitmap copy;
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
2375 if (FLAGS_forceBWtext) { 2382 if (FLAGS_forceBWtext) {
2376 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); 2383 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2377 } 2384 }
2378 } 2385 }
2379 2386
2380 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 2387 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
2381 int main(int argc, char * const argv[]) { 2388 int main(int argc, char * const argv[]) {
2382 return tool_main(argc, (char**) argv); 2389 return tool_main(argc, (char**) argv);
2383 } 2390 }
2384 #endif 2391 #endif
OLDNEW
« no previous file with comments | « no previous file | include/pdf/SkPDFDevice.h » ('j') | src/pdf/SkPDFDevice.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698