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

Side by Side Diff: src/pdf/SkPDFImage.cpp

Issue 936403002: PDF: why do we have flags no one uses (or can use)? (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 10 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
« no previous file with comments | « src/pdf/SkPDFDocument.cpp ('k') | src/pdf/SkPDFPage.cpp » ('j') | 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 2010 The Android Open Source Project 2 * Copyright 2010 The Android Open Source Project
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 "SkPDFImage.h" 8 #include "SkPDFImage.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
11 #include "SkColor.h" 11 #include "SkColor.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #include "SkData.h" 13 #include "SkData.h"
14 #include "SkFlate.h" 14 #include "SkFlate.h"
15 #include "SkPDFBitmap.h" 15 #include "SkPDFBitmap.h"
16 #include "SkPDFCatalog.h" 16 #include "SkPDFCatalog.h"
17 #include "SkPixelRef.h" 17 #include "SkPixelRef.h"
18 #include "SkRect.h" 18 #include "SkRect.h"
19 #include "SkStream.h" 19 #include "SkStream.h"
20 #include "SkString.h" 20 #include "SkString.h"
21 #include "SkUnPreMultiply.h" 21 #include "SkUnPreMultiply.h"
22 22
23 static const int kNoColorTransform = 0; 23 static const int kNoColorTransform = 0;
24 24
25 static bool skip_compression(SkPDFCatalog* catalog) {
26 return SkToBool(catalog->getDocumentFlags() &
27 SkPDFDocument::kFavorSpeedOverSize_Flags);
28 }
29
30 static size_t get_uncompressed_size(const SkBitmap& bitmap, 25 static size_t get_uncompressed_size(const SkBitmap& bitmap,
31 const SkIRect& srcRect) { 26 const SkIRect& srcRect) {
32 switch (bitmap.colorType()) { 27 switch (bitmap.colorType()) {
33 case kIndex_8_SkColorType: 28 case kIndex_8_SkColorType:
34 return srcRect.width() * srcRect.height(); 29 return srcRect.width() * srcRect.height();
35 case kARGB_4444_SkColorType: 30 case kARGB_4444_SkColorType:
36 return ((srcRect.width() * 3 + 1) / 2) * srcRect.height(); 31 return ((srcRect.width() * 3 + 1) / 2) * srcRect.height();
37 case kRGB_565_SkColorType: 32 case kRGB_565_SkColorType:
38 return srcRect.width() * 3 * srcRect.height(); 33 return srcRect.width() * 3 * srcRect.height();
39 case kRGBA_8888_SkColorType: 34 case kRGBA_8888_SkColorType:
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 fEncoder(pdfImage.fEncoder), 591 fEncoder(pdfImage.fEncoder),
597 fStreamValid(pdfImage.fStreamValid) { 592 fStreamValid(pdfImage.fStreamValid) {
598 // Nothing to do here - the image params are already copied in SkPDFStream's 593 // Nothing to do here - the image params are already copied in SkPDFStream's
599 // constructor, and the bitmap will be regenerated and encoded in 594 // constructor, and the bitmap will be regenerated and encoded in
600 // populate. 595 // populate.
601 } 596 }
602 597
603 bool SkPDFImage::populate(SkPDFCatalog* catalog) { 598 bool SkPDFImage::populate(SkPDFCatalog* catalog) {
604 if (getState() == kUnused_State) { 599 if (getState() == kUnused_State) {
605 // Initializing image data for the first time. 600 // Initializing image data for the first time.
606 if (!skip_compression(catalog) && fEncoder && 601 if (fEncoder && get_uncompressed_size(fBitmap, fSrcRect) > 1) {
607 get_uncompressed_size(fBitmap, fSrcRect) > 1) {
608 SkBitmap subset; 602 SkBitmap subset;
609 // Extract subset 603 // Extract subset
610 if (!fBitmap.extractSubset(&subset, fSrcRect)) { 604 if (!fBitmap.extractSubset(&subset, fSrcRect)) {
611 return false; 605 return false;
612 } 606 }
613 size_t pixelRefOffset = 0; 607 size_t pixelRefOffset = 0;
614 SkAutoTUnref<SkData> data(fEncoder(&pixelRefOffset, subset)); 608 SkAutoTUnref<SkData> data(fEncoder(&pixelRefOffset, subset));
615 if (data.get() && data->size() < get_uncompressed_size(fBitmap, 609 if (data.get() && data->size() < get_uncompressed_size(fBitmap,
616 fSrcRect)) { 610 fSrcRect)) {
617 this->setData(data.get()); 611 this->setData(data.get());
618 612
619 insertName("Filter", "DCTDecode"); 613 insertName("Filter", "DCTDecode");
620 insertInt("ColorTransform", kNoColorTransform); 614 insertInt("ColorTransform", kNoColorTransform);
621 insertInt("Length", this->dataSize()); 615 insertInt("Length", this->dataSize());
622 setState(kCompressed_State); 616 setState(kCompressed_State);
623 return true; 617 return true;
624 } 618 }
625 } 619 }
626 // Fallback method 620 // Fallback method
627 if (!fStreamValid) { 621 if (!fStreamValid) {
628 SkAutoTDelete<SkStream> stream( 622 SkAutoTDelete<SkStream> stream(
629 extract_image_data(fBitmap, fSrcRect, fIsAlpha, NULL)); 623 extract_image_data(fBitmap, fSrcRect, fIsAlpha, NULL));
630 this->setData(stream); 624 this->setData(stream);
631 fStreamValid = true; 625 fStreamValid = true;
632 } 626 }
633 return INHERITED::populate(catalog); 627 return INHERITED::populate(catalog);
634 } 628 }
635 #ifndef SK_NO_FLATE 629 #ifndef SK_NO_FLATE
636 else if (getState() == kNoCompression_State && !skip_compression(catalog)) { 630 else if (getState() == kNoCompression_State) {
637 #else // SK_NO_FLATE 631 #else // SK_NO_FLATE
638 else if (getState() == kNoCompression_State && 632 else if (getState() == kNoCompression_State && fEncoder) {
639 !skip_compression(catalog) &&
640 fEncoder) {
641 #endif // SK_NO_FLATE 633 #endif // SK_NO_FLATE
642 // Compression has not been requested when the stream was first created, 634 // Compression has not been requested when the stream was first created,
643 // but the new catalog wants it compressed. 635 // but the new catalog wants it compressed.
644 if (!getSubstitute()) { 636 if (!getSubstitute()) {
645 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); 637 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this));
646 setSubstitute(substitute); 638 setSubstitute(substitute);
647 catalog->setSubstitute(this, substitute); 639 catalog->setSubstitute(this, substitute);
648 } 640 }
649 return false; 641 return false;
650 } 642 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { 728 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) {
737 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); 729 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap));
738 if (is_jfif_jpeg(encodedData)) { 730 if (is_jfif_jpeg(encodedData)) {
739 return SkNEW_ARGS(PDFJPEGImage, 731 return SkNEW_ARGS(PDFJPEGImage,
740 (encodedData, bitmap.width(), bitmap.height())); 732 (encodedData, bitmap.width(), bitmap.height()));
741 } 733 }
742 } 734 }
743 #endif 735 #endif
744 return SkPDFImage::CreateImage(bitmap, subset, encoder); 736 return SkPDFImage::CreateImage(bitmap, subset, encoder);
745 } 737 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDocument.cpp ('k') | src/pdf/SkPDFPage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698