| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 324 } |
| 325 | 325 |
| 326 static void fast_swizzle_bgra_to_n32_unpremul( | 326 static void fast_swizzle_bgra_to_n32_unpremul( |
| 327 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 327 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 328 const SkPMColor ctable[]) { | 328 const SkPMColor ctable[]) { |
| 329 | 329 |
| 330 // This function must not be called if we are sampling. If we are not | 330 // This function must not be called if we are sampling. If we are not |
| 331 // sampling, deltaSrc should equal bpp. | 331 // sampling, deltaSrc should equal bpp. |
| 332 SkASSERT(deltaSrc == bpp); | 332 SkASSERT(deltaSrc == bpp); |
| 333 | 333 |
| 334 // These swizzles trust that the alpha value is already 0xFF. | |
| 335 #ifdef SK_PMCOLOR_IS_RGBA | 334 #ifdef SK_PMCOLOR_IS_RGBA |
| 336 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); | 335 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); |
| 337 #else | 336 #else |
| 338 memcpy(dst, src + offset, width * bpp); | 337 memcpy(dst, src + offset, width * bpp); |
| 339 #endif | 338 #endif |
| 340 } | 339 } |
| 341 | 340 |
| 342 static void swizzle_bgra_to_n32_premul( | 341 static void swizzle_bgra_to_n32_premul( |
| 343 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 342 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 344 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 343 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 369 | 368 |
| 370 // kRGB | 369 // kRGB |
| 371 | 370 |
| 372 static void swizzle_rgb_to_n32( | 371 static void swizzle_rgb_to_n32( |
| 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 372 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 373 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 375 | 374 |
| 376 src += offset; | 375 src += offset; |
| 377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 376 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 378 for (int x = 0; x < dstWidth; x++) { | 377 for (int x = 0; x < dstWidth; x++) { |
| 379 dst[x] = SkPackARGB32(0xFF, src[0], src[1], src[2]); | 378 dst[x] = SkPackARGB32NoCheck(0xFF, src[0], src[1], src[2]); |
| 380 src += deltaSrc; | 379 src += deltaSrc; |
| 381 } | 380 } |
| 382 } | 381 } |
| 383 | 382 |
| 383 static void fast_swizzle_rgb_to_n32( |
| 384 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| 385 int offset, const SkPMColor ctable[]) { |
| 384 | 386 |
| 387 // This function must not be called if we are sampling. If we are not |
| 388 // sampling, deltaSrc should equal bpp. |
| 389 SkASSERT(deltaSrc == bpp); |
| 390 |
| 391 #ifdef SK_PMCOLOR_IS_RGBA |
| 392 SkOpts::RGB_to_RGB1((uint32_t*) dst, src + offset, width); |
| 393 #else |
| 394 SkOpts::RGB_to_BGR1((uint32_t*) dst, src + offset, width); |
| 395 #endif |
| 396 } |
| 385 | 397 |
| 386 static void swizzle_rgb_to_565( | 398 static void swizzle_rgb_to_565( |
| 387 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 399 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 388 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 400 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 389 | 401 |
| 390 src += offset; | 402 src += offset; |
| 391 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 403 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 392 for (int x = 0; x < dstWidth; x++) { | 404 for (int x = 0; x < dstWidth; x++) { |
| 393 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 405 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| 394 src += deltaSrc; | 406 src += deltaSrc; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 451 } |
| 440 | 452 |
| 441 static void fast_swizzle_rgba_to_n32_unpremul( | 453 static void fast_swizzle_rgba_to_n32_unpremul( |
| 442 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 454 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 443 const SkPMColor ctable[]) { | 455 const SkPMColor ctable[]) { |
| 444 | 456 |
| 445 // This function must not be called if we are sampling. If we are not | 457 // This function must not be called if we are sampling. If we are not |
| 446 // sampling, deltaSrc should equal bpp. | 458 // sampling, deltaSrc should equal bpp. |
| 447 SkASSERT(deltaSrc == bpp); | 459 SkASSERT(deltaSrc == bpp); |
| 448 | 460 |
| 449 // These swizzles trust that the alpha value is already 0xFF. | |
| 450 #ifdef SK_PMCOLOR_IS_RGBA | 461 #ifdef SK_PMCOLOR_IS_RGBA |
| 451 memcpy(dst, src + offset, width * bpp); | 462 memcpy(dst, src + offset, width * bpp); |
| 452 #else | 463 #else |
| 453 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); | 464 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); |
| 454 #endif | 465 #endif |
| 455 } | 466 } |
| 456 | 467 |
| 457 // kCMYK | 468 // kCMYK |
| 458 // | 469 // |
| 459 // CMYK is stored as four bytes per pixel. | 470 // CMYK is stored as four bytes per pixel. |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 686 } |
| 676 break; | 687 break; |
| 677 default: | 688 default: |
| 678 break; | 689 break; |
| 679 } | 690 } |
| 680 break; | 691 break; |
| 681 case kRGB: | 692 case kRGB: |
| 682 switch (dstInfo.colorType()) { | 693 switch (dstInfo.colorType()) { |
| 683 case kN32_SkColorType: | 694 case kN32_SkColorType: |
| 684 proc = &swizzle_rgb_to_n32; | 695 proc = &swizzle_rgb_to_n32; |
| 696 fastProc = &fast_swizzle_rgb_to_n32; |
| 685 break; | 697 break; |
| 686 case kRGB_565_SkColorType: | 698 case kRGB_565_SkColorType: |
| 687 proc = &swizzle_rgb_to_565; | 699 proc = &swizzle_rgb_to_565; |
| 688 default: | 700 default: |
| 689 break; | 701 break; |
| 690 } | 702 } |
| 691 break; | 703 break; |
| 692 case kRGBA: | 704 case kRGBA: |
| 693 switch (dstInfo.colorType()) { | 705 switch (dstInfo.colorType()) { |
| 694 case kN32_SkColorType: | 706 case kN32_SkColorType: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 814 } |
| 803 | 815 |
| 804 return fAllocatedWidth; | 816 return fAllocatedWidth; |
| 805 } | 817 } |
| 806 | 818 |
| 807 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 819 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 808 SkASSERT(nullptr != dst && nullptr != src); | 820 SkASSERT(nullptr != dst && nullptr != src); |
| 809 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, | 821 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, |
| 810 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 822 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 811 } | 823 } |
| OLD | NEW |