OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkData.h" | 8 #include "SkData.h" |
9 #include "SkDeflate.h" | 9 #include "SkDeflate.h" |
10 #include "SkPDFTypes.h" | 10 #include "SkPDFTypes.h" |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 566 |
567 #ifdef SK_PDF_LESS_COMPRESSION | 567 #ifdef SK_PDF_LESS_COMPRESSION |
568 fCompressedData = std::move(stream); | 568 fCompressedData = std::move(stream); |
569 SkASSERT(fCompressedData && fCompressedData->hasLength()); | 569 SkASSERT(fCompressedData && fCompressedData->hasLength()); |
570 fDict.insertInt("Length", fCompressedData->getLength()); | 570 fDict.insertInt("Length", fCompressedData->getLength()); |
571 #else | 571 #else |
572 | 572 |
573 SkASSERT(stream->hasLength()); | 573 SkASSERT(stream->hasLength()); |
574 SkDynamicMemoryWStream compressedData; | 574 SkDynamicMemoryWStream compressedData; |
575 SkDeflateWStream deflateWStream(&compressedData); | 575 SkDeflateWStream deflateWStream(&compressedData); |
576 SkStreamCopy(&deflateWStream, stream.get()); | 576 if (stream->getLength() > 0) { |
| 577 SkStreamCopy(&deflateWStream, stream.get()); |
| 578 } |
577 deflateWStream.finalize(); | 579 deflateWStream.finalize(); |
578 size_t compressedLength = compressedData.bytesWritten(); | 580 size_t compressedLength = compressedData.bytesWritten(); |
579 size_t originalLength = stream->getLength(); | 581 size_t originalLength = stream->getLength(); |
580 | 582 |
581 if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) { | 583 if (originalLength <= compressedLength + strlen("/Filter_/FlateDecode_")) { |
582 SkAssertResult(stream->rewind()); | 584 SkAssertResult(stream->rewind()); |
583 fCompressedData = std::move(stream); | 585 fCompressedData = std::move(stream); |
584 fDict.insertInt("Length", originalLength); | 586 fDict.insertInt("Length", originalLength); |
585 return; | 587 return; |
586 } | 588 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 | 642 |
641 void SkPDFImageDumpStats() { | 643 void SkPDFImageDumpStats() { |
642 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" | 644 SkDebugf("\ntotal PDF drawImage/drawBitmap calls: %d\n" |
643 "total PDF jpeg images: %d\n" | 645 "total PDF jpeg images: %d\n" |
644 "total PDF regular images: %d\n", | 646 "total PDF regular images: %d\n", |
645 gDrawImageCalls.load(), | 647 gDrawImageCalls.load(), |
646 gJpegImageObjects.load(), | 648 gJpegImageObjects.load(), |
647 gRegularImageObjects.load()); | 649 gRegularImageObjects.load()); |
648 } | 650 } |
649 #endif // SK_PDF_IMAGE_STATS | 651 #endif // SK_PDF_IMAGE_STATS |
OLD | NEW |