Chromium Code Reviews| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 224 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 225 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 225 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 226 | 226 |
| 227 src += offset; | 227 src += offset; |
| 228 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 228 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
| 229 INIT_RESULT_ALPHA; | 229 INIT_RESULT_ALPHA; |
| 230 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? | 230 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? |
| 231 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous | 231 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous |
| 232 // and probably wrong since gif and bmp (rarely) may have al pha. | 232 // and probably wrong since gif and bmp (rarely) may have al pha. |
| 233 if (1 == deltaSrc) { | 233 if (1 == deltaSrc) { |
| 234 // A non-zero offset is only used when sampling, meaning that deltaSrc w ill be | |
| 235 // greater than 1. The below loop relies on the fact that src remains un changed. | |
|
scroggo
2015/10/02 18:27:03
Does the below loop not need to be updated to take
msarett
2015/10/06 23:01:27
Don't think so...
scroggo
2015/10/07 17:49:39
Can you help me understand why that is? I thought
| |
| 236 SkASSERT(0 == offset); | |
| 237 memcpy(dst, src, dstWidth); | 234 memcpy(dst, src, dstWidth); |
| 238 for (int x = 0; x < dstWidth; x++) { | 235 for (int x = 0; x < dstWidth; x++) { |
| 239 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 236 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
| 240 } | 237 } |
| 241 } else { | 238 } else { |
| 242 for (int x = 0; x < dstWidth; x++) { | 239 for (int x = 0; x < dstWidth; x++) { |
| 243 dst[x] = *src; | 240 dst[x] = *src; |
| 244 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); | 241 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); |
| 245 src += deltaSrc; | 242 src += deltaSrc; |
| 246 } | 243 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 alphaMask &= alpha; | 507 alphaMask &= alpha; |
| 511 } | 508 } |
| 512 return alphaMask != 0xFF; | 509 return alphaMask != 0xFF; |
| 513 } | 510 } |
| 514 */ | 511 */ |
| 515 | 512 |
| 516 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 513 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
| 517 const SkPMColor* ctable, | 514 const SkPMColor* ctable, |
| 518 const SkImageInfo& dstInfo, | 515 const SkImageInfo& dstInfo, |
| 519 SkCodec::ZeroInitialized zeroInit, | 516 SkCodec::ZeroInitialized zeroInit, |
| 520 const SkImageInfo& srcInfo) { | 517 const SkImageInfo& srcInfo, |
| 518 int subsetLeft, int subsetWidth) { | |
| 521 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 519 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
| 522 return nullptr; | 520 return nullptr; |
| 523 } | 521 } |
| 524 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 522 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
| 525 && nullptr == ctable) { | 523 && nullptr == ctable) { |
| 526 return nullptr; | 524 return nullptr; |
| 527 } | 525 } |
| 528 RowProc proc = nullptr; | 526 RowProc proc = nullptr; |
| 529 | 527 |
| 530 switch (sc) { | 528 switch (sc) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 default: | 676 default: |
| 679 break; | 677 break; |
| 680 } | 678 } |
| 681 default: | 679 default: |
| 682 break; | 680 break; |
| 683 } | 681 } |
| 684 if (nullptr == proc) { | 682 if (nullptr == proc) { |
| 685 return nullptr; | 683 return nullptr; |
| 686 } | 684 } |
| 687 | 685 |
| 688 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits | 686 // Store bpp in bytes if it is an even multiple, otherwise use bits |
| 689 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc); | 687 int bpp = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc ); |
| 690 | 688 |
| 691 // get sampleX based on srcInfo and dstInfo dimensions | 689 // get sampleX based on srcInfo and dstInfo dimensions |
| 692 int sampleX; | 690 int sampleX; |
| 693 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, nullptr); | 691 SkScaledCodec::ComputeSampleSize(dstInfo.dimensions(), srcInfo.dimensions(), &sampleX, nullptr); |
| 694 | 692 int x0 = get_start_coord(sampleX) + subsetLeft; |
| 695 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX); | 693 |
| 694 return new SkSwizzler(proc, ctable, x0 * bpp, subsetWidth, bpp, sampleX * bp p); | |
| 696 } | 695 } |
| 697 | 696 |
| 698 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 697 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, |
| 699 int deltaSrc, const SkImageInfo& info, int sampleX) | 698 int left, int width, int bpp, int deltaSrc) |
| 700 : fRowProc(proc) | 699 : fRowProc(proc) |
| 701 , fColorTable(ctable) | 700 , fColorTable(ctable) |
| 701 , fLeft(left) | |
| 702 , fWidth(width) | |
| 703 , fBPP(bpp) | |
| 702 , fDeltaSrc(deltaSrc) | 704 , fDeltaSrc(deltaSrc) |
| 703 , fDstInfo(info) | 705 {} |
| 704 , fSampleX(sampleX) | |
| 705 , fX0(get_start_coord(sampleX)) | |
| 706 { | |
| 707 // check that fX0 is less than original width | |
| 708 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); | |
| 709 } | |
| 710 | 706 |
| 711 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { | 707 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { |
| 712 SkASSERT(nullptr != dst && nullptr != src); | 708 SkASSERT(nullptr != dst && nullptr != src); |
| 713 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fSampleX * fDeltaSrc, | 709 return fRowProc(dst, src, fWidth, fBPP, fDeltaSrc, fLeft, fColorTable); |
| 714 fX0 * fDeltaSrc, fColorTable); | |
| 715 } | 710 } |
| 716 | 711 |
| 717 void SkSwizzler::Fill(void* fillDst, const SkImageInfo& fillInfo, size_t rowByte s, | 712 void SkSwizzler::Fill(void* fillDst, const SkImageInfo& fillInfo, size_t rowByte s, |
| 718 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) { | 713 uint32_t colorOrIndex, SkCodec::ZeroInitialized zeroInit) { |
| 719 SkASSERT(fillDst != nullptr); | 714 SkASSERT(fillDst != nullptr); |
| 720 | 715 |
| 721 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. | 716 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. |
| 722 const size_t bytesToFill = fillInfo.getSafeSize(rowBytes); | 717 const size_t bytesToFill = fillInfo.getSafeSize(rowBytes); |
| 723 | 718 |
| 724 // Use the proper memset routine to fill the remaining bytes | 719 // Use the proper memset routine to fill the remaining bytes |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 } | 790 } |
| 796 | 791 |
| 797 memset(fillDst, (uint8_t) colorOrIndex, bytesToFill); | 792 memset(fillDst, (uint8_t) colorOrIndex, bytesToFill); |
| 798 break; | 793 break; |
| 799 default: | 794 default: |
| 800 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); | 795 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| 801 SkASSERT(false); | 796 SkASSERT(false); |
| 802 break; | 797 break; |
| 803 } | 798 } |
| 804 } | 799 } |
| OLD | NEW |