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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 223 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
224 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 224 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
225 | 225 |
226 src += offset; | 226 src += offset; |
227 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; | 227 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; |
228 INIT_RESULT_ALPHA; | 228 INIT_RESULT_ALPHA; |
229 // TODO (msarett): Should we skip the loop here and guess that the row is op
aque/not opaque? | 229 // TODO (msarett): Should we skip the loop here and guess that the row is op
aque/not opaque? |
230 // SkScaledBitmap sampler just guesses that it is opaque. T
his is dangerous | 230 // SkScaledBitmap sampler just guesses that it is opaque. T
his is dangerous |
231 // and probably wrong since gif and bmp (rarely) may have al
pha. | 231 // and probably wrong since gif and bmp (rarely) may have al
pha. |
232 if (1 == deltaSrc) { | 232 if (1 == deltaSrc) { |
233 // A non-zero offset is only used when sampling, meaning that deltaSrc w
ill be | |
234 // greater than 1. The below loop relies on the fact that src remains un
changed. | |
235 SkASSERT(0 == offset); | |
236 memcpy(dst, src, dstWidth); | 233 memcpy(dst, src, dstWidth); |
237 for (int x = 0; x < dstWidth; x++) { | 234 for (int x = 0; x < dstWidth; x++) { |
238 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); | 235 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); |
239 } | 236 } |
240 } else { | 237 } else { |
241 for (int x = 0; x < dstWidth; x++) { | 238 for (int x = 0; x < dstWidth; x++) { |
242 dst[x] = *src; | 239 dst[x] = *src; |
243 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); | 240 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); |
244 src += deltaSrc; | 241 src += deltaSrc; |
245 } | 242 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 } | 504 } |
508 src += deltaSrc; | 505 src += deltaSrc; |
509 alphaMask &= alpha; | 506 alphaMask &= alpha; |
510 } | 507 } |
511 return alphaMask != 0xFF; | 508 return alphaMask != 0xFF; |
512 } | 509 } |
513 */ | 510 */ |
514 | 511 |
515 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, | 512 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, |
516 const SkPMColor* ctable, | 513 const SkPMColor* ctable, |
517 const SkImageInfo& dstInfo, | 514 const SkImageInfo& dstInfo, |
518 SkCodec::ZeroInitialized zeroInit) { | 515 const SkCodec::Options& options) { |
519 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { | 516 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { |
520 return nullptr; | 517 return nullptr; |
521 } | 518 } |
522 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) | 519 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) |
523 && nullptr == ctable) { | 520 && nullptr == ctable) { |
524 return nullptr; | 521 return nullptr; |
525 } | 522 } |
526 RowProc proc = nullptr; | 523 RowProc proc = nullptr; |
527 | 524 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
528 switch (sc) { | 525 switch (sc) { |
529 case kBit: | 526 case kBit: |
530 switch (dstInfo.colorType()) { | 527 switch (dstInfo.colorType()) { |
531 case kN32_SkColorType: | 528 case kN32_SkColorType: |
532 proc = &swizzle_bit_to_n32; | 529 proc = &swizzle_bit_to_n32; |
533 break; | 530 break; |
534 case kIndex_8_SkColorType: | 531 case kIndex_8_SkColorType: |
535 proc = &swizzle_bit_to_index; | 532 proc = &swizzle_bit_to_index; |
536 break; | 533 break; |
537 case kRGB_565_SkColorType: | 534 case kRGB_565_SkColorType: |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 default: | 673 default: |
677 break; | 674 break; |
678 } | 675 } |
679 default: | 676 default: |
680 break; | 677 break; |
681 } | 678 } |
682 if (nullptr == proc) { | 679 if (nullptr == proc) { |
683 return nullptr; | 680 return nullptr; |
684 } | 681 } |
685 | 682 |
686 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits | 683 // Store bpp in bytes if it is an even multiple, otherwise use bits |
687 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix
el(sc); | 684 int bpp = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc
); |
| 685 |
| 686 int srcOffset = 0; |
| 687 int srcWidth = dstInfo.width(); |
| 688 if (options.fSubset) { |
| 689 srcOffset = options.fSubset->left(); |
| 690 srcWidth = options.fSubset->width(); |
| 691 } |
688 | 692 |
689 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo.width()); | 693 return new SkSwizzler(proc, ctable, srcOffset, srcWidth, bpp); |
690 } | 694 } |
691 | 695 |
692 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, | 696 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int
srcWidth, int bpp) |
693 int deltaSrc, int srcWidth) | |
694 : fRowProc(proc) | 697 : fRowProc(proc) |
695 , fColorTable(ctable) | 698 , fColorTable(ctable) |
696 , fDeltaSrc(deltaSrc) | 699 , fSrcOffset(srcOffset) |
| 700 , fX0(srcOffset) |
697 , fSrcWidth(srcWidth) | 701 , fSrcWidth(srcWidth) |
698 , fDstWidth(srcWidth) | 702 , fDstWidth(srcWidth) |
| 703 , fBPP(bpp) |
699 , fSampleX(1) | 704 , fSampleX(1) |
700 , fX0(0) | |
701 {} | 705 {} |
702 | 706 |
703 int SkSwizzler::onSetSampleX(int sampleX) { | 707 int SkSwizzler::onSetSampleX(int sampleX) { |
704 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be | 708 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be |
705 // way to report failure? | 709 // way to report failure? |
706 fSampleX = sampleX; | 710 fSampleX = sampleX; |
707 fX0 = get_start_coord(sampleX); | 711 fX0 = get_start_coord(sampleX) + fSrcOffset; |
708 fDstWidth = get_scaled_dimension(fSrcWidth, sampleX); | 712 fDstWidth = get_scaled_dimension(fSrcWidth, sampleX); |
709 | 713 |
710 // check that fX0 is less than original width | 714 // check that fX0 is less than original width |
711 SkASSERT(fX0 >= 0 && fX0 < fSrcWidth); | 715 SkASSERT(fX0 >= 0 && fX0 < fSrcWidth); |
712 return fDstWidth; | 716 return fDstWidth; |
713 } | 717 } |
714 | 718 |
715 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { | 719 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC
T src) { |
716 SkASSERT(nullptr != dst && nullptr != src); | 720 SkASSERT(nullptr != dst && nullptr != src); |
717 return fRowProc(dst, src, fDstWidth, fDeltaSrc, fSampleX * fDeltaSrc, | 721 return fRowProc(dst, src, fDstWidth, fBPP, fSampleX * fBPP, fX0 * fBPP, fCol
orTable); |
718 fX0 * fDeltaSrc, fColorTable); | |
719 } | 722 } |
OLD | NEW |