Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: src/codec/SkCodec_libpng.cpp

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 417 }
418 // Check for supported color types 418 // Check for supported color types
419 switch (dst.colorType()) { 419 switch (dst.colorType()) {
420 case kN32_SkColorType: 420 case kN32_SkColorType:
421 return true; 421 return true;
422 default: 422 default:
423 return dst.colorType() == src.colorType(); 423 return dst.colorType() == src.colorType();
424 } 424 }
425 } 425 }
426 426
427 bool SkPngCodec::onIsInterlaced() {
428 if (1 == png_set_interlace_handling(fPng_ptr)){
scroggo 2015/07/27 15:09:19 You actually do not need a conditional here. You c
emmaleer 2015/07/27 18:31:38 Acknowledged.
429 return false;
430 } else {
431 return true;
432 }
433 }
434
427 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, 435 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
428 void* dst, size_t rowBytes, 436 void* dst, size_t rowBytes,
429 const Options& options, 437 const Options& options,
430 SkPMColor ctable[], 438 SkPMColor ctable[],
431 int* ctableCount) { 439 int* ctableCount) {
432 // FIXME: Could we use the return value of setjmp to specify the type of 440 // FIXME: Could we use the return value of setjmp to specify the type of
433 // error? 441 // error?
434 if (setjmp(png_jmpbuf(fPng_ptr))) { 442 if (setjmp(png_jmpbuf(fPng_ptr))) {
435 SkCodecPrintf("setjmp long jump!\n"); 443 SkCodecPrintf("setjmp long jump!\n");
436 return kInvalidInput; 444 return kInvalidInput;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 594 }
587 595
588 // read rest of file, and get additional comment and time chunks in info_ptr 596 // read rest of file, and get additional comment and time chunks in info_ptr
589 png_read_end(fPng_ptr, fInfo_ptr); 597 png_read_end(fPng_ptr, fInfo_ptr);
590 return kSuccess; 598 return kSuccess;
591 } 599 }
592 600
593 class SkPngScanlineDecoder : public SkScanlineDecoder { 601 class SkPngScanlineDecoder : public SkScanlineDecoder {
594 public: 602 public:
595 SkPngScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec) 603 SkPngScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec)
596 : INHERITED(dstInfo) 604 : INHERITED(dstInfo, codec->getInfo())
597 , fCodec(codec) 605 , fCodec(codec)
598 , fHasAlpha(false) 606 , fHasAlpha(false)
599 { 607 {
600 fStorage.reset(dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcC onfig)); 608 fStorage.reset(fCodec->getInfo().width() * SkSwizzler::BytesPerPixel(fCo dec->fSrcConfig));
601 fSrcRow = static_cast<uint8_t*>(fStorage.get()); 609 fSrcRow = static_cast<uint8_t*>(fStorage.get());
602 } 610 }
603 611
612 bool onSetSampleX(int sampleX) override {
613 fCodec->fSwizzler->setSampleX(sampleX);
614 return true;
615 }
616
604 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de { 617 SkCodec::Result onGetScanlines(void* dst, int count, size_t rowBytes) overri de {
605 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) { 618 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
606 SkCodecPrintf("setjmp long jump!\n"); 619 SkCodecPrintf("setjmp long jump!\n");
607 return SkCodec::kInvalidInput; 620 return SkCodec::kInvalidInput;
608 } 621 }
609 622
610 for (int i = 0; i < count; i++) { 623 for (int i = 0; i < count; i++) {
611 png_read_rows(fCodec->fPng_ptr, &fSrcRow, png_bytepp_NULL, 1); 624 png_read_rows(fCodec->fPng_ptr, &fSrcRow, png_bytepp_NULL, 1);
612 fCodec->fSwizzler->setDstRow(dst); 625 fCodec->fSwizzler->setDstRow(dst);
613 fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(fSrcRow)) ; 626 fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(fSrcRow)) ;
(...skipping 26 matching lines...) Expand all
640 SkAutoMalloc fStorage; 653 SkAutoMalloc fStorage;
641 uint8_t* fSrcRow; 654 uint8_t* fSrcRow;
642 655
643 typedef SkScanlineDecoder INHERITED; 656 typedef SkScanlineDecoder INHERITED;
644 }; 657 };
645 658
646 659
647 class SkPngInterlacedScanlineDecoder : public SkScanlineDecoder { 660 class SkPngInterlacedScanlineDecoder : public SkScanlineDecoder {
648 public: 661 public:
649 SkPngInterlacedScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec ) 662 SkPngInterlacedScanlineDecoder(const SkImageInfo& dstInfo, SkPngCodec* codec )
650 : INHERITED(dstInfo) 663 : INHERITED(dstInfo, codec->getInfo())
651 , fCodec(codec) 664 , fCodec(codec)
652 , fHasAlpha(false) 665 , fHasAlpha(false)
653 , fCurrentRow(0) 666 , fCurrentRow(0)
654 , fHeight(dstInfo.height()) 667 , fHeight(dstInfo.height())
655 { 668 {
656 fSrcRowBytes = dstInfo.width() * SkSwizzler::BytesPerPixel(fCodec->fSrcC onfig); 669 fSrcRowBytes = codec->getInfo().width() * SkSwizzler::BytesPerPixel(fCod ec->fSrcConfig);
657 fGarbageRow.reset(fSrcRowBytes); 670 fGarbageRow.reset(fSrcRowBytes);
658 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); 671 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get());
659 } 672 }
660 673
674 bool onSetSampleX(int sampleX) override {
675 fCodec->fSwizzler->setSampleX(sampleX);
676 return true;
677 }
678
661 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove rride { 679 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove rride {
662 //rewind stream if have previously called onGetScanlines, 680 //rewind stream if have previously called onGetScanlines,
663 //since we need entire progressive image to get scanlines 681 //since we need entire progressive image to get scanlines
664 if (!fCodec->handleRewind()) { 682 if (!fCodec->handleRewind()) {
665 return SkCodec::kCouldNotRewind; 683 return SkCodec::kCouldNotRewind;
666 } 684 }
667 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) { 685 if (setjmp(png_jmpbuf(fCodec->fPng_ptr))) {
668 SkCodecPrintf("setjmp long jump!\n"); 686 SkCodecPrintf("setjmp long jump!\n");
669 return SkCodec::kInvalidInput; 687 return SkCodec::kInvalidInput;
670 } 688 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 }; 739 };
722 740
723 741
724 SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, 742 SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
725 const Options& options, SkPMColor ctable[], int* ctableCount) { 743 const Options& options, SkPMColor ctable[], int* ctableCount) {
726 if (!conversion_possible(dstInfo, this->getInfo())) { 744 if (!conversion_possible(dstInfo, this->getInfo())) {
727 SkCodecPrintf("no conversion possible\n"); 745 SkCodecPrintf("no conversion possible\n");
728 return NULL; 746 return NULL;
729 } 747 }
730 // Check to see if scaling was requested. 748 // Check to see if scaling was requested.
731 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 749 if(options.fScaled == false) {
scroggo 2015/07/27 15:09:19 Please add a comment explaining this. Something li
emmaleer 2015/07/27 18:31:38 Changed to fSampled. For normal images the dstHei
scroggo 2015/07/27 19:29:56 Does the SkCodec need to know that dstHeight is sm
emmaleer 2015/07/28 14:19:16 Yes, I have changed the height to be the original
732 return NULL; 750 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
751 return NULL;
752 }
733 } 753 }
734 // Create a new SkPngCodec, to be owned by the scanline decoder. 754 // Create a new SkPngCodec, to be owned by the scanline decoder.
735 SkStream* stream = this->stream()->duplicate(); 755 SkStream* stream = this->stream()->duplicate();
736 if (!stream) { 756 if (!stream) {
737 return NULL; 757 return NULL;
738 } 758 }
739 SkAutoTDelete<SkPngCodec> codec (static_cast<SkPngCodec*>(SkPngCodec::NewFro mStream(stream))); 759 SkAutoTDelete<SkPngCodec> codec (static_cast<SkPngCodec*>(SkPngCodec::NewFro mStream(stream)));
740 if (!codec) { 760 if (!codec) {
741 return NULL; 761 return NULL;
742 } 762 }
743 763
744 // Note: We set dst to NULL since we do not know it yet. rowBytes is not nee ded, 764 // Note: We set dst to NULL since we do not know it yet. rowBytes is not nee ded,
745 // since we'll be manually updating the dstRow, but the SkSwizzler requires it to 765 // since we'll be manually updating the dstRow, but the SkSwizzler requires it to
746 // be at least dstInfo.minRowBytes. 766 // be at least dstInfo.minRowBytes.
747 if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable, 767 if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable,
748 ctableCount) != kSuccess) { 768 ctableCount) != kSuccess) {
749 SkCodecPrintf("failed to initialize the swizzler.\n"); 769 SkCodecPrintf("failed to initialize the swizzler.\n");
750 return NULL; 770 return NULL;
751 } 771 }
752 772
753 SkASSERT(codec->fNumberPasses != INVALID_NUMBER_PASSES); 773 SkASSERT(codec->fNumberPasses != INVALID_NUMBER_PASSES);
754 if (codec->fNumberPasses > 1) { 774 if (codec->fNumberPasses > 1) {
755 // interlaced image 775 // interlaced image
756 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, codec.detach ())); 776 return SkNEW_ARGS(SkPngInterlacedScanlineDecoder, (dstInfo, codec.detach ()));
757 } 777 }
758 778
759 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, codec.detach())); 779 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, codec.detach()));
760 } 780 }
761 781
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698