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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkScaledCodec.h" | 10 #include "SkScaledCodec.h" |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 return alphaMask != 0xFF; | 510 return alphaMask != 0xFF; |
511 } | 511 } |
512 */ | 512 */ |
513 | 513 |
514 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 514 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
515 const SkPMColor* ctable, | 515 const SkPMColor* ctable, |
516 const SkImageInfo& dstInfo, | 516 const SkImageInfo& dstInfo, |
517 SkCodec::ZeroInitialized zeroInit, | 517 SkCodec::ZeroInitialized zeroInit, |
518 const SkImageInfo& srcInfo) { | 518 const SkImageInfo& srcInfo) { |
519 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 519 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
520 return NULL; | 520 return nullptr; |
521 } | 521 } |
522 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 522 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
523 && NULL == ctable) { | 523 && nullptr == ctable) { |
524 return NULL; | 524 return nullptr; |
525 } | 525 } |
526 RowProc proc = NULL; | 526 RowProc proc = nullptr; |
527 | 527 |
528 switch (sc) { | 528 switch (sc) { |
529 case kBit: | 529 case kBit: |
530 switch (dstInfo.colorType()) { | 530 switch (dstInfo.colorType()) { |
531 case kN32_SkColorType: | 531 case kN32_SkColorType: |
532 proc = &swizzle_bit_to_n32; | 532 proc = &swizzle_bit_to_n32; |
533 break; | 533 break; |
534 case kIndex_8_SkColorType: | 534 case kIndex_8_SkColorType: |
535 proc = &swizzle_bit_to_index; | 535 proc = &swizzle_bit_to_index; |
536 break; | 536 break; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 switch (dstInfo.colorType()) { | 672 switch (dstInfo.colorType()) { |
673 case kRGB_565_SkColorType: | 673 case kRGB_565_SkColorType: |
674 proc = &sample565; | 674 proc = &sample565; |
675 break; | 675 break; |
676 default: | 676 default: |
677 break; | 677 break; |
678 } | 678 } |
679 default: | 679 default: |
680 break; | 680 break; |
681 } | 681 } |
682 if (NULL == proc) { | 682 if (nullptr == proc) { |
683 return NULL; | 683 return nullptr; |
684 } | 684 } |
685 | 685 |
686 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits | 686 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits |
687 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix
el(sc); | 687 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix
el(sc); |
688 | 688 |
689 // get sampleX based on srcInfo and dstInfo dimensions | 689 // get sampleX based on srcInfo and dstInfo dimensions |
690 int sampleX; | 690 int sampleX; |
691 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, NULL); | 691 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, nullptr); |
692 | 692 |
693 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX); | 693 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX); |
694 } | 694 } |
695 | 695 |
696 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 696 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
697 int deltaSrc, const SkImageInfo& info, int sampleX) | 697 int deltaSrc, const SkImageInfo& info, int sampleX) |
698 : fRowProc(proc) | 698 : fRowProc(proc) |
699 , fColorTable(ctable) | 699 , fColorTable(ctable) |
700 , fDeltaSrc(deltaSrc) | 700 , fDeltaSrc(deltaSrc) |
701 , fDstInfo(info) | 701 , fDstInfo(info) |
702 , fSampleX(sampleX) | 702 , fSampleX(sampleX) |
703 , fX0(sampleX == 1 ? 0 : sampleX >> 1) | 703 , fX0(sampleX == 1 ? 0 : sampleX >> 1) |
704 { | 704 { |
705 // check that fX0 is less than original width | 705 // check that fX0 is less than original width |
706 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | 706 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); |
707 } | 707 } |
708 | 708 |
709 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { | 709 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { |
710 SkASSERT(NULL != dst && NULL != src); | 710 SkASSERT(nullptr != dst && nullptr != src); |
711 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel
taSrc, fColorTable); | 711 return fRowProc(dst, src, fDstInfo.width(), fSampleX * fDeltaSrc, fX0 * fDel
taSrc, fColorTable); |
712 } | 712 } |
713 | 713 |
714 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
owBytes, | 714 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR
owBytes, |
715 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { | 715 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable) { |
716 SkASSERT(dstStartRow != NULL); | 716 SkASSERT(dstStartRow != nullptr); |
717 SkASSERT(numRows <= (uint32_t) dstInfo.height()); | 717 SkASSERT(numRows <= (uint32_t) dstInfo.height()); |
718 | 718 |
719 // Calculate bytes to fill. We use getSafeSize since the last row may not b
e padded. | 719 // Calculate bytes to fill. We use getSafeSize since the last row may not b
e padded. |
720 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS
ize(dstRowBytes); | 720 const size_t bytesToFill = dstInfo.makeWH(dstInfo.width(), numRows).getSafeS
ize(dstRowBytes); |
721 | 721 |
722 // Use the proper memset routine to fill the remaining bytes | 722 // Use the proper memset routine to fill the remaining bytes |
723 switch(dstInfo.colorType()) { | 723 switch(dstInfo.colorType()) { |
724 case kN32_SkColorType: | 724 case kN32_SkColorType: |
725 // Assume input is an index if we have a color table | 725 // Assume input is an index if we have a color table |
726 uint32_t color; | 726 uint32_t color; |
727 if (NULL != colorTable) { | 727 if (nullptr != colorTable) { |
728 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); | 728 SkASSERT(colorOrIndex == (uint8_t) colorOrIndex); |
729 color = colorTable[colorOrIndex]; | 729 color = colorTable[colorOrIndex]; |
730 // Otherwise, assume the input is a color | 730 // Otherwise, assume the input is a color |
731 } else { | 731 } else { |
732 color = colorOrIndex; | 732 color = colorOrIndex; |
733 } | 733 } |
734 | 734 |
735 // We must fill row by row in the case of unaligned row bytes | 735 // We must fill row by row in the case of unaligned row bytes |
736 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) { | 736 if (SkIsAlign4((size_t) dstStartRow) && SkIsAlign4(dstRowBytes)) { |
737 sk_memset32((uint32_t*) dstStartRow, color, | 737 sk_memset32((uint32_t*) dstStartRow, color, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 // bits of SK_ColorBLACK are identical to the 565 representation | 770 // bits of SK_ColorBLACK are identical to the 565 representation |
771 // for black. | 771 // for black. |
772 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); | 772 memset(dstStartRow, (uint16_t) colorOrIndex, bytesToFill); |
773 break; | 773 break; |
774 default: | 774 default: |
775 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing
nothing.\n"); | 775 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing
nothing.\n"); |
776 SkASSERT(false); | 776 SkASSERT(false); |
777 break; | 777 break; |
778 } | 778 } |
779 } | 779 } |
OLD | NEW |