aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkPDFBitmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pdf/SkPDFBitmap.cpp')
-rw-r--r--src/pdf/SkPDFBitmap.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index 8c312963da..f97eeff484 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -408,16 +408,15 @@ void PDFJpegBitmap::emitObject(SkWStream* stream,
////////////////////////////////////////////////////////////////////////////////
sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
- SkPixelSerializer* pixelSerializer) {
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
+ SkPixelSerializer* pixelSerializer,
+#endif
+ int encodingQuality) {
SkASSERT(image);
+ SkASSERT(encodingQuality >= 0);
sk_sp<SkData> data = image->refEncodedData();
SkJFIFInfo info;
- if (data && SkIsJFIF(data.get(), &info) &&
- (!pixelSerializer ||
- pixelSerializer->useEncodedData(data->data(), data->size()))) {
- // If there is a SkPixelSerializer, give it a chance to
- // re-encode the JPEG with more compression by returning false
- // from useEncodedData.
+ if (data && SkIsJFIF(data.get(), &info)) {
bool yuv = info.fType == SkJFIFInfo::kYCbCr;
if (info.fSize == image->dimensions()) { // Sanity check.
// hold on to data, not image.
@@ -428,6 +427,7 @@ sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
}
}
+#ifdef SK_SUPPORT_LEGACY_PDF_PIXELSERIALIZER
if (pixelSerializer) {
SkBitmap bm;
SkPixmap pmap;
@@ -441,9 +441,22 @@ sk_sp<SkPDFObject> SkPDFCreateBitmapObject(sk_sp<SkImage> image,
}
}
}
+#endif
+
+ const bool isOpaque = image_compute_is_opaque(image.get());
+
+ if (encodingQuality <= 100 && isOpaque) {
+ data = image->encodeToData(SkEncodedImageFormat::kJPEG, encodingQuality);
+ if (data && SkIsJFIF(data.get(), &info)) {
+ bool yuv = info.fType == SkJFIFInfo::kYCbCr;
+ if (info.fSize == image->dimensions()) { // Sanity check.
+ return sk_make_sp<PDFJpegBitmap>(info.fSize, data.get(), yuv);
+ }
+ }
+ }
sk_sp<SkPDFObject> smask;
- if (!image_compute_is_opaque(image.get())) {
+ if (!isOpaque) {
smask = sk_make_sp<PDFAlphaBitmap>(image);
}
#ifdef SK_PDF_IMAGE_STATS