| 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. | 334 // These swizzles trust that the alpha value is already 0xFF. |
| 335 #ifdef SK_PMCOLOR_IS_RGBA | 335 #ifdef SK_PMCOLOR_IS_RGBA |
| 336 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); | 336 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); |
| 337 #else | 337 #else |
| 338 memcpy(dst, src + offset, width * bpp); | 338 memcpy(dst, src + offset, width * bpp); |
| 339 #endif | 339 #endif |
| 340 } | 340 } |
| 341 | 341 |
| 342 static void swizzle_bgra_to_n32_premul( | 342 static void swizzle_bgra_to_n32_premul( |
| 343 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 343 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 344 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 344 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 345 | 345 |
| 346 src += offset; | 346 src += offset; |
| 347 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 347 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 348 for (int x = 0; x < dstWidth; x++) { | 348 for (int x = 0; x < dstWidth; x++) { |
| 349 uint8_t alpha = src[3]; | 349 uint8_t alpha = src[3]; |
| 350 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | 350 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); |
| 351 src += deltaSrc; | 351 src += deltaSrc; |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 static void fast_swizzle_bgra_to_n32_premul( | 355 static void fast_swizzle_bgra_to_n32_premul( |
| 356 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 356 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 357 const SkPMColor ctable[]) { | 357 const SkPMColor ctable[]) { |
| 358 | 358 |
| 359 // This function must not be called if we are sampling. If we are not | 359 // This function must not be called if we are sampling. If we are not |
| 360 // sampling, deltaSrc should equal bpp. | 360 // sampling, deltaSrc should equal bpp. |
| 361 SkASSERT(deltaSrc == bpp); | 361 SkASSERT(deltaSrc == bpp); |
| 362 | 362 |
| 363 #ifdef SK_PMCOLOR_IS_RGBA | 363 #ifdef SK_PMCOLOR_IS_RGBA |
| 364 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset)
, width); | 364 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); |
| 365 #else | 365 #else |
| 366 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); | 366 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); |
| 367 #endif | 367 #endif |
| 368 } | 368 } |
| 369 | 369 |
| 370 // kRGB | 370 // kRGB |
| 371 | 371 |
| 372 static void swizzle_rgb_to_n32( | 372 static void swizzle_rgb_to_n32( |
| 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 375 | 375 |
| 376 src += offset; | 376 src += offset; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 412 |
| 413 static void fast_swizzle_rgba_to_n32_premul( | 413 static void fast_swizzle_rgba_to_n32_premul( |
| 414 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | 414 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| 415 int offset, const SkPMColor ctable[]) { | 415 int offset, const SkPMColor ctable[]) { |
| 416 | 416 |
| 417 // This function must not be called if we are sampling. If we are not | 417 // This function must not be called if we are sampling. If we are not |
| 418 // sampling, deltaSrc should equal bpp. | 418 // sampling, deltaSrc should equal bpp. |
| 419 SkASSERT(deltaSrc == bpp); | 419 SkASSERT(deltaSrc == bpp); |
| 420 | 420 |
| 421 #ifdef SK_PMCOLOR_IS_RGBA | 421 #ifdef SK_PMCOLOR_IS_RGBA |
| 422 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); | 422 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); |
| 423 #else | 423 #else |
| 424 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset)
, width); | 424 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); |
| 425 #endif | 425 #endif |
| 426 } | 426 } |
| 427 | 427 |
| 428 static void swizzle_rgba_to_n32_unpremul( | 428 static void swizzle_rgba_to_n32_unpremul( |
| 429 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 429 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 430 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 430 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 431 | 431 |
| 432 src += offset; | 432 src += offset; |
| 433 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 433 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 434 for (int x = 0; x < dstWidth; x++) { | 434 for (int x = 0; x < dstWidth; x++) { |
| 435 unsigned alpha = src[3]; | 435 unsigned alpha = src[3]; |
| 436 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 436 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); |
| 437 src += deltaSrc; | 437 src += deltaSrc; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 | 440 |
| 441 static void fast_swizzle_rgba_to_n32_unpremul( | 441 static void fast_swizzle_rgba_to_n32_unpremul( |
| 442 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 442 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 443 const SkPMColor ctable[]) { | 443 const SkPMColor ctable[]) { |
| 444 | 444 |
| 445 // This function must not be called if we are sampling. If we are not | 445 // This function must not be called if we are sampling. If we are not |
| 446 // sampling, deltaSrc should equal bpp. | 446 // sampling, deltaSrc should equal bpp. |
| 447 SkASSERT(deltaSrc == bpp); | 447 SkASSERT(deltaSrc == bpp); |
| 448 | 448 |
| 449 // These swizzles trust that the alpha value is already 0xFF. | 449 // These swizzles trust that the alpha value is already 0xFF. |
| 450 #ifdef SK_PMCOLOR_IS_RGBA | 450 #ifdef SK_PMCOLOR_IS_RGBA |
| 451 memcpy(dst, src + offset, width * bpp); | 451 memcpy(dst, src + offset, width * bpp); |
| 452 #else | 452 #else |
| 453 SkOpts::swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width
); | 453 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); |
| 454 #endif | 454 #endif |
| 455 } | 455 } |
| 456 | 456 |
| 457 // kCMYK | 457 // kCMYK |
| 458 // | 458 // |
| 459 // CMYK is stored as four bytes per pixel. | 459 // CMYK is stored as four bytes per pixel. |
| 460 // | 460 // |
| 461 // We will implement a crude conversion from CMYK -> RGB using formulas | 461 // We will implement a crude conversion from CMYK -> RGB using formulas |
| 462 // from easyrgb.com. | 462 // from easyrgb.com. |
| 463 // | 463 // |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 802 } |
| 803 | 803 |
| 804 return fAllocatedWidth; | 804 return fAllocatedWidth; |
| 805 } | 805 } |
| 806 | 806 |
| 807 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 807 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 808 SkASSERT(nullptr != dst && nullptr != src); | 808 SkASSERT(nullptr != dst && nullptr != src); |
| 809 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, | 809 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, |
| 810 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 810 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 811 } | 811 } |
| OLD | NEW |