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

Unified Diff: gm/gmmain.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, 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 | « no previous file | include/pdf/SkPDFDevice.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gmmain.cpp
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index e84d61ada34731dcab06b7ff9adf6442eb5a2b02..defd691b52f83259468e80281e25ad625a813c8a 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -193,7 +193,7 @@ static PipeFlagComboData gPipeWritingFlagCombos[] = {
| SkGPipeWriter::kSharedAddressSpace_Flag }
};
-static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, const SkIRect& rect);
+static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap);
const static ErrorCombination kDefaultIgnorableErrorTypes = ErrorCombination()
.plus(kMissingExpectations_ErrorType)
@@ -633,7 +633,7 @@ public:
SkScalarRoundToInt(content.height()));
dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
}
- dev->setDCTEncoder(encode_to_dct_stream);
+ dev->setDCTEncoder(encode_to_dct_data);
SkAutoUnref aur(dev);
SkCanvas c(dev);
@@ -1422,7 +1422,6 @@ DEFINE_string2(writePicturePath, p, "", "Write .skp files into this directory.")
DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
"which can be in range 0-100). N = -1 will disable JPEG compression. "
"Default is N = 100, maximum quality.");
-
// TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
// Either the 9 numbers defining the matrix
// or probably more readable would be to replace it with a set of a few predicates
@@ -1431,32 +1430,33 @@ DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
// then we can write something reabable like --rotate centerx centery 90
DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
-static bool encode_to_dct_stream(SkWStream* stream, const SkBitmap& bitmap, const SkIRect& rect) {
+static SkData* encode_to_dct_data(size_t* pixelRefOffset, const SkBitmap& bitmap) {
// Filter output of warnings that JPEG is not available for the image.
- if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return false;
- if (FLAGS_pdfJpegQuality == -1) return false;
-
- SkIRect bitmapBounds;
- SkBitmap subset;
- const SkBitmap* bitmapToUse = &bitmap;
- bitmap.getBounds(&bitmapBounds);
- if (rect != bitmapBounds) {
- SkAssertResult(bitmap.extractSubset(&subset, rect));
- bitmapToUse = ⊂
- }
+ if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
+ if (FLAGS_pdfJpegQuality == -1) return NULL;
+ SkBitmap bm = bitmap;
#if defined(SK_BUILD_FOR_MAC)
// Workaround bug #1043 where bitmaps with referenced pixels cause
// CGImageDestinationFinalize to crash
SkBitmap copy;
- bitmapToUse->deepCopyTo(&copy, bitmapToUse->config());
- bitmapToUse = ©
+ bitmap.deepCopyTo(&copy, bitmap.config());
+ bm = copy;
#endif
- return SkImageEncoder::EncodeStream(stream,
- *bitmapToUse,
- SkImageEncoder::kJPEG_Type,
- FLAGS_pdfJpegQuality);
+ SkPixelRef* pr = bm.pixelRef();
+ if (pr != NULL) {
+ SkData* data = pr->refEncodedData();
+ if (data != NULL) {
+ *pixelRefOffset = bm.pixelRefOffset();
+ return data;
+ }
+ }
+
+ *pixelRefOffset = 0;
+ return SkImageEncoder::EncodeData(bm,
+ SkImageEncoder::kJPEG_Type,
+ FLAGS_pdfJpegQuality);
}
static int findConfig(const char config[]) {
« no previous file with comments | « no previous file | include/pdf/SkPDFDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698