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

Unified Diff: src/pdf/SkPDFImage.cpp

Issue 25054002: Use SkPicture::ExtractBitmap callback in pdf too. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pdf/SkPDFImage.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pdf/SkPDFImage.cpp
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index fbd37ebd8eba82a4e76ae77c1db7f4e3a52dee6a..dde4e8708cf72d9bbc842be30f09c0b56a9f7c23 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -339,7 +339,7 @@ static SkPDFArray* make_indexed_color_space(SkColorTable* table) {
// static
SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
const SkIRect& srcRect,
- EncodeToDCTStream encoder) {
+ SkPicture::EncodeBitmap encoder) {
if (bitmap.getConfig() == SkBitmap::kNo_Config) {
return NULL;
}
@@ -390,7 +390,7 @@ SkPDFImage::SkPDFImage(SkStream* stream,
const SkBitmap& bitmap,
bool isAlpha,
const SkIRect& srcRect,
- EncodeToDCTStream encoder)
+ SkPicture::EncodeBitmap encoder)
: fIsAlpha(isAlpha),
fSrcRect(srcRect),
fEncoder(encoder) {
@@ -482,19 +482,27 @@ bool SkPDFImage::populate(SkPDFCatalog* catalog) {
// Initializing image data for the first time.
SkDynamicMemoryWStream dctCompressedWStream;
if (!skip_compression(catalog) && fEncoder &&
- get_uncompressed_size(fBitmap, fSrcRect) > 1 &&
- fEncoder(&dctCompressedWStream, fBitmap, fSrcRect) &&
- dctCompressedWStream.getOffset() <
- get_uncompressed_size(fBitmap, fSrcRect)) {
- SkAutoTUnref<SkData> data(dctCompressedWStream.copyToData());
- SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data)));
- setData(stream.get());
-
- insertName("Filter", "DCTDecode");
- insertInt("ColorTransform", kNoColorTransform);
- insertInt("Length", getData()->getLength());
- setState(kCompressed_State);
- return true;
+ get_uncompressed_size(fBitmap, fSrcRect) > 1) {
+ SkBitmap subset;
+ // Extract subset
vandebo (ex-Chrome) 2013/09/27 16:06:13 It's unfortunate that we have to do this without g
+ if (!fBitmap.extractSubset(&subset, fSrcRect)) {
vandebo (ex-Chrome) 2013/09/27 16:06:13 extractSubset doesn't have any special cases for f
reed1 2013/09/27 16:15:29 What is the concern with always calling extractSub
vandebo (ex-Chrome) 2013/09/27 16:16:37 Just that it's unnecessary computational overhead
+ // If Extract subset fails, make a deep copy.
+ if (!fBitmap.copyTo(&subset, fBitmap.config())) {
vandebo (ex-Chrome) 2013/09/27 16:06:13 Don't you still need to subset the image after thi
edisonn 2013/09/27 17:57:20 removed. extractSubset will not fork for A1, if th
+ return false;
+ }
+ }
+ size_t pixelRefOffset = 0;
+ SkAutoTUnref<SkData> data(fEncoder(&pixelRefOffset, subset));
+ if (data.get() && data->size() < get_uncompressed_size(fBitmap, fSrcRect)) {
vandebo (ex-Chrome) 2013/09/27 16:06:13 This file is basically 80-column clean, so please
edisonn 2013/09/27 17:57:20 Done.
+ SkAutoTUnref<SkStream> stream(SkNEW_ARGS(SkMemoryStream, (data)));
+ setData(stream.get());
+
+ insertName("Filter", "DCTDecode");
+ insertInt("ColorTransform", kNoColorTransform);
+ insertInt("Length", getData()->getLength());
+ setState(kCompressed_State);
+ return true;
+ }
}
// Fallback method
if (!fStreamValid) {
« no previous file with comments | « src/pdf/SkPDFImage.h ('k') | tests/PDFPrimitivesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698