| 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 "SkCodec_libpng.h" | 8 #include "SkCodec_libpng.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 for (int y = 0; y < requestedInfo.height(); y++) { | 569 for (int y = 0; y < requestedInfo.height(); y++) { |
| 570 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); | 570 png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); |
| 571 fReallyHasAlpha |= !SkSwizzler::IsOpaque(fSwizzler->next(srcRow)); | 571 fReallyHasAlpha |= !SkSwizzler::IsOpaque(fSwizzler->next(srcRow)); |
| 572 } | 572 } |
| 573 } | 573 } |
| 574 | 574 |
| 575 // FIXME: do we need substituteTranspColor? Note that we cannot do it for | 575 // FIXME: do we need substituteTranspColor? Note that we cannot do it for |
| 576 // scanline decoding, but we could do it here. Alternatively, we could do | 576 // scanline decoding, but we could do it here. Alternatively, we could do |
| 577 // it as we go, instead of in post-processing like SkPNGImageDecoder. | 577 // it as we go, instead of in post-processing like SkPNGImageDecoder. |
| 578 | 578 |
| 579 this->finish(); | 579 if (setjmp(png_jmpbuf(fPng_ptr))) { |
| 580 // We've already read all the scanlines. This is a success. |
| 581 return kSuccess; |
| 582 } |
| 583 |
| 584 // read rest of file, and get additional comment and time chunks in info_ptr |
| 585 png_read_end(fPng_ptr, fInfo_ptr); |
| 580 return kSuccess; | 586 return kSuccess; |
| 581 } | 587 } |
| 582 | 588 |
| 583 void SkPngCodec::finish() { | |
| 584 if (setjmp(png_jmpbuf(fPng_ptr))) { | |
| 585 // We've already read all the scanlines. This is a success. | |
| 586 return; | |
| 587 } | |
| 588 // FIXME: Is this necessary? | |
| 589 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ | |
| 590 png_read_end(fPng_ptr, fInfo_ptr); | |
| 591 } | |
| 592 | |
| 593 class SkPngScanlineDecoder : public SkScanlineDecoder { | 589 class SkPngScanlineDecoder : public SkScanlineDecoder { |
| 594 public: | 590 public: |
| 595 SkPngScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec) | 591 SkPngScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec) |
| 596 : INHERITED(dstInfo) | 592 : INHERITED(dstInfo) |
| 597 , fCodec(codec) | 593 , fCodec(codec) |
| 598 , fHasAlpha(false) | 594 , fHasAlpha(false) |
| 599 { | 595 { |
| 600 fStorage.reset(dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcC
onfig)); | 596 fStorage.reset(dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcC
onfig)); |
| 601 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | 597 fSrcRow = static_cast<uint8_t*>(fStorage.get()); |
| 602 } | 598 } |
| 603 | 599 |
| 604 ~SkPngScanlineDecoder() { | |
| 605 fCodec->finish(); | |
| 606 } | |
| 607 | |
| 608 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri
de { | 600 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri
de { |
| 609 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) { | 601 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) { |
| 610 SkCodecPrintf("setjmp long jump!\n"); | 602 SkCodecPrintf("setjmp long jump!\n"); |
| 611 return SkCodec::kInvalidInput; | 603 return SkCodec::kInvalidInput; |
| 612 } | 604 } |
| 613 | 605 |
| 614 for (int i = 0; i < count; i++) { | 606 for (int i = 0; i < count; i++) { |
| 615 png_read_rows(fCodec->fPng_ptr, &fSrcRow, png_bytepp_NULL, 1); | 607 png_read_rows(fCodec->fPng_ptr, &fSrcRow, png_bytepp_NULL, 1); |
| 616 fCodec->fSwizzler->setDstRow(dst); | 608 fCodec->fSwizzler->setDstRow(dst); |
| 617 fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(fSrcRow))
; | 609 fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(fSrcRow))
; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 , fCodec(codec) | 647 , fCodec(codec) |
| 656 , fHasAlpha(false) | 648 , fHasAlpha(false) |
| 657 , fCurrentRow(0) | 649 , fCurrentRow(0) |
| 658 , fHeight(dstInfo.height()) | 650 , fHeight(dstInfo.height()) |
| 659 { | 651 { |
| 660 fSrcRowBytes = dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcC
onfig); | 652 fSrcRowBytes = dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcC
onfig); |
| 661 fGarbageRow.reset(fSrcRowBytes); | 653 fGarbageRow.reset(fSrcRowBytes); |
| 662 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); | 654 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); |
| 663 } | 655 } |
| 664 | 656 |
| 665 ~SkPngInterlacedScanlineDecoder() { | |
| 666 fCodec->finish(); | |
| 667 } | |
| 668 | |
| 669 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove
rride { | 657 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove
rride { |
| 670 //rewind stream if have previously called onGetScanlines, | 658 //rewind stream if have previously called onGetScanlines, |
| 671 //since we need entire progressive image to get scanlines | 659 //since we need entire progressive image to get scanlines |
| 672 if (!fCodec->handleRewind()) { | 660 if (!fCodec->handleRewind()) { |
| 673 return SkCodec::kCouldNotRewind; | 661 return SkCodec::kCouldNotRewind; |
| 674 } | 662 } |
| 675 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) { | 663 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) { |
| 676 SkCodecPrintf("setjmp long jump!\n"); | 664 SkCodecPrintf("setjmp long jump!\n"); |
| 677 return SkCodec::kInvalidInput; | 665 return SkCodec::kInvalidInput; |
| 678 } | 666 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 748 |
| 761 SkASSERT(codec->fNumberPasses != INVALID_NUMBER_PASSES); | 749 SkASSERT(codec->fNumberPasses != INVALID_NUMBER_PASSES); |
| 762 if (codec->fNumberPasses > 1) { | 750 if (codec->fNumberPasses > 1) { |
| 763 // interlaced image | 751 // interlaced image |
| 764 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, codec.detach
())); | 752 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, codec.detach
())); |
| 765 } | 753 } |
| 766 | 754 |
| 767 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, codec.detach())); | 755 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, codec.detach())); |
| 768 } | 756 } |
| 769 | 757 |
| OLD | NEW |