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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 380 |
381 namespace { | 381 namespace { |
382 // This SkPDFObject only outputs the alpha layer of the given bitmap. | 382 // This SkPDFObject only outputs the alpha layer of the given bitmap. |
383 class PDFAlphaBitmap final : public SkPDFObject { | 383 class PDFAlphaBitmap final : public SkPDFObject { |
384 public: | 384 public: |
385 PDFAlphaBitmap(const SkImage* image) : fImage(SkRef(image)) {} | 385 PDFAlphaBitmap(const SkImage* image) : fImage(SkRef(image)) {} |
386 ~PDFAlphaBitmap() {} | 386 ~PDFAlphaBitmap() {} |
387 void emitObject(SkWStream* stream, | 387 void emitObject(SkWStream* stream, |
388 const SkPDFObjNumMap& objNumMap, | 388 const SkPDFObjNumMap& objNumMap, |
389 const SkPDFSubstituteMap& subs) const override { | 389 const SkPDFSubstituteMap& subs) const override { |
390 emit_image_xobject(stream, fImage, true, nullptr, objNumMap, subs); | 390 emit_image_xobject(stream, fImage.get(), true, nullptr, objNumMap, subs)
; |
391 } | 391 } |
392 | 392 |
393 private: | 393 private: |
394 SkAutoTUnref<const SkImage> fImage; | 394 SkAutoTUnref<const SkImage> fImage; |
395 }; | 395 }; |
396 | 396 |
397 } // namespace | 397 } // namespace |
398 | 398 |
399 //////////////////////////////////////////////////////////////////////////////// | 399 //////////////////////////////////////////////////////////////////////////////// |
400 | 400 |
401 namespace { | 401 namespace { |
402 class PDFDefaultBitmap final : public SkPDFObject { | 402 class PDFDefaultBitmap final : public SkPDFObject { |
403 public: | 403 public: |
404 void emitObject(SkWStream* stream, | 404 void emitObject(SkWStream* stream, |
405 const SkPDFObjNumMap& objNumMap, | 405 const SkPDFObjNumMap& objNumMap, |
406 const SkPDFSubstituteMap& subs) const override { | 406 const SkPDFSubstituteMap& subs) const override { |
407 emit_image_xobject(stream, fImage, false, fSMask, objNumMap, subs); | 407 emit_image_xobject(stream, fImage.get(), false, fSMask.get(), objNumMap,
subs); |
408 } | 408 } |
409 void addResources(SkPDFObjNumMap* catalog, | 409 void addResources(SkPDFObjNumMap* catalog, |
410 const SkPDFSubstituteMap& subs) const override { | 410 const SkPDFSubstituteMap& subs) const override { |
411 if (fSMask.get()) { | 411 if (fSMask.get()) { |
412 SkPDFObject* obj = subs.getSubstitute(fSMask.get()); | 412 SkPDFObject* obj = subs.getSubstitute(fSMask.get()); |
413 SkASSERT(obj); | 413 SkASSERT(obj); |
414 catalog->addObjectRecursively(obj, subs); | 414 catalog->addObjectRecursively(obj, subs); |
415 } | 415 } |
416 } | 416 } |
417 PDFDefaultBitmap(const SkImage* image, SkPDFObject* smask) | 417 PDFDefaultBitmap(const SkImage* image, SkPDFObject* smask) |
(...skipping 47 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.get(), &info) && |
476 (!pixelSerializer || | 476 (!pixelSerializer || |
477 pixelSerializer->useEncodedData(data->data(), data->size()))) { | 477 pixelSerializer->useEncodedData(data->data(), data->size()))) { |
478 // If there is a SkPixelSerializer, give it a chance to | 478 // If there is a SkPixelSerializer, give it a chance to |
479 // re-encode the JPEG with more compression by returning false | 479 // re-encode the JPEG with more compression by returning false |
480 // from useEncodedData. | 480 // from useEncodedData. |
481 bool yuv = info.fType == SkJFIFInfo::kYCbCr; | 481 bool yuv = info.fType == SkJFIFInfo::kYCbCr; |
482 if (info.fSize == image->dimensions()) { // Sanity check. | 482 if (info.fSize == image->dimensions()) { // Sanity check. |
483 // hold on to data, not image. | 483 // hold on to data, not image. |
484 #ifdef SK_PDF_IMAGE_STATS | 484 #ifdef SK_PDF_IMAGE_STATS |
485 gJpegImageObjects.fetch_add(1); | 485 gJpegImageObjects.fetch_add(1); |
486 #endif | 486 #endif |
487 return new PDFJpegBitmap(info.fSize, data, yuv); | 487 return new PDFJpegBitmap(info.fSize, data.get(), yuv); |
488 } | 488 } |
489 } | 489 } |
490 | 490 |
491 if (pixelSerializer) { | 491 if (pixelSerializer) { |
492 SkBitmap bm; | 492 SkBitmap bm; |
493 SkAutoPixmapUnlock apu; | 493 SkAutoPixmapUnlock apu; |
494 if (as_IB(image)->getROPixels(&bm) && bm.requestLock(&apu)) { | 494 if (as_IB(image)->getROPixels(&bm) && bm.requestLock(&apu)) { |
495 data.reset(pixelSerializer->encode(apu.pixmap())); | 495 data.reset(pixelSerializer->encode(apu.pixmap())); |
496 if (data && SkIsJFIF(data, &info)) { | 496 if (data && SkIsJFIF(data.get(), &info)) { |
497 bool yuv = info.fType == SkJFIFInfo::kYCbCr; | 497 bool yuv = info.fType == SkJFIFInfo::kYCbCr; |
498 if (info.fSize == image->dimensions()) { // Sanity check. | 498 if (info.fSize == image->dimensions()) { // Sanity check. |
499 return new PDFJpegBitmap(info.fSize, data, yuv); | 499 return new PDFJpegBitmap(info.fSize, data.get(), yuv); |
500 } | 500 } |
501 } | 501 } |
502 } | 502 } |
503 } | 503 } |
504 | 504 |
505 SkPDFObject* smask = | 505 SkPDFObject* smask = |
506 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image)
; | 506 image_compute_is_opaque(image) ? nullptr : new PDFAlphaBitmap(image)
; |
507 #ifdef SK_PDF_IMAGE_STATS | 507 #ifdef SK_PDF_IMAGE_STATS |
508 gRegularImageObjects.fetch_add(1); | 508 gRegularImageObjects.fetch_add(1); |
509 #endif | 509 #endif |
510 return new PDFDefaultBitmap(image, smask); | 510 return new PDFDefaultBitmap(image, smask); |
511 } | 511 } |
OLD | NEW |