| 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 const SkPMColor ctable[]) { | 302 const SkPMColor ctable[]) { |
| 303 | 303 |
| 304 src += offset; | 304 src += offset; |
| 305 SkPMColor* dst32 = (SkPMColor*) dst; | 305 SkPMColor* dst32 = (SkPMColor*) dst; |
| 306 for (int x = 0; x < width; x++) { | 306 for (int x = 0; x < width; x++) { |
| 307 dst32[x] = SkPackARGB32NoCheck(src[1], src[0], src[0], src[0]); | 307 dst32[x] = SkPackARGB32NoCheck(src[1], src[0], src[0], src[0]); |
| 308 src += deltaSrc; | 308 src += deltaSrc; |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 | 311 |
| 312 static void fast_swizzle_grayalpha_to_n32_unpremul( |
| 313 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 314 const SkPMColor ctable[]) { |
| 315 |
| 316 // This function must not be called if we are sampling. If we are not |
| 317 // sampling, deltaSrc should equal bpp. |
| 318 SkASSERT(deltaSrc == bpp); |
| 319 |
| 320 // Note that there is no need to distinguish between RGB and BGR. |
| 321 // Each color channel will get the same value. |
| 322 SkOpts::grayA_to_RGBA((uint32_t*) dst, src + offset, width); |
| 323 } |
| 324 |
| 312 static void swizzle_grayalpha_to_n32_premul( | 325 static void swizzle_grayalpha_to_n32_premul( |
| 313 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 326 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 314 const SkPMColor ctable[]) { | 327 const SkPMColor ctable[]) { |
| 315 | 328 |
| 316 src += offset; | 329 src += offset; |
| 317 SkPMColor* dst32 = (SkPMColor*) dst; | 330 SkPMColor* dst32 = (SkPMColor*) dst; |
| 318 for (int x = 0; x < width; x++) { | 331 for (int x = 0; x < width; x++) { |
| 319 uint8_t pmgray = SkMulDiv255Round(src[1], src[0]); | 332 uint8_t pmgray = SkMulDiv255Round(src[1], src[0]); |
| 320 dst32[x] = SkPackARGB32NoCheck(src[1], pmgray, pmgray, pmgray); | 333 dst32[x] = SkPackARGB32NoCheck(src[1], pmgray, pmgray, pmgray); |
| 321 src += deltaSrc; | 334 src += deltaSrc; |
| 322 } | 335 } |
| 323 } | 336 } |
| 324 | 337 |
| 338 static void fast_swizzle_grayalpha_to_n32_premul( |
| 339 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 340 const SkPMColor ctable[]) { |
| 341 |
| 342 // This function must not be called if we are sampling. If we are not |
| 343 // sampling, deltaSrc should equal bpp. |
| 344 SkASSERT(deltaSrc == bpp); |
| 345 |
| 346 // Note that there is no need to distinguish between rgb and bgr. |
| 347 // Each color channel will get the same value. |
| 348 SkOpts::grayA_to_rgbA((uint32_t*) dst, src + offset, width); |
| 349 } |
| 350 |
| 325 // kBGRX | 351 // kBGRX |
| 326 | 352 |
| 327 static void swizzle_bgrx_to_n32( | 353 static void swizzle_bgrx_to_n32( |
| 328 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 354 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 329 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 355 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 330 | 356 |
| 331 src += offset; | 357 src += offset; |
| 332 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 358 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 333 for (int x = 0; x < dstWidth; x++) { | 359 for (int x = 0; x < dstWidth; x++) { |
| 334 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 360 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 break; | 737 break; |
| 712 } | 738 } |
| 713 break; | 739 break; |
| 714 case kGrayAlpha: | 740 case kGrayAlpha: |
| 715 switch (dstInfo.colorType()) { | 741 switch (dstInfo.colorType()) { |
| 716 case kN32_SkColorType: | 742 case kN32_SkColorType: |
| 717 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 743 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 718 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 744 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 719 proc = &SkipLeadingGrayAlphaZerosThen | 745 proc = &SkipLeadingGrayAlphaZerosThen |
| 720 <swizzle_grayalpha_to_n32_unpremul>; | 746 <swizzle_grayalpha_to_n32_unpremul>; |
| 747 fastProc = &SkipLeadingGrayAlphaZerosThen |
| 748 <fast_swizzle_grayalpha_to_n32_unpremul>; |
| 721 } else { | 749 } else { |
| 722 proc = &swizzle_grayalpha_to_n32_unpremul; | 750 proc = &swizzle_grayalpha_to_n32_unpremul; |
| 751 fastProc = &fast_swizzle_grayalpha_to_n32_unpremul; |
| 723 } | 752 } |
| 724 } else { | 753 } else { |
| 725 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 754 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 726 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal
pha_to_n32_premul>; | 755 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal
pha_to_n32_premul>; |
| 756 fastProc = &SkipLeadingGrayAlphaZerosThen |
| 757 <fast_swizzle_grayalpha_to_n32_premul>; |
| 727 } else { | 758 } else { |
| 728 proc = &swizzle_grayalpha_to_n32_premul; | 759 proc = &swizzle_grayalpha_to_n32_premul; |
| 760 fastProc = &fast_swizzle_grayalpha_to_n32_premul; |
| 729 } | 761 } |
| 730 } | 762 } |
| 731 break; | 763 break; |
| 732 default: | 764 default: |
| 733 break; | 765 break; |
| 734 } | 766 } |
| 735 break; | 767 break; |
| 736 case kBGR: | 768 case kBGR: |
| 737 case kBGRX: | 769 case kBGRX: |
| 738 switch (dstInfo.colorType()) { | 770 switch (dstInfo.colorType()) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 } | 928 } |
| 897 | 929 |
| 898 return fAllocatedWidth; | 930 return fAllocatedWidth; |
| 899 } | 931 } |
| 900 | 932 |
| 901 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 933 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 902 SkASSERT(nullptr != dst && nullptr != src); | 934 SkASSERT(nullptr != dst && nullptr != src); |
| 903 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, | 935 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, |
| 904 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 936 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 905 } | 937 } |
| OLD | NEW |