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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 387 } |
388 } | 388 } |
389 | 389 |
390 /////////////////////////////////////////////////////////////////////////////// | 390 /////////////////////////////////////////////////////////////////////////////// |
391 // Getting the pixels | 391 // Getting the pixels |
392 /////////////////////////////////////////////////////////////////////////////// | 392 /////////////////////////////////////////////////////////////////////////////// |
393 | 393 |
394 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, | 394 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, |
395 const Options& options, | 395 const Options& options, |
396 SkPMColor ctable[], | 396 SkPMColor ctable[], |
397 int* ctableCount) { | 397 int* ctableCount, |
| 398 int subsetLeft, |
| 399 int subsetWidth) { |
398 // FIXME: Could we use the return value of setjmp to specify the type of | 400 // FIXME: Could we use the return value of setjmp to specify the type of |
399 // error? | 401 // error? |
400 if (setjmp(png_jmpbuf(fPng_ptr))) { | 402 if (setjmp(png_jmpbuf(fPng_ptr))) { |
401 SkCodecPrintf("setjmp long jump!\n"); | 403 SkCodecPrintf("setjmp long jump!\n"); |
402 return kInvalidInput; | 404 return kInvalidInput; |
403 } | 405 } |
404 png_read_update_info(fPng_ptr, fInfo_ptr); | 406 png_read_update_info(fPng_ptr, fInfo_ptr); |
405 | 407 |
406 //srcColorType was determined in read_header() which determined png color ty
pe | 408 //srcColorType was determined in read_header() which determined png color ty
pe |
407 const SkColorType srcColorType = this->getInfo().colorType(); | 409 const SkColorType srcColorType = this->getInfo().colorType(); |
(...skipping 21 matching lines...) Expand all Loading... |
429 //would have exited before now if the colorType was supported by png | 431 //would have exited before now if the colorType was supported by png |
430 SkASSERT(false); | 432 SkASSERT(false); |
431 } | 433 } |
432 | 434 |
433 // Copy the color table to the client if they request kIndex8 mode | 435 // Copy the color table to the client if they request kIndex8 mode |
434 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); | 436 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); |
435 | 437 |
436 // Create the swizzler. SkPngCodec retains ownership of the color table. | 438 // Create the swizzler. SkPngCodec retains ownership of the color table. |
437 const SkPMColor* colors = get_color_ptr(fColorTable.get()); | 439 const SkPMColor* colors = get_color_ptr(fColorTable.get()); |
438 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo
, | 440 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo
, |
439 options.fZeroInitialized)); | 441 options.fZeroInitialized, subsetLeft, subsetWidth)); |
440 if (!fSwizzler) { | 442 if (!fSwizzler) { |
441 // FIXME: CreateSwizzler could fail for another reason. | 443 // FIXME: CreateSwizzler could fail for another reason. |
442 return kUnimplemented; | 444 return kUnimplemented; |
443 } | 445 } |
444 return kSuccess; | 446 return kSuccess; |
445 } | 447 } |
446 | 448 |
447 | 449 |
448 bool SkPngCodec::onRewind() { | 450 bool SkPngCodec::onRewind() { |
449 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header | 451 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header |
(...skipping 20 matching lines...) Expand all Loading... |
470 int* rowsDecoded) { | 472 int* rowsDecoded) { |
471 if (!conversion_possible(requestedInfo, this->getInfo())) { | 473 if (!conversion_possible(requestedInfo, this->getInfo())) { |
472 return kInvalidConversion; | 474 return kInvalidConversion; |
473 } | 475 } |
474 if (options.fSubset) { | 476 if (options.fSubset) { |
475 // Subsets are not supported. | 477 // Subsets are not supported. |
476 return kUnimplemented; | 478 return kUnimplemented; |
477 } | 479 } |
478 | 480 |
479 // Note that ctable and ctableCount may be modified if there is a color tabl
e | 481 // Note that ctable and ctableCount may be modified if there is a color tabl
e |
480 const Result result = this->initializeSwizzler(requestedInfo, options, | 482 const Result result = this->initializeSwizzler(requestedInfo, options, ctabl
e, ctableCount, 0, |
481 ctable, ctableCount); | 483 requestedInfo.width()); |
482 if (result != kSuccess) { | 484 if (result != kSuccess) { |
483 return result; | 485 return result; |
484 } | 486 } |
485 // FIXME: Could we use the return value of setjmp to specify the type of | 487 // FIXME: Could we use the return value of setjmp to specify the type of |
486 // error? | 488 // error? |
487 int row = 0; | 489 int row = 0; |
488 if (setjmp(png_jmpbuf(fPng_ptr))) { | 490 if (setjmp(png_jmpbuf(fPng_ptr))) { |
489 // Assume that any error that occurs while reading rows is caused by an
incomplete input. | 491 // Assume that any error that occurs while reading rows is caused by an
incomplete input. |
490 if (fNumberPasses > 1) { | 492 if (fNumberPasses > 1) { |
491 // FIXME (msarett): Handle incomplete interlaced pngs. | 493 // FIXME (msarett): Handle incomplete interlaced pngs. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 class SkPngScanlineDecoder : public SkPngCodec { | 606 class SkPngScanlineDecoder : public SkPngCodec { |
605 public: | 607 public: |
606 SkPngScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, | 608 SkPngScanlineDecoder(const SkImageInfo& srcInfo, SkStream* stream, |
607 png_structp png_ptr, png_infop info_ptr, int bitDepth) | 609 png_structp png_ptr, png_infop info_ptr, int bitDepth) |
608 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, 1) | 610 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, 1) |
609 , fSrcRow(nullptr) | 611 , fSrcRow(nullptr) |
610 , fAlphaState(kUnknown_AlphaState) | 612 , fAlphaState(kUnknown_AlphaState) |
611 {} | 613 {} |
612 | 614 |
613 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 615 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
614 SkPMColor ctable[], int* ctableCount) override { | 616 SkPMColor ctable[], int* ctableCount, int subsetLeft, int subsetWidt
h) override { |
615 if (!conversion_possible(dstInfo, this->getInfo())) { | 617 if (!conversion_possible(dstInfo, this->getInfo())) { |
616 return kInvalidConversion; | 618 return kInvalidConversion; |
617 } | 619 } |
618 | 620 |
619 const Result result = this->initializeSwizzler(dstInfo, options, ctable, | 621 const Result result = this->initializeSwizzler(dstInfo, options, ctable, |
620 ctableCount); | 622 ctableCount, subsetLeft,
subsetWidth); |
621 if (result != kSuccess) { | 623 if (result != kSuccess) { |
622 return result; | 624 return result; |
623 } | 625 } |
624 | 626 |
625 fAlphaState = kUnknown_AlphaState; | 627 fAlphaState = kUnknown_AlphaState; |
626 fStorage.reset(this->getInfo().width() * SkSwizzler::BytesPerPixel(this-
>srcConfig())); | 628 fStorage.reset(this->getInfo().width() * SkSwizzler::BytesPerPixel(this-
>srcConfig())); |
627 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | 629 fSrcRow = static_cast<uint8_t*>(fStorage.get()); |
628 | 630 |
629 return kSuccess; | 631 return kSuccess; |
630 } | 632 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 png_structp png_ptr, png_infop info_ptr, int bitDepth, int numberPas
ses) | 693 png_structp png_ptr, png_infop info_ptr, int bitDepth, int numberPas
ses) |
692 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, numberPasses) | 694 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, numberPasses) |
693 , fAlphaState(kUnknown_AlphaState) | 695 , fAlphaState(kUnknown_AlphaState) |
694 , fHeight(-1) | 696 , fHeight(-1) |
695 , fCanSkipRewind(false) | 697 , fCanSkipRewind(false) |
696 { | 698 { |
697 SkASSERT(numberPasses != 1); | 699 SkASSERT(numberPasses != 1); |
698 } | 700 } |
699 | 701 |
700 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 702 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
701 SkPMColor ctable[], int* ctableCount) override | 703 SkPMColor ctable[], int* ctableCount, int subsetLeft, int subsetWidt
h) override { |
702 { | |
703 if (!conversion_possible(dstInfo, this->getInfo())) { | 704 if (!conversion_possible(dstInfo, this->getInfo())) { |
704 return kInvalidConversion; | 705 return kInvalidConversion; |
705 } | 706 } |
706 | 707 |
707 const SkCodec::Result result = this->initializeSwizzler(dstInfo, options
, ctable, | 708 const Result result = this->initializeSwizzler(dstInfo, options, ctable, |
708 ctableCount); | 709 ctableCount, subsetLeft,
subsetWidth); |
709 if (result != SkCodec::kSuccess) { | 710 if (result != kSuccess) { |
710 return result; | 711 return result; |
711 } | 712 } |
712 | 713 |
713 fAlphaState = kUnknown_AlphaState; | 714 fAlphaState = kUnknown_AlphaState; |
714 fHeight = dstInfo.height(); | 715 fHeight = dstInfo.height(); |
715 // FIXME: This need not be called on a second call to onStartScanlineDec
ode. | 716 // FIXME: This need not be called on a second call to onStartScanlineDec
ode. |
716 fSrcRowBytes = this->getInfo().width() * SkSwizzler::BytesPerPixel(this-
>srcConfig()); | 717 fSrcRowBytes = this->getInfo().width() * SkSwizzler::BytesPerPixel(this-
>srcConfig()); |
717 fGarbageRow.reset(fSrcRowBytes); | 718 fGarbageRow.reset(fSrcRowBytes); |
718 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); | 719 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); |
719 fCanSkipRewind = true; | 720 fCanSkipRewind = true; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 | 840 |
840 if (1 == numberPasses) { | 841 if (1 == numberPasses) { |
841 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), png_p
tr, info_ptr, | 842 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), png_p
tr, info_ptr, |
842 bitDepth); | 843 bitDepth); |
843 } | 844 } |
844 | 845 |
845 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
png_ptr, | 846 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
png_ptr, |
846 info_ptr, bitDepth, numberPasses); | 847 info_ptr, bitDepth, numberPasses); |
847 } | 848 } |
848 | 849 |
OLD | NEW |