| 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 296         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 296         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 
| 297 | 297 | 
| 298     src += offset; | 298     src += offset; | 
| 299     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 299     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 
| 300     for (int x = 0; x < dstWidth; x++) { | 300     for (int x = 0; x < dstWidth; x++) { | 
| 301         dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 301         dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | 
| 302         src += deltaSrc; | 302         src += deltaSrc; | 
| 303     } | 303     } | 
| 304 } | 304 } | 
| 305 | 305 | 
|  | 306 static void fast_swizzle_bgrx_to_32( | 
|  | 307         void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
     set, | 
|  | 308         const SkPMColor ctable[]) { | 
|  | 309 | 
|  | 310     // This function must not be called if we are sampling.  If we are not | 
|  | 311     // sampling, deltaSrc should equal bpp. | 
|  | 312     SkASSERT(deltaSrc == bpp); | 
|  | 313 | 
|  | 314     // The default swizzle supports BGR->N32 and BGRX->N32.  This only | 
|  | 315     // supports BGRX->N32. | 
|  | 316     SkASSERT(4 == bpp); | 
|  | 317 | 
|  | 318     // These swizzles trust that the alpha value is already 0xFF. | 
|  | 319 #ifdef SK_PMCOLOR_IS_RGBA | 
|  | 320     SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
     ); | 
|  | 321 #else | 
|  | 322     memcpy(dst, src + offset, width * bpp); | 
|  | 323 #endif | 
|  | 324 } | 
|  | 325 | 
| 306 static void swizzle_bgrx_to_565( | 326 static void swizzle_bgrx_to_565( | 
| 307         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 327         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 
| 308         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 328         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 
| 309 | 329 | 
| 310     src += offset; | 330     src += offset; | 
| 311     uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 331     uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 
| 312     for (int x = 0; x < dstWidth; x++) { | 332     for (int x = 0; x < dstWidth; x++) { | 
| 313         dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 333         dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 
| 314         src += deltaSrc; | 334         src += deltaSrc; | 
| 315     } | 335     } | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 336 | 356 | 
| 337     src += offset; | 357     src += offset; | 
| 338     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 358     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 
| 339     for (int x = 0; x < dstWidth; x++) { | 359     for (int x = 0; x < dstWidth; x++) { | 
| 340         uint8_t alpha = src[3]; | 360         uint8_t alpha = src[3]; | 
| 341         dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | 361         dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | 
| 342         src += deltaSrc; | 362         src += deltaSrc; | 
| 343     } | 363     } | 
| 344 } | 364 } | 
| 345 | 365 | 
|  | 366 static void fast_swizzle_bgra_to_n32_premul( | 
|  | 367         void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
     set, | 
|  | 368         const SkPMColor ctable[]) { | 
|  | 369 | 
|  | 370     // This function must not be called if we are sampling.  If we are not | 
|  | 371     // sampling, deltaSrc should equal bpp. | 
|  | 372     SkASSERT(deltaSrc == bpp); | 
|  | 373 | 
|  | 374 #ifdef SK_PMCOLOR_IS_RGBA | 
|  | 375     SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset)
     , width); | 
|  | 376 #else | 
|  | 377     SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
     ); | 
|  | 378 #endif | 
|  | 379 } | 
|  | 380 | 
| 346 // kRGBX | 381 // kRGBX | 
|  | 382 | 
| 347 static void swizzle_rgbx_to_n32( | 383 static void swizzle_rgbx_to_n32( | 
| 348         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 384         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 
| 349         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 385         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 
| 350 | 386 | 
| 351     src += offset; | 387     src += offset; | 
| 352     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 388     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 
| 353     for (int x = 0; x < dstWidth; x++) { | 389     for (int x = 0; x < dstWidth; x++) { | 
| 354         dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 390         dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 
| 355         src += deltaSrc; | 391         src += deltaSrc; | 
| 356     } | 392     } | 
| 357 } | 393 } | 
| 358 | 394 | 
|  | 395 static void fast_swizzle_rgbx_to_32( | 
|  | 396         void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
     set, | 
|  | 397         const SkPMColor ctable[]) { | 
|  | 398 | 
|  | 399     // This function must not be called if we are sampling.  If we are not | 
|  | 400     // sampling, deltaSrc should equal bpp. | 
|  | 401     SkASSERT(deltaSrc == bpp); | 
|  | 402 | 
|  | 403     // The default swizzle supports RGB->N32 and RGBX->N32.  This only | 
|  | 404     // supports RGBX->N32. | 
|  | 405     SkASSERT(4 == bpp); | 
|  | 406 | 
|  | 407     // These swizzles trust that the alpha value is already 0xFF. | 
|  | 408 #ifdef SK_PMCOLOR_IS_RGBA | 
|  | 409     memcpy(dst, src + offset, width * bpp); | 
|  | 410 #else | 
|  | 411     SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
     ); | 
|  | 412 #endif | 
|  | 413 } | 
|  | 414 | 
| 359 static void swizzle_rgbx_to_565( | 415 static void swizzle_rgbx_to_565( | 
| 360        void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 416        void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 
| 361        int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 417        int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 
| 362 | 418 | 
| 363     src += offset; | 419     src += offset; | 
| 364     uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 420     uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 
| 365     for (int x = 0; x < dstWidth; x++) { | 421     for (int x = 0; x < dstWidth; x++) { | 
| 366         dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 422         dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 
| 367         src += deltaSrc; | 423         src += deltaSrc; | 
| 368     } | 424     } | 
| 369 } | 425 } | 
| 370 | 426 | 
| 371 // kRGBA | 427 // kRGBA | 
|  | 428 | 
| 372 static void swizzle_rgba_to_n32_premul( | 429 static void swizzle_rgba_to_n32_premul( | 
| 373         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 430         void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 
| 374         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 431         int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 
| 375 | 432 | 
| 376     src += offset; | 433     src += offset; | 
| 377     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 434     SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 
| 378     for (int x = 0; x < dstWidth; x++) { | 435     for (int x = 0; x < dstWidth; x++) { | 
| 379         unsigned alpha = src[3]; | 436         unsigned alpha = src[3]; | 
| 380         dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); | 437         dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); | 
| 381         src += deltaSrc; | 438         src += deltaSrc; | 
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 603                 case kRGB_565_SkColorType: | 660                 case kRGB_565_SkColorType: | 
| 604                     proc = &swizzle_bgrx_to_565; | 661                     proc = &swizzle_bgrx_to_565; | 
| 605                     break; | 662                     break; | 
| 606                 default: | 663                 default: | 
| 607                     break; | 664                     break; | 
| 608             } | 665             } | 
| 609             break; | 666             break; | 
| 610         case kBGRA: | 667         case kBGRA: | 
| 611             switch (dstInfo.colorType()) { | 668             switch (dstInfo.colorType()) { | 
| 612                 case kN32_SkColorType: | 669                 case kN32_SkColorType: | 
| 613                     switch (dstInfo.alphaType()) { | 670                     if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 
| 614                         case kUnpremul_SkAlphaType: | 671                         if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 
|  | 672                             proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
     _unpremul>; | 
|  | 673                             fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
     rx_to_32>; | 
|  | 674                         } else { | 
| 615                             proc = &swizzle_bgra_to_n32_unpremul; | 675                             proc = &swizzle_bgra_to_n32_unpremul; | 
| 616                             break; | 676                             fastProc = &fast_swizzle_bgrx_to_32; | 
| 617                         case kPremul_SkAlphaType: | 677                         } | 
|  | 678                     } else { | 
|  | 679                         if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 
|  | 680                             proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
     _premul>; | 
|  | 681                             fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
     ra_to_n32_premul>; | 
|  | 682                         } else { | 
| 618                             proc = &swizzle_bgra_to_n32_premul; | 683                             proc = &swizzle_bgra_to_n32_premul; | 
| 619                             break; | 684                             fastProc = &fast_swizzle_bgra_to_n32_premul; | 
| 620                         default: | 685                         } | 
| 621                             break; |  | 
| 622                     } | 686                     } | 
| 623                     break; | 687                     break; | 
| 624                 default: | 688                 default: | 
| 625                     break; | 689                     break; | 
| 626             } | 690             } | 
| 627             break; | 691             break; | 
| 628         case kRGBX: | 692         case kRGBX: | 
| 629             switch (dstInfo.colorType()) { | 693             switch (dstInfo.colorType()) { | 
| 630                 case kN32_SkColorType: | 694                 case kN32_SkColorType: | 
| 631                     proc = &swizzle_rgbx_to_n32; | 695                     proc = &swizzle_rgbx_to_n32; | 
|  | 696                     fastProc = &fast_swizzle_rgbx_to_32; | 
| 632                     break; | 697                     break; | 
| 633                 case kRGB_565_SkColorType: | 698                 case kRGB_565_SkColorType: | 
| 634                     proc = &swizzle_rgbx_to_565; | 699                     proc = &swizzle_rgbx_to_565; | 
| 635                 default: | 700                 default: | 
| 636                     break; | 701                     break; | 
| 637             } | 702             } | 
| 638             break; | 703             break; | 
| 639         case kRGBA: | 704         case kRGBA: | 
| 640             switch (dstInfo.colorType()) { | 705             switch (dstInfo.colorType()) { | 
| 641                 case kN32_SkColorType: | 706                 case kN32_SkColorType: | 
| 642                     if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 707                     if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { | 
| 643                         if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 708                         if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 
| 644                             proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
     _unpremul>; | 709                             proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
     _unpremul>; | 
|  | 710                             fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
     bx_to_32>; | 
| 645                         } else { | 711                         } else { | 
| 646                             proc = &swizzle_rgba_to_n32_unpremul; | 712                             proc = &swizzle_rgba_to_n32_unpremul; | 
|  | 713                             fastProc = &fast_swizzle_rgbx_to_32; | 
| 647                         } | 714                         } | 
| 648                     } else { | 715                     } else { | 
| 649                         if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 716                         if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 
| 650                             proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
     _premul>; | 717                             proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
     _premul>; | 
| 651                             fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
     ba_to_n32_premul>; | 718                             fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
     ba_to_n32_premul>; | 
| 652                         } else { | 719                         } else { | 
| 653                             proc = &swizzle_rgba_to_n32_premul; | 720                             proc = &swizzle_rgba_to_n32_premul; | 
| 654                             fastProc = &fast_swizzle_rgba_to_n32_premul; | 721                             fastProc = &fast_swizzle_rgba_to_n32_premul; | 
| 655                         } | 722                         } | 
| 656                     } | 723                     } | 
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 749 | 816 | 
| 750     return fAllocatedWidth; | 817     return fAllocatedWidth; | 
| 751 } | 818 } | 
| 752 | 819 | 
| 753 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 820 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 
| 754     SkASSERT(nullptr != dst && nullptr != src); | 821     SkASSERT(nullptr != dst && nullptr != src); | 
| 755     RowProc proc = fFastProc ? fFastProc : fProc; | 822     RowProc proc = fFastProc ? fFastProc : fProc; | 
| 756     proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, | 823     proc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP, | 
| 757             fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 824             fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 
| 758 } | 825 } | 
| OLD | NEW | 
|---|