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 "SkOpts.h" | 10 #include "SkOpts.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 288 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
289 | 289 |
290 src += offset; | 290 src += offset; |
291 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 291 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
292 for (int x = 0; x < dstWidth; x++) { | 292 for (int x = 0; x < dstWidth; x++) { |
293 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); | 293 dst[x] = SkPack888ToRGB16(src[0], src[0], src[0]); |
294 src += deltaSrc; | 294 src += deltaSrc; |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 // kGrayAlpha | |
299 | |
300 static void swizzle_grayalpha_to_n32_unpremul( | |
301 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | |
302 const SkPMColor ctable[]) { | |
303 | |
304 src += offset; | |
305 SkPMColor* dst32 = (SkPMColor*) dst; | |
306 for (int x = 0; x < width; x++) { | |
307 dst32[x] = SkPackARGB32NoCheck(src[1], src[0], src[0], src[0]); | |
308 src += deltaSrc; | |
309 } | |
310 } | |
311 | |
312 static void swizzle_grayalpha_to_n32_premul( | |
313 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, | |
314 const SkPMColor ctable[]) { | |
315 | |
316 src += offset; | |
317 SkPMColor* dst32 = (SkPMColor*) dst; | |
318 for (int x = 0; x < width; x++) { | |
319 uint8_t pmgray = SkMulDiv255Round(src[1], src[0]); | |
320 dst32[x] = SkPackARGB32NoCheck(src[1], pmgray, pmgray, pmgray); | |
321 src += deltaSrc; | |
322 } | |
323 } | |
324 | |
298 // kBGRX | 325 // kBGRX |
299 | 326 |
300 static void swizzle_bgrx_to_n32( | 327 static void swizzle_bgrx_to_n32( |
301 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 328 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
302 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 329 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
303 | 330 |
304 src += offset; | 331 src += offset; |
305 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 332 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
306 for (int x = 0; x < dstWidth; x++) { | 333 for (int x = 0; x < dstWidth; x++) { |
307 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 334 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 const uint8_t r = SkMulDiv255Round(src[0], src[3]); | 576 const uint8_t r = SkMulDiv255Round(src[0], src[3]); |
550 const uint8_t g = SkMulDiv255Round(src[1], src[3]); | 577 const uint8_t g = SkMulDiv255Round(src[1], src[3]); |
551 const uint8_t b = SkMulDiv255Round(src[2], src[3]); | 578 const uint8_t b = SkMulDiv255Round(src[2], src[3]); |
552 | 579 |
553 dst[x] = SkPack888ToRGB16(r, g, b); | 580 dst[x] = SkPack888ToRGB16(r, g, b); |
554 src += deltaSrc; | 581 src += deltaSrc; |
555 } | 582 } |
556 } | 583 } |
557 | 584 |
558 template <SkSwizzler::RowProc proc> | 585 template <SkSwizzler::RowProc proc> |
586 void SkSwizzler::SkipLeadingGrayAlphaZerosThen( | |
587 void* dst, const uint8_t* src, int width, | |
588 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | |
589 SkASSERT(!ctable); | |
590 | |
591 const uint16_t* src16 = (const uint16_t*) (src + offset); | |
592 uint32_t* dst32 = (uint32_t*) dst; | |
593 | |
594 // This may miss opportunities to skip when the output is premultiplied, | |
595 // e.g. for a src pixel 0x00FF which is not zero but becomes zero after prem ultiplication. | |
596 while (width > 0 && *src16 == 0x0000) { | |
scroggo
2016/02/03 16:11:33
Should this have two exit conditions?
- width ==
msarett
2016/02/03 17:21:13
I believe it would be the same. I just checked th
| |
597 width--; | |
598 dst32++; | |
599 src16 += deltaSrc / 2; | |
600 } | |
601 proc(dst32, (const uint8_t*)src16, width, bpp, deltaSrc, 0, ctable); | |
602 } | |
603 | |
604 template <SkSwizzler::RowProc proc> | |
559 void SkSwizzler::SkipLeading8888ZerosThen( | 605 void SkSwizzler::SkipLeading8888ZerosThen( |
560 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 606 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
561 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 607 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
562 SkASSERT(!ctable); | 608 SkASSERT(!ctable); |
563 | 609 |
564 auto src32 = (const uint32_t*)(src+offset); | 610 auto src32 = (const uint32_t*)(src+offset); |
565 auto dst32 = (uint32_t*)dstRow; | 611 auto dst32 = (uint32_t*)dstRow; |
566 | 612 |
567 // This may miss opportunities to skip when the output is premultiplied, | 613 // This may miss opportunities to skip when the output is premultiplied, |
568 // e.g. for a src pixel 0x00FFFFFF which is not zero but becomes zero after premultiplication. | 614 // e.g. for a src pixel 0x00FFFFFF which is not zero but becomes zero after premultiplication. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 proc = &sample1; | 704 proc = &sample1; |
659 fastProc = © | 705 fastProc = © |
660 break; | 706 break; |
661 case kRGB_565_SkColorType: | 707 case kRGB_565_SkColorType: |
662 proc = &swizzle_gray_to_565; | 708 proc = &swizzle_gray_to_565; |
663 break; | 709 break; |
664 default: | 710 default: |
665 break; | 711 break; |
666 } | 712 } |
667 break; | 713 break; |
714 case kGrayAlpha: | |
715 switch (dstInfo.colorType()) { | |
716 case kN32_SkColorType: | |
717 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | |
718 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | |
719 proc = &SkipLeadingGrayAlphaZerosThen | |
720 <swizzle_grayalpha_to_n32_unpremul>; | |
721 } else { | |
722 proc = &swizzle_grayalpha_to_n32_unpremul; | |
723 } | |
724 } else { | |
725 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | |
726 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal pha_to_n32_premul>; | |
727 } else { | |
728 proc = &swizzle_grayalpha_to_n32_premul; | |
729 } | |
730 } | |
731 break; | |
732 default: | |
733 break; | |
734 } | |
735 break; | |
668 case kBGR: | 736 case kBGR: |
669 case kBGRX: | 737 case kBGRX: |
670 switch (dstInfo.colorType()) { | 738 switch (dstInfo.colorType()) { |
671 case kN32_SkColorType: | 739 case kN32_SkColorType: |
672 proc = &swizzle_bgrx_to_n32; | 740 proc = &swizzle_bgrx_to_n32; |
673 break; | 741 break; |
674 case kRGB_565_SkColorType: | 742 case kRGB_565_SkColorType: |
675 proc = &swizzle_bgrx_to_565; | 743 proc = &swizzle_bgrx_to_565; |
676 break; | 744 break; |
677 default: | 745 default: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 } | 896 } |
829 | 897 |
830 return fAllocatedWidth; | 898 return fAllocatedWidth; |
831 } | 899 } |
832 | 900 |
833 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 901 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
834 SkASSERT(nullptr != dst && nullptr != src); | 902 SkASSERT(nullptr != dst && nullptr != src); |
835 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, | 903 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, |
836 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 904 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
837 } | 905 } |
OLD | NEW |