| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
| 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 "SkPDFImage.h" | 8 #include "SkPDFImage.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 if (!getSubstitute()) { | 622 if (!getSubstitute()) { |
| 623 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); | 623 SkPDFStream* substitute = SkNEW_ARGS(SkPDFImage, (*this)); |
| 624 setSubstitute(substitute); | 624 setSubstitute(substitute); |
| 625 catalog->setSubstitute(this, substitute); | 625 catalog->setSubstitute(this, substitute); |
| 626 } | 626 } |
| 627 return false; | 627 return false; |
| 628 } | 628 } |
| 629 return true; | 629 return true; |
| 630 } | 630 } |
| 631 | 631 |
| 632 #if 0 // reenable when we can figure out the JPEG colorspace |
| 632 namespace { | 633 namespace { |
| 633 /** | 634 /** |
| 634 * This PDFObject assumes that its constructor was handed | 635 * This PDFObject assumes that its constructor was handed |
| 635 * Jpeg-encoded data that can be directly embedded into a PDF. | 636 * Jpeg-encoded data that can be directly embedded into a PDF. |
| 636 */ | 637 */ |
| 637 class PDFJPEGImage : public SkPDFObject { | 638 class PDFJPEGImage : public SkPDFObject { |
| 638 SkAutoTUnref<SkData> fData; | 639 SkAutoTUnref<SkData> fData; |
| 639 int fWidth; | 640 int fWidth; |
| 640 int fHeight; | 641 int fHeight; |
| 641 public: | 642 public: |
| 642 PDFJPEGImage(SkData* data, int width, int height) | 643 PDFJPEGImage(SkData* data, int width, int height) |
| 643 : fData(SkRef(data)), fWidth(width), fHeight(height) {} | 644 : fData(SkRef(data)), fWidth(width), fHeight(height) {} |
| 644 virtual void getResources(const SkTSet<SkPDFObject*>&, | 645 virtual void getResources(const SkTSet<SkPDFObject*>&, |
| 645 SkTSet<SkPDFObject*>*) SK_OVERRIDE {} | 646 SkTSet<SkPDFObject*>*) SK_OVERRIDE {} |
| 646 virtual void emitObject( | 647 virtual void emitObject( |
| 647 SkWStream* stream, | 648 SkWStream* stream, |
| 648 SkPDFCatalog* catalog, bool indirect) SK_OVERRIDE { | 649 SkPDFCatalog* catalog, bool indirect) SK_OVERRIDE { |
| 649 if (indirect) { | 650 if (indirect) { |
| 650 this->emitIndirectObject(stream, catalog); | 651 this->emitIndirectObject(stream, catalog); |
| 651 return; | 652 return; |
| 652 } | 653 } |
| 653 SkASSERT(fData.get()); | 654 SkASSERT(fData.get()); |
| 654 const char kPrefaceFormat[] = | 655 const char kPrefaceFormat[] = |
| 655 "<<" | 656 "<<" |
| 656 "/Type /XObject\n" | 657 "/Type /XObject\n" |
| 657 "/Subtype /Image\n" | 658 "/Subtype /Image\n" |
| 658 "/Width %d\n" | 659 "/Width %d\n" |
| 659 "/Height %d\n" | 660 "/Height %d\n" |
| 660 "/ColorSpace /DeviceRGB\n" | 661 "/ColorSpace /DeviceRGB\n" // or DeviceGray |
| 661 "/BitsPerComponent 8\n" | 662 "/BitsPerComponent 8\n" |
| 662 "/Filter /DCTDecode\n" | 663 "/Filter /DCTDecode\n" |
| 663 "/ColorTransform 0\n" | 664 "/ColorTransform 0\n" |
| 664 "/Length " SK_SIZE_T_SPECIFIER "\n" | 665 "/Length " SK_SIZE_T_SPECIFIER "\n" |
| 665 ">> stream\n"; | 666 ">> stream\n"; |
| 666 SkString preface( | 667 SkString preface( |
| 667 SkStringPrintf(kPrefaceFormat, fWidth, fHeight, fData->size())); | 668 SkStringPrintf(kPrefaceFormat, fWidth, fHeight, fData->size())); |
| 668 const char kPostface[] = "\nendstream"; | 669 const char kPostface[] = "\nendstream"; |
| 669 stream->write(preface.c_str(), preface.size()); | 670 stream->write(preface.c_str(), preface.size()); |
| 670 stream->write(fData->data(), fData->size()); | 671 stream->write(fData->data(), fData->size()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 695 const uint8_t bytesZeroToThree[] = {0xFF, 0xD8, 0xFF, 0xE0}; | 696 const uint8_t bytesZeroToThree[] = {0xFF, 0xD8, 0xFF, 0xE0}; |
| 696 const uint8_t bytesSixToTen[] = {'J', 'F', 'I', 'F', 0}; | 697 const uint8_t bytesSixToTen[] = {'J', 'F', 'I', 'F', 0}; |
| 697 // 0 1 2 3 4 5 6 7 8 9 10 | 698 // 0 1 2 3 4 5 6 7 8 9 10 |
| 698 // FF D8 FF E0 ?? ?? 'J' 'F' 'I' 'F' 00 ... | 699 // FF D8 FF E0 ?? ?? 'J' 'F' 'I' 'F' 00 ... |
| 699 return ((0 == memcmp(data->bytes(), bytesZeroToThree, | 700 return ((0 == memcmp(data->bytes(), bytesZeroToThree, |
| 700 sizeof(bytesZeroToThree))) | 701 sizeof(bytesZeroToThree))) |
| 701 && (0 == memcmp(data->bytes() + 6, bytesSixToTen, | 702 && (0 == memcmp(data->bytes() + 6, bytesSixToTen, |
| 702 sizeof(bytesSixToTen)))); | 703 sizeof(bytesSixToTen)))); |
| 703 } | 704 } |
| 704 } // namespace | 705 } // namespace |
| 706 #endif |
| 705 | 707 |
| 706 SkPDFObject* SkPDFCreateImageObject( | 708 SkPDFObject* SkPDFCreateImageObject( |
| 707 const SkBitmap& bitmap, | 709 const SkBitmap& bitmap, |
| 708 const SkIRect& subset, | 710 const SkIRect& subset, |
| 709 SkPicture::EncodeBitmap encoder) { | 711 SkPicture::EncodeBitmap encoder) { |
| 712 #if 0 // reenable when we can figure out the JPEG colorspace |
| 710 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { | 713 if (SkIRect::MakeWH(bitmap.width(), bitmap.height()) == subset) { |
| 711 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); | 714 SkAutoTUnref<SkData> encodedData(ref_encoded_data(bitmap)); |
| 712 if (is_jfif_jpeg(encodedData)) { | 715 if (is_jfif_jpeg(encodedData)) { |
| 713 return SkNEW_ARGS(PDFJPEGImage, | 716 return SkNEW_ARGS(PDFJPEGImage, |
| 714 (encodedData, bitmap.width(), bitmap.height())); | 717 (encodedData, bitmap.width(), bitmap.height())); |
| 715 } | 718 } |
| 716 } | 719 } |
| 720 #endif |
| 717 return SkPDFImage::CreateImage(bitmap, subset, encoder); | 721 return SkPDFImage::CreateImage(bitmap, subset, encoder); |
| 718 } | 722 } |
| OLD | NEW |