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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 default: | 428 default: |
429 //would have exited before now if the colorType was supported by png | 429 //would have exited before now if the colorType was supported by png |
430 SkASSERT(false); | 430 SkASSERT(false); |
431 } | 431 } |
432 | 432 |
433 // Copy the color table to the client if they request kIndex8 mode | 433 // Copy the color table to the client if they request kIndex8 mode |
434 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); | 434 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); |
435 | 435 |
436 // Create the swizzler. SkPngCodec retains ownership of the color table. | 436 // Create the swizzler. SkPngCodec retains ownership of the color table. |
437 const SkPMColor* colors = get_color_ptr(fColorTable.get()); | 437 const SkPMColor* colors = get_color_ptr(fColorTable.get()); |
438 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo
, | 438 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo
, options)); |
439 options.fZeroInitialized)); | |
440 if (!fSwizzler) { | 439 if (!fSwizzler) { |
441 // FIXME: CreateSwizzler could fail for another reason. | 440 // FIXME: CreateSwizzler could fail for another reason. |
442 return kUnimplemented; | 441 return kUnimplemented; |
443 } | 442 } |
444 return kSuccess; | 443 return kSuccess; |
445 } | 444 } |
446 | 445 |
447 | 446 |
448 bool SkPngCodec::onRewind() { | 447 bool SkPngCodec::onRewind() { |
449 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header | 448 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header |
(...skipping 20 matching lines...) Expand all Loading... |
470 int* rowsDecoded) { | 469 int* rowsDecoded) { |
471 if (!conversion_possible(requestedInfo, this->getInfo())) { | 470 if (!conversion_possible(requestedInfo, this->getInfo())) { |
472 return kInvalidConversion; | 471 return kInvalidConversion; |
473 } | 472 } |
474 if (options.fSubset) { | 473 if (options.fSubset) { |
475 // Subsets are not supported. | 474 // Subsets are not supported. |
476 return kUnimplemented; | 475 return kUnimplemented; |
477 } | 476 } |
478 | 477 |
479 // Note that ctable and ctableCount may be modified if there is a color tabl
e | 478 // Note that ctable and ctableCount may be modified if there is a color tabl
e |
480 const Result result = this->initializeSwizzler(requestedInfo, options, | 479 const Result result = this->initializeSwizzler(requestedInfo, options, ctabl
e, ctableCount); |
481 ctable, ctableCount); | |
482 if (result != kSuccess) { | 480 if (result != kSuccess) { |
483 return result; | 481 return result; |
484 } | 482 } |
485 // FIXME: Could we use the return value of setjmp to specify the type of | 483 // FIXME: Could we use the return value of setjmp to specify the type of |
486 // error? | 484 // error? |
487 int row = 0; | 485 int row = 0; |
488 if (setjmp(png_jmpbuf(fPng_ptr))) { | 486 if (setjmp(png_jmpbuf(fPng_ptr))) { |
489 // Assume that any error that occurs while reading rows is caused by an
incomplete input. | 487 // Assume that any error that occurs while reading rows is caused by an
incomplete input. |
490 if (fNumberPasses > 1) { | 488 if (fNumberPasses > 1) { |
491 // FIXME (msarett): Handle incomplete interlaced pngs. | 489 // FIXME (msarett): Handle incomplete interlaced pngs. |
(...skipping 199 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) | 689 png_structp png_ptr, png_infop info_ptr, int bitDepth, int numberPas
ses) |
692 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, numberPasses) | 690 : INHERITED(srcInfo, stream, png_ptr, info_ptr, bitDepth, numberPasses) |
693 , fAlphaState(kUnknown_AlphaState) | 691 , fAlphaState(kUnknown_AlphaState) |
694 , fHeight(-1) | 692 , fHeight(-1) |
695 , fCanSkipRewind(false) | 693 , fCanSkipRewind(false) |
696 { | 694 { |
697 SkASSERT(numberPasses != 1); | 695 SkASSERT(numberPasses != 1); |
698 } | 696 } |
699 | 697 |
700 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, | 698 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti
ons, |
701 SkPMColor ctable[], int* ctableCount) override | 699 SkPMColor ctable[], int* ctableCount) override { |
702 { | |
703 if (!conversion_possible(dstInfo, this->getInfo())) { | 700 if (!conversion_possible(dstInfo, this->getInfo())) { |
704 return kInvalidConversion; | 701 return kInvalidConversion; |
705 } | 702 } |
706 | 703 |
707 const SkCodec::Result result = this->initializeSwizzler(dstInfo, options
, ctable, | 704 const Result result = this->initializeSwizzler(dstInfo, options, ctable, |
708 ctableCount); | 705 ctableCount); |
709 if (result != SkCodec::kSuccess) { | 706 if (result != kSuccess) { |
710 return result; | 707 return result; |
711 } | 708 } |
712 | 709 |
713 fAlphaState = kUnknown_AlphaState; | 710 fAlphaState = kUnknown_AlphaState; |
714 fHeight = dstInfo.height(); | 711 fHeight = dstInfo.height(); |
715 // FIXME: This need not be called on a second call to onStartScanlineDec
ode. | 712 // FIXME: This need not be called on a second call to onStartScanlineDec
ode. |
716 fSrcRowBytes = this->getInfo().width() * SkSwizzler::BytesPerPixel(this-
>srcConfig()); | 713 fSrcRowBytes = this->getInfo().width() * SkSwizzler::BytesPerPixel(this-
>srcConfig()); |
717 fGarbageRow.reset(fSrcRowBytes); | 714 fGarbageRow.reset(fSrcRowBytes); |
718 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); | 715 fGarbageRowPtr = static_cast<uint8_t*>(fGarbageRow.get()); |
719 fCanSkipRewind = true; | 716 fCanSkipRewind = true; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 | 836 |
840 if (1 == numberPasses) { | 837 if (1 == numberPasses) { |
841 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), png_p
tr, info_ptr, | 838 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), png_p
tr, info_ptr, |
842 bitDepth); | 839 bitDepth); |
843 } | 840 } |
844 | 841 |
845 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
png_ptr, | 842 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(),
png_ptr, |
846 info_ptr, bitDepth, numberPasses); | 843 info_ptr, bitDepth, numberPasses); |
847 } | 844 } |
848 | 845 |
OLD | NEW |