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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 case kN32_SkColorType: | 422 case kN32_SkColorType: |
423 return true; | 423 return true; |
424 default: | 424 default: |
425 return dst.colorType() == src.colorType(); | 425 return dst.colorType() == src.colorType(); |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, | 429 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, |
430 void* dst, size_t rowBytes, | 430 void* dst, size_t rowBytes, |
431 const Options& options, | 431 const Options& options, |
432 SkPMColor ctable[], | |
432 int* ctableCount) { | 433 int* ctableCount) { |
433 // FIXME: Could we use the return value of setjmp to specify the type of | 434 // FIXME: Could we use the return value of setjmp to specify the type of |
434 // error? | 435 // error? |
435 if (setjmp(png_jmpbuf(fPng_ptr))) { | 436 if (setjmp(png_jmpbuf(fPng_ptr))) { |
436 SkCodecPrintf("setjmp long jump!\n"); | 437 SkCodecPrintf("setjmp long jump!\n"); |
437 return kInvalidInput; | 438 return kInvalidInput; |
438 } | 439 } |
439 | 440 |
440 // FIXME: We already retrieved this information. Store it in SkPngCodec? | 441 // FIXME: We already retrieved this information. Store it in SkPngCodec? |
441 png_uint_32 origWidth, origHeight; | 442 png_uint_32 origWidth, origHeight; |
(...skipping 15 matching lines...) Expand all Loading... | |
457 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) { | 458 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) { |
458 // Note: we check the destination, since otherwise we would have | 459 // Note: we check the destination, since otherwise we would have |
459 // told png to upscale. | 460 // told png to upscale. |
460 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType); | 461 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType); |
461 fSrcConfig = SkSwizzler::kGray; | 462 fSrcConfig = SkSwizzler::kGray; |
462 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { | 463 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { |
463 fSrcConfig = SkSwizzler::kRGBX; | 464 fSrcConfig = SkSwizzler::kRGBX; |
464 } else { | 465 } else { |
465 fSrcConfig = SkSwizzler::kRGBA; | 466 fSrcConfig = SkSwizzler::kRGBA; |
466 } | 467 } |
468 | |
469 // Copy the color table to the client if they request kIndex8 mode | |
467 const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL; | 470 const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL; |
471 if (kIndex_8_SkColorType == requestedInfo.colorType()) { | |
scroggo
2015/04/21 21:43:05
I think these same 5 lines are copied elsewhere. F
msarett
2015/04/22 14:32:52
Done.
| |
472 SkASSERT(NULL != ctable); | |
473 SkASSERT(NULL != ctableCount); | |
474 SkASSERT(NULL != fColorTable); | |
475 sk_memcpy32(ctable, colors, *ctableCount); | |
476 } | |
477 | |
478 // Create the swizzler, SkPngCodec retains ownership of the color table | |
scroggo
2015/04/21 21:43:05
nit: this seems like it should be two sentences.
msarett
2015/04/22 14:32:52
Done.
| |
468 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo , | 479 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo , |
469 dst, rowBytes, options.fZeroInitialized)); | 480 dst, rowBytes, options.fZeroInitialized)); |
470 if (!fSwizzler) { | 481 if (!fSwizzler) { |
471 // FIXME: CreateSwizzler could fail for another reason. | 482 // FIXME: CreateSwizzler could fail for another reason. |
472 return kUnimplemented; | 483 return kUnimplemented; |
473 } | 484 } |
474 | 485 |
475 // FIXME: Here is where we should likely insert some of the modifications | 486 // FIXME: Here is where we should likely insert some of the modifications |
476 // made in the factory. | 487 // made in the factory. |
477 png_read_update_info(fPng_ptr, fInfo_ptr); | 488 png_read_update_info(fPng_ptr, fInfo_ptr); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 if (!this->handleRewind()) { | 524 if (!this->handleRewind()) { |
514 return kCouldNotRewind; | 525 return kCouldNotRewind; |
515 } | 526 } |
516 if (requestedInfo.dimensions() != this->getInfo().dimensions()) { | 527 if (requestedInfo.dimensions() != this->getInfo().dimensions()) { |
517 return kInvalidScale; | 528 return kInvalidScale; |
518 } | 529 } |
519 if (!conversion_possible(requestedInfo, this->getInfo())) { | 530 if (!conversion_possible(requestedInfo, this->getInfo())) { |
520 return kInvalidConversion; | 531 return kInvalidConversion; |
521 } | 532 } |
522 | 533 |
523 // Note that ctableCount will be modified if there is a color table | 534 // Note that ctable and ctableCount may be modified if there is a color tabl e |
524 const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes, | 535 const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes, |
525 options, ctableCount); | 536 options, ctable, ctableCount) ; |
526 | |
527 // Copy the color table to the client if necessary | |
528 if (kIndex_8_SkColorType == requestedInfo.colorType()) { | |
529 SkASSERT(NULL != ctable); | |
530 SkASSERT(NULL != ctableCount); | |
531 SkASSERT(NULL != fColorTable.get()); | |
532 sk_memcpy32(ctable, fColorTable->readColors(), *ctableCount); | |
533 } | |
534 | 537 |
535 if (result != kSuccess) { | 538 if (result != kSuccess) { |
536 return result; | 539 return result; |
537 } | 540 } |
538 | 541 |
539 // FIXME: Could we use the return value of setjmp to specify the type of | 542 // FIXME: Could we use the return value of setjmp to specify the type of |
540 // error? | 543 // error? |
541 if (setjmp(png_jmpbuf(fPng_ptr))) { | 544 if (setjmp(png_jmpbuf(fPng_ptr))) { |
542 SkCodecPrintf("setjmp long jump!\n"); | 545 SkCodecPrintf("setjmp long jump!\n"); |
543 return kInvalidInput; | 546 return kInvalidInput; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 | 644 |
642 private: | 645 private: |
643 SkPngCodec* fCodec; // Unowned. | 646 SkPngCodec* fCodec; // Unowned. |
644 bool fHasAlpha; | 647 bool fHasAlpha; |
645 SkAutoMalloc fStorage; | 648 SkAutoMalloc fStorage; |
646 uint8_t* fSrcRow; | 649 uint8_t* fSrcRow; |
647 | 650 |
648 typedef SkScanlineDecoder INHERITED; | 651 typedef SkScanlineDecoder INHERITED; |
649 }; | 652 }; |
650 | 653 |
651 SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo) { | 654 SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, |
655 const Options& options, SkPMColor ctable[], int* ctableCount) { | |
652 if (!this->handleRewind()) { | 656 if (!this->handleRewind()) { |
653 return NULL; | 657 return NULL; |
654 } | 658 } |
655 | 659 |
656 // Check to see if scaling was requested. | 660 // Check to see if scaling was requested. |
657 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 661 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
658 return NULL; | 662 return NULL; |
659 } | 663 } |
660 | 664 |
661 if (!conversion_possible(dstInfo, this->getInfo())) { | 665 if (!conversion_possible(dstInfo, this->getInfo())) { |
662 SkCodecPrintf("no conversion possible\n"); | 666 SkCodecPrintf("no conversion possible\n"); |
663 return NULL; | 667 return NULL; |
664 } | 668 } |
665 | 669 |
666 // Note: We set dst to NULL since we do not know it yet. rowBytes is not nee ded, | 670 // Note: We set dst to NULL since we do not know it yet. rowBytes is not nee ded, |
667 // since we'll be manually updating the dstRow, but the SkSwizzler requires it to | 671 // since we'll be manually updating the dstRow, but the SkSwizzler requires it to |
668 // be at least dstInfo.minRowBytes. | 672 // be at least dstInfo.minRowBytes. |
669 Options opts; | 673 if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable, |
670 // FIXME: Pass this in to getScanlineDecoder? | 674 ctableCount) != kSuccess) { |
671 opts.fZeroInitialized = kNo_ZeroInitialized; | |
672 // FIXME: onGetScanlineDecoder does not currently have a way to get color ta ble information | |
673 // for a kIndex8 decoder. | |
674 if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), opts, NUL L) != kSuccess) { | |
675 SkCodecPrintf("failed to initialize the swizzler.\n"); | 675 SkCodecPrintf("failed to initialize the swizzler.\n"); |
676 return NULL; | 676 return NULL; |
677 } | 677 } |
678 | 678 |
679 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); | 679 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); |
680 if (fNumberPasses > 1) { | 680 if (fNumberPasses > 1) { |
681 // We cannot efficiently do scanline decoding. | 681 // We cannot efficiently do scanline decoding. |
682 return NULL; | 682 return NULL; |
683 } | 683 } |
684 | 684 |
685 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); | 685 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); |
686 } | 686 } |
687 | 687 |
OLD | NEW |