OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkDeflate.h" | 10 #include "SkDeflate.h" |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 pdf_stream_end(stream); | 465 pdf_stream_end(stream); |
466 } | 466 } |
467 } // namespace | 467 } // namespace |
468 | 468 |
469 //////////////////////////////////////////////////////////////////////////////// | 469 //////////////////////////////////////////////////////////////////////////////// |
470 | 470 |
471 SkPDFObject* SkPDFCreateBitmapObject(const SkImage* image, | 471 SkPDFObject* SkPDFCreateBitmapObject(const SkImage* image, |
472 SkPixelSerializer* pixelSerializer) { | 472 SkPixelSerializer* pixelSerializer) { |
473 SkAutoTUnref<SkData> data(image->refEncoded()); | 473 SkAutoTUnref<SkData> data(image->refEncoded()); |
474 SkJFIFInfo info; | 474 SkJFIFInfo info; |
475 if (data && SkIsJFIF(data, &info)) { | 475 if (data && SkIsJFIF(data, &info) && |
| 476 (!pixelSerializer || |
| 477 pixelSerializer->useEncodedData(data->data(), data->size()))) { |
| 478 // If there is a SkPixelSerializer, give it a chance to |
| 479 // re-encode the JPEG with more compression by returning false |
| 480 // from useEncodedData. |
476 bool yuv = info.fType == SkJFIFInfo::kYCbCr; | 481 bool yuv = info.fType == SkJFIFInfo::kYCbCr; |
477 if (info.fSize == image->dimensions()) { // Sanity check. | 482 if (info.fSize == image->dimensions()) { // Sanity check. |
478 // hold on to data, not image. | 483 // hold on to data, not image. |
479 #ifdef SK_PDF_IMAGE_STATS | 484 #ifdef SK_PDF_IMAGE_STATS |
480 gJpegImageObjects.fetch_add(1); | 485 gJpegImageObjects.fetch_add(1); |
481 #endif | 486 #endif |
482 return new PDFJpegBitmap(info.fSize, data, yuv); | 487 return new PDFJpegBitmap(info.fSize, data, yuv); |
483 } | 488 } |
484 } | 489 } |
485 | 490 |
(...skipping 11 matching lines...) Expand all Loading... |
497 } | 502 } |
498 } | 503 } |
499 | 504 |
500 SkPDFObject* smask = | 505 SkPDFObject* smask = |
501 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image)
; | 506 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image)
; |
502 #ifdef SK_PDF_IMAGE_STATS | 507 #ifdef SK_PDF_IMAGE_STATS |
503 gRegularImageObjects.fetch_add(1); | 508 gRegularImageObjects.fetch_add(1); |
504 #endif | 509 #endif |
505 return new PDFDefaultBitmap(image, smask); | 510 return new PDFDefaultBitmap(image, smask); |
506 } | 511 } |
OLD | NEW |