| 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 // This function must not be called if we are sampling. If we are not | 342 // This function must not be called if we are sampling. If we are not |
| 343 // sampling, deltaSrc should equal bpp. | 343 // sampling, deltaSrc should equal bpp. |
| 344 SkASSERT(deltaSrc == bpp); | 344 SkASSERT(deltaSrc == bpp); |
| 345 | 345 |
| 346 // Note that there is no need to distinguish between rgb and bgr. | 346 // Note that there is no need to distinguish between rgb and bgr. |
| 347 // Each color channel will get the same value. | 347 // Each color channel will get the same value. |
| 348 SkOpts::grayA_to_rgbA((uint32_t*) dst, src + offset, width); | 348 SkOpts::grayA_to_rgbA((uint32_t*) dst, src + offset, width); |
| 349 } | 349 } |
| 350 | 350 |
| 351 // kBGRX | 351 // kBGR |
| 352 | 352 |
| 353 static void swizzle_bgrx_to_n32( | 353 static void swizzle_bgr_to_565( |
| 354 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, |
| 355 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 355 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 356 | 356 |
| 357 src += offset; | |
| 358 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | |
| 359 for (int x = 0; x < dstWidth; x++) { | |
| 360 dst[x] = SkPackARGB32NoCheck(0xFF, src[2], src[1], src[0]); | |
| 361 src += deltaSrc; | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 static void swizzle_bgrx_to_565( | |
| 366 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 367 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | |
| 368 | |
| 369 src += offset; | 357 src += offset; |
| 370 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 358 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 371 for (int x = 0; x < dstWidth; x++) { | 359 for (int x = 0; x < dstWidth; x++) { |
| 372 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); | 360 dst[x] = SkPack888ToRGB16(src[2], src[1], src[0]); |
| 373 src += deltaSrc; | 361 src += deltaSrc; |
| 374 } | 362 } |
| 375 } | 363 } |
| 376 | 364 |
| 377 // kBGRA | 365 // kRGB |
| 378 | 366 |
| 379 static void swizzle_bgra_to_n32_unpremul( | 367 static void swizzle_rgb_to_rgba( |
| 380 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 368 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 381 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 369 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 382 | 370 |
| 383 src += offset; | 371 src += offset; |
| 384 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 372 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 385 for (int x = 0; x < dstWidth; x++) { | 373 for (int x = 0; x < dstWidth; x++) { |
| 386 uint8_t alpha = src[3]; | 374 dst[x] = SkPackARGB_as_RGBA(0xFF, src[0], src[1], src[2]); |
| 387 dst[x] = SkPackARGB32NoCheck(alpha, src[2], src[1], src[0]); | |
| 388 src += deltaSrc; | 375 src += deltaSrc; |
| 389 } | 376 } |
| 390 } | 377 } |
| 391 | 378 |
| 392 static void fast_swizzle_bgra_to_n32_unpremul( | 379 static void swizzle_rgb_to_bgra( |
| 393 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | |
| 394 const SkPMColor ctable[]) { | |
| 395 | |
| 396 // This function must not be called if we are sampling. If we are not | |
| 397 // sampling, deltaSrc should equal bpp. | |
| 398 SkASSERT(deltaSrc == bpp); | |
| 399 | |
| 400 #ifdef SK_PMCOLOR_IS_RGBA | |
| 401 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); | |
| 402 #else | |
| 403 memcpy(dst, src + offset, width * bpp); | |
| 404 #endif | |
| 405 } | |
| 406 | |
| 407 static void swizzle_bgra_to_n32_premul( | |
| 408 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 380 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 409 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 381 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 410 | 382 |
| 411 src += offset; | 383 src += offset; |
| 412 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 384 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 413 for (int x = 0; x < dstWidth; x++) { | 385 for (int x = 0; x < dstWidth; x++) { |
| 414 uint8_t alpha = src[3]; | 386 dst[x] = SkPackARGB_as_BGRA(0xFF, src[0], src[1], src[2]); |
| 415 dst[x] = SkPremultiplyARGBInline(alpha, src[2], src[1], src[0]); | |
| 416 src += deltaSrc; | 387 src += deltaSrc; |
| 417 } | 388 } |
| 418 } | 389 } |
| 419 | 390 |
| 420 static void fast_swizzle_bgra_to_n32_premul( | 391 static void fast_swizzle_rgb_to_rgba( |
| 421 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 392 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| 422 const SkPMColor ctable[]) { | 393 int offset, const SkPMColor ctable[]) { |
| 423 | 394 |
| 424 // This function must not be called if we are sampling. If we are not | 395 // This function must not be called if we are sampling. If we are not |
| 425 // sampling, deltaSrc should equal bpp. | 396 // sampling, deltaSrc should equal bpp. |
| 426 SkASSERT(deltaSrc == bpp); | 397 SkASSERT(deltaSrc == bpp); |
| 427 | 398 |
| 428 #ifdef SK_PMCOLOR_IS_RGBA | 399 SkOpts::RGB_to_RGB1((uint32_t*) dst, src + offset, width); |
| 429 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); | |
| 430 #else | |
| 431 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); | |
| 432 #endif | |
| 433 } | 400 } |
| 434 | 401 |
| 435 // kRGB | 402 static void fast_swizzle_rgb_to_bgra( |
| 436 | |
| 437 static void swizzle_rgb_to_n32( | |
| 438 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | |
| 439 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | |
| 440 | |
| 441 src += offset; | |
| 442 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | |
| 443 for (int x = 0; x < dstWidth; x++) { | |
| 444 dst[x] = SkPackARGB32NoCheck(0xFF, src[0], src[1], src[2]); | |
| 445 src += deltaSrc; | |
| 446 } | |
| 447 } | |
| 448 | |
| 449 static void fast_swizzle_rgb_to_n32( | |
| 450 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | 403 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| 451 int offset, const SkPMColor ctable[]) { | 404 int offset, const SkPMColor ctable[]) { |
| 452 | 405 |
| 453 // This function must not be called if we are sampling. If we are not | 406 // This function must not be called if we are sampling. If we are not |
| 454 // sampling, deltaSrc should equal bpp. | 407 // sampling, deltaSrc should equal bpp. |
| 455 SkASSERT(deltaSrc == bpp); | 408 SkASSERT(deltaSrc == bpp); |
| 456 | 409 |
| 457 #ifdef SK_PMCOLOR_IS_RGBA | |
| 458 SkOpts::RGB_to_RGB1((uint32_t*) dst, src + offset, width); | |
| 459 #else | |
| 460 SkOpts::RGB_to_BGR1((uint32_t*) dst, src + offset, width); | 410 SkOpts::RGB_to_BGR1((uint32_t*) dst, src + offset, width); |
| 461 #endif | |
| 462 } | 411 } |
| 463 | 412 |
| 464 static void swizzle_rgb_to_565( | 413 static void swizzle_rgb_to_565( |
| 465 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 414 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 466 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { | 415 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 467 | 416 |
| 468 src += offset; | 417 src += offset; |
| 469 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 418 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 470 for (int x = 0; x < dstWidth; x++) { | 419 for (int x = 0; x < dstWidth; x++) { |
| 471 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); | 420 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); |
| 472 src += deltaSrc; | 421 src += deltaSrc; |
| 473 } | 422 } |
| 474 } | 423 } |
| 475 | 424 |
| 476 // kRGBA | 425 // kRGBA |
| 477 | 426 |
| 478 static void swizzle_rgba_to_n32_premul( | 427 static void swizzle_rgba_to_rgba_premul( |
| 479 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 428 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 480 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 429 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 481 | 430 |
| 482 src += offset; | 431 src += offset; |
| 483 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 432 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 484 for (int x = 0; x < dstWidth; x++) { | 433 for (int x = 0; x < dstWidth; x++) { |
| 485 unsigned alpha = src[3]; | 434 dst[x] = premultiply_argb_as_rgba(src[3], src[0], src[1], src[2]); |
| 486 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); | |
| 487 src += deltaSrc; | 435 src += deltaSrc; |
| 488 } | 436 } |
| 489 } | 437 } |
| 490 | 438 |
| 491 static void fast_swizzle_rgba_to_n32_premul( | 439 static void swizzle_rgba_to_bgra_premul( |
| 440 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 441 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 442 |
| 443 src += offset; |
| 444 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 445 for (int x = 0; x < dstWidth; x++) { |
| 446 dst[x] = premultiply_argb_as_bgra(src[3], src[0], src[1], src[2]); |
| 447 src += deltaSrc; |
| 448 } |
| 449 } |
| 450 |
| 451 static void fast_swizzle_rgba_to_rgba_premul( |
| 492 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, | 452 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| 493 int offset, const SkPMColor ctable[]) { | 453 int offset, const SkPMColor ctable[]) { |
| 494 | 454 |
| 495 // This function must not be called if we are sampling. If we are not | 455 // This function must not be called if we are sampling. If we are not |
| 496 // sampling, deltaSrc should equal bpp. | 456 // sampling, deltaSrc should equal bpp. |
| 497 SkASSERT(deltaSrc == bpp); | 457 SkASSERT(deltaSrc == bpp); |
| 498 | 458 |
| 499 #ifdef SK_PMCOLOR_IS_RGBA | |
| 500 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); | 459 SkOpts::RGBA_to_rgbA((uint32_t*) dst, src + offset, width); |
| 501 #else | |
| 502 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); | |
| 503 #endif | |
| 504 } | 460 } |
| 505 | 461 |
| 506 static void swizzle_rgba_to_n32_unpremul( | 462 static void fast_swizzle_rgba_to_bgra_premul( |
| 463 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, |
| 464 int offset, const SkPMColor ctable[]) { |
| 465 |
| 466 // This function must not be called if we are sampling. If we are not |
| 467 // sampling, deltaSrc should equal bpp. |
| 468 SkASSERT(deltaSrc == bpp); |
| 469 |
| 470 SkOpts::RGBA_to_bgrA((uint32_t*) dst, src + offset, width); |
| 471 } |
| 472 |
| 473 static void swizzle_rgba_to_bgra_unpremul( |
| 507 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 474 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 508 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 475 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 509 | 476 |
| 510 src += offset; | 477 src += offset; |
| 511 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); | 478 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); |
| 512 for (int x = 0; x < dstWidth; x++) { | 479 for (int x = 0; x < dstWidth; x++) { |
| 513 unsigned alpha = src[3]; | 480 unsigned alpha = src[3]; |
| 514 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); | 481 dst[x] = SkPackARGB_as_BGRA(alpha, src[0], src[1], src[2]); |
| 515 src += deltaSrc; | 482 src += deltaSrc; |
| 516 } | 483 } |
| 517 } | 484 } |
| 518 | 485 |
| 519 static void fast_swizzle_rgba_to_n32_unpremul( | 486 static void fast_swizzle_rgba_to_bgra_unpremul( |
| 520 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 487 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 521 const SkPMColor ctable[]) { | 488 const SkPMColor ctable[]) { |
| 522 | 489 |
| 523 // This function must not be called if we are sampling. If we are not | 490 // This function must not be called if we are sampling. If we are not |
| 524 // sampling, deltaSrc should equal bpp. | 491 // sampling, deltaSrc should equal bpp. |
| 525 SkASSERT(deltaSrc == bpp); | 492 SkASSERT(deltaSrc == bpp); |
| 526 | 493 |
| 527 #ifdef SK_PMCOLOR_IS_RGBA | |
| 528 memcpy(dst, src + offset, width * bpp); | |
| 529 #else | |
| 530 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); | 494 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); |
| 531 #endif | |
| 532 } | 495 } |
| 533 | 496 |
| 534 // kCMYK | 497 // kCMYK |
| 535 // | 498 // |
| 536 // CMYK is stored as four bytes per pixel. | 499 // CMYK is stored as four bytes per pixel. |
| 537 // | 500 // |
| 538 // We will implement a crude conversion from CMYK -> RGB using formulas | 501 // We will implement a crude conversion from CMYK -> RGB using formulas |
| 539 // from easyrgb.com. | 502 // from easyrgb.com. |
| 540 // | 503 // |
| 541 // CMYK -> CMY | 504 // CMYK -> CMY |
| (...skipping 27 matching lines...) Expand all Loading... |
| 569 // B = Y * K * 255 | 532 // B = Y * K * 255 |
| 570 // | 533 // |
| 571 // As a final note, we have treated the CMYK values as if they were on | 534 // As a final note, we have treated the CMYK values as if they were on |
| 572 // a scale from 0-1, when in fact they are 8-bit ints scaling from 0-255. | 535 // a scale from 0-1, when in fact they are 8-bit ints scaling from 0-255. |
| 573 // We must divide each CMYK component by 255 to obtain the true conversion | 536 // We must divide each CMYK component by 255 to obtain the true conversion |
| 574 // we should perform. | 537 // we should perform. |
| 575 // CMYK -> RGB | 538 // CMYK -> RGB |
| 576 // R = C * K / 255 | 539 // R = C * K / 255 |
| 577 // G = M * K / 255 | 540 // G = M * K / 255 |
| 578 // B = Y * K / 255 | 541 // B = Y * K / 255 |
| 579 static void swizzle_cmyk_to_n32( | 542 static void swizzle_cmyk_to_rgba( |
| 580 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 543 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 581 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 544 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 582 | 545 |
| 546 src += offset; |
| 547 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 548 for (int x = 0; x < dstWidth; x++) { |
| 549 const uint8_t r = SkMulDiv255Round(src[0], src[3]); |
| 550 const uint8_t g = SkMulDiv255Round(src[1], src[3]); |
| 551 const uint8_t b = SkMulDiv255Round(src[2], src[3]); |
| 552 |
| 553 dst[x] = SkPackARGB_as_RGBA(0xFF, r, g, b); |
| 554 src += deltaSrc; |
| 555 } |
| 556 } |
| 557 |
| 558 static void swizzle_cmyk_to_bgra( |
| 559 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 560 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 561 |
| 583 src += offset; | 562 src += offset; |
| 584 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; | 563 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; |
| 585 for (int x = 0; x < dstWidth; x++) { | 564 for (int x = 0; x < dstWidth; x++) { |
| 586 const uint8_t r = SkMulDiv255Round(src[0], src[3]); | 565 const uint8_t r = SkMulDiv255Round(src[0], src[3]); |
| 587 const uint8_t g = SkMulDiv255Round(src[1], src[3]); | 566 const uint8_t g = SkMulDiv255Round(src[1], src[3]); |
| 588 const uint8_t b = SkMulDiv255Round(src[2], src[3]); | 567 const uint8_t b = SkMulDiv255Round(src[2], src[3]); |
| 589 | 568 |
| 590 dst[x] = SkPackARGB32NoCheck(0xFF, r, g, b); | 569 dst[x] = SkPackARGB_as_BGRA(0xFF, r, g, b); |
| 591 src += deltaSrc; | 570 src += deltaSrc; |
| 592 } | 571 } |
| 593 } | 572 } |
| 594 | 573 |
| 595 static void fast_swizzle_cmyk_to_n32( | 574 static void fast_swizzle_cmyk_to_rgba( |
| 596 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, | 575 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 597 const SkPMColor ctable[]) { | 576 const SkPMColor ctable[]) { |
| 598 | 577 |
| 599 // This function must not be called if we are sampling. If we are not | 578 // This function must not be called if we are sampling. If we are not |
| 600 // sampling, deltaSrc should equal bpp. | 579 // sampling, deltaSrc should equal bpp. |
| 601 SkASSERT(deltaSrc == bpp); | 580 SkASSERT(deltaSrc == bpp); |
| 602 | 581 |
| 603 #ifdef SK_PMCOLOR_IS_RGBA | |
| 604 SkOpts::inverted_CMYK_to_RGB1((uint32_t*) dst, src + offset, width); | 582 SkOpts::inverted_CMYK_to_RGB1((uint32_t*) dst, src + offset, width); |
| 605 #else | 583 } |
| 584 |
| 585 static void fast_swizzle_cmyk_to_bgra( |
| 586 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off
set, |
| 587 const SkPMColor ctable[]) { |
| 588 |
| 589 // This function must not be called if we are sampling. If we are not |
| 590 // sampling, deltaSrc should equal bpp. |
| 591 SkASSERT(deltaSrc == bpp); |
| 592 |
| 606 SkOpts::inverted_CMYK_to_BGR1((uint32_t*) dst, src + offset, width); | 593 SkOpts::inverted_CMYK_to_BGR1((uint32_t*) dst, src + offset, width); |
| 607 #endif | |
| 608 } | 594 } |
| 609 | 595 |
| 610 static void swizzle_cmyk_to_565( | 596 static void swizzle_cmyk_to_565( |
| 611 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, | 597 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, |
| 612 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { | 598 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { |
| 613 | 599 |
| 614 src += offset; | 600 src += offset; |
| 615 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; | 601 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; |
| 616 for (int x = 0; x < dstWidth; x++) { | 602 for (int x = 0; x < dstWidth; x++) { |
| 617 const uint8_t r = SkMulDiv255Round(src[0], src[3]); | 603 const uint8_t r = SkMulDiv255Round(src[0], src[3]); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 RowProc fastProc = nullptr; | 659 RowProc fastProc = nullptr; |
| 674 RowProc proc = nullptr; | 660 RowProc proc = nullptr; |
| 675 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; | 661 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; |
| 676 const bool premultiply = (SkEncodedInfo::kOpaque_Alpha != encodedInfo.alpha(
)) && | 662 const bool premultiply = (SkEncodedInfo::kOpaque_Alpha != encodedInfo.alpha(
)) && |
| 677 (kPremul_SkAlphaType == dstInfo.alphaType()); | 663 (kPremul_SkAlphaType == dstInfo.alphaType()); |
| 678 switch (encodedInfo.color()) { | 664 switch (encodedInfo.color()) { |
| 679 case SkEncodedInfo::kGray_Color: | 665 case SkEncodedInfo::kGray_Color: |
| 680 switch (encodedInfo.bitsPerComponent()) { | 666 switch (encodedInfo.bitsPerComponent()) { |
| 681 case 1: | 667 case 1: |
| 682 switch (dstInfo.colorType()) { | 668 switch (dstInfo.colorType()) { |
| 683 case kN32_SkColorType: | 669 case kRGBA_8888_SkColorType: |
| 670 case kBGRA_8888_SkColorType: |
| 684 proc = &swizzle_bit_to_n32; | 671 proc = &swizzle_bit_to_n32; |
| 685 break; | 672 break; |
| 686 case kIndex_8_SkColorType: | 673 case kIndex_8_SkColorType: |
| 687 proc = &swizzle_bit_to_index; | 674 proc = &swizzle_bit_to_index; |
| 688 break; | 675 break; |
| 689 case kRGB_565_SkColorType: | 676 case kRGB_565_SkColorType: |
| 690 proc = &swizzle_bit_to_565; | 677 proc = &swizzle_bit_to_565; |
| 691 break; | 678 break; |
| 692 case kGray_8_SkColorType: | 679 case kGray_8_SkColorType: |
| 693 proc = &swizzle_bit_to_grayscale; | 680 proc = &swizzle_bit_to_grayscale; |
| 694 break; | 681 break; |
| 695 default: | 682 default: |
| 696 return nullptr; | 683 return nullptr; |
| 697 } | 684 } |
| 698 break; | 685 break; |
| 699 case 8: | 686 case 8: |
| 700 switch (dstInfo.colorType()) { | 687 switch (dstInfo.colorType()) { |
| 701 case kN32_SkColorType: | 688 case kRGBA_8888_SkColorType: |
| 689 case kBGRA_8888_SkColorType: |
| 702 proc = &swizzle_gray_to_n32; | 690 proc = &swizzle_gray_to_n32; |
| 703 fastProc = &fast_swizzle_gray_to_n32; | 691 fastProc = &fast_swizzle_gray_to_n32; |
| 704 break; | 692 break; |
| 705 case kGray_8_SkColorType: | 693 case kGray_8_SkColorType: |
| 706 proc = &sample1; | 694 proc = &sample1; |
| 707 fastProc = © | 695 fastProc = © |
| 708 break; | 696 break; |
| 709 case kRGB_565_SkColorType: | 697 case kRGB_565_SkColorType: |
| 710 proc = &swizzle_gray_to_565; | 698 proc = &swizzle_gray_to_565; |
| 711 break; | 699 break; |
| 712 default: | 700 default: |
| 713 return nullptr; | 701 return nullptr; |
| 714 } | 702 } |
| 715 break; | 703 break; |
| 716 default: | 704 default: |
| 717 return nullptr; | 705 return nullptr; |
| 718 } | 706 } |
| 719 break; | 707 break; |
| 720 case SkEncodedInfo::kGrayAlpha_Color: | 708 case SkEncodedInfo::kGrayAlpha_Color: |
| 721 switch (dstInfo.colorType()) { | 709 switch (dstInfo.colorType()) { |
| 722 case kN32_SkColorType: | 710 case kRGBA_8888_SkColorType: |
| 711 case kBGRA_8888_SkColorType: |
| 723 if (premultiply) { | 712 if (premultiply) { |
| 724 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 713 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 725 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal
pha_to_n32_premul>; | 714 proc = &SkipLeadingGrayAlphaZerosThen<swizzle_grayal
pha_to_n32_premul>; |
| 726 fastProc = &SkipLeadingGrayAlphaZerosThen | 715 fastProc = &SkipLeadingGrayAlphaZerosThen |
| 727 <fast_swizzle_grayalpha_to_n32_premul>; | 716 <fast_swizzle_grayalpha_to_n32_premul>; |
| 728 } else { | 717 } else { |
| 729 proc = &swizzle_grayalpha_to_n32_premul; | 718 proc = &swizzle_grayalpha_to_n32_premul; |
| 730 fastProc = &fast_swizzle_grayalpha_to_n32_premul; | 719 fastProc = &fast_swizzle_grayalpha_to_n32_premul; |
| 731 } | 720 } |
| 732 } else { | 721 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 746 } | 735 } |
| 747 break; | 736 break; |
| 748 case SkEncodedInfo::kPalette_Color: | 737 case SkEncodedInfo::kPalette_Color: |
| 749 // We assume that the color table is premultiplied and swizzled | 738 // We assume that the color table is premultiplied and swizzled |
| 750 // as desired. | 739 // as desired. |
| 751 switch (encodedInfo.bitsPerComponent()) { | 740 switch (encodedInfo.bitsPerComponent()) { |
| 752 case 1: | 741 case 1: |
| 753 case 2: | 742 case 2: |
| 754 case 4: | 743 case 4: |
| 755 switch (dstInfo.colorType()) { | 744 switch (dstInfo.colorType()) { |
| 756 case kN32_SkColorType: | 745 case kRGBA_8888_SkColorType: |
| 746 case kBGRA_8888_SkColorType: |
| 757 proc = &swizzle_small_index_to_n32; | 747 proc = &swizzle_small_index_to_n32; |
| 758 break; | 748 break; |
| 759 case kRGB_565_SkColorType: | 749 case kRGB_565_SkColorType: |
| 760 proc = &swizzle_small_index_to_565; | 750 proc = &swizzle_small_index_to_565; |
| 761 break; | 751 break; |
| 762 case kIndex_8_SkColorType: | 752 case kIndex_8_SkColorType: |
| 763 proc = &swizzle_small_index_to_index; | 753 proc = &swizzle_small_index_to_index; |
| 764 break; | 754 break; |
| 765 default: | 755 default: |
| 766 return nullptr; | 756 return nullptr; |
| 767 } | 757 } |
| 768 break; | 758 break; |
| 769 case 8: | 759 case 8: |
| 770 switch (dstInfo.colorType()) { | 760 switch (dstInfo.colorType()) { |
| 771 case kN32_SkColorType: | 761 case kRGBA_8888_SkColorType: |
| 762 case kBGRA_8888_SkColorType: |
| 772 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 763 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 773 proc = &swizzle_index_to_n32_skipZ; | 764 proc = &swizzle_index_to_n32_skipZ; |
| 774 } else { | 765 } else { |
| 775 proc = &swizzle_index_to_n32; | 766 proc = &swizzle_index_to_n32; |
| 776 } | 767 } |
| 777 break; | 768 break; |
| 778 case kRGB_565_SkColorType: | 769 case kRGB_565_SkColorType: |
| 779 proc = &swizzle_index_to_565; | 770 proc = &swizzle_index_to_565; |
| 780 break; | 771 break; |
| 781 case kIndex_8_SkColorType: | 772 case kIndex_8_SkColorType: |
| 782 proc = &sample1; | 773 proc = &sample1; |
| 783 fastProc = © | 774 fastProc = © |
| 784 break; | 775 break; |
| 785 default: | 776 default: |
| 786 return nullptr; | 777 return nullptr; |
| 787 } | 778 } |
| 788 break; | 779 break; |
| 789 default: | 780 default: |
| 790 return nullptr; | 781 return nullptr; |
| 791 } | 782 } |
| 792 break; | 783 break; |
| 793 case SkEncodedInfo::kRGB_Color: | 784 case SkEncodedInfo::kRGB_Color: |
| 794 switch (dstInfo.colorType()) { | 785 switch (dstInfo.colorType()) { |
| 795 case kN32_SkColorType: | 786 case kRGBA_8888_SkColorType: |
| 796 proc = &swizzle_rgb_to_n32; | 787 proc = &swizzle_rgb_to_rgba; |
| 797 fastProc = &fast_swizzle_rgb_to_n32; | 788 fastProc = &fast_swizzle_rgb_to_rgba; |
| 789 break; |
| 790 case kBGRA_8888_SkColorType: |
| 791 proc = &swizzle_rgb_to_bgra; |
| 792 fastProc = &fast_swizzle_rgb_to_bgra; |
| 798 break; | 793 break; |
| 799 case kRGB_565_SkColorType: | 794 case kRGB_565_SkColorType: |
| 800 proc = &swizzle_rgb_to_565; | 795 proc = &swizzle_rgb_to_565; |
| 801 break; | 796 break; |
| 802 default: | 797 default: |
| 803 return nullptr; | 798 return nullptr; |
| 804 } | 799 } |
| 805 break; | 800 break; |
| 806 case SkEncodedInfo::kRGBA_Color: | 801 case SkEncodedInfo::kRGBA_Color: |
| 807 switch (dstInfo.colorType()) { | 802 switch (dstInfo.colorType()) { |
| 808 case kN32_SkColorType: | 803 case kRGBA_8888_SkColorType: |
| 809 if (premultiply) { | 804 if (premultiply) { |
| 810 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 805 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 811 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_premul>; | 806 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_rgb
a_premul>; |
| 812 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_n32_premul>; | 807 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_rgba_premul>; |
| 813 } else { | 808 } else { |
| 814 proc = &swizzle_rgba_to_n32_premul; | 809 proc = &swizzle_rgba_to_rgba_premul; |
| 815 fastProc = &fast_swizzle_rgba_to_n32_premul; | 810 fastProc = &fast_swizzle_rgba_to_rgba_premul; |
| 816 } | 811 } |
| 817 } else { | 812 } else { |
| 818 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 813 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 819 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; | 814 proc = &SkipLeading8888ZerosThen<sample4>; |
| 820 fastProc = &SkipLeading8888ZerosThen | 815 fastProc = &SkipLeading8888ZerosThen<copy>; |
| 821 <fast_swizzle_rgba_to_n32_unpremul>; | |
| 822 } else { | 816 } else { |
| 823 proc = &swizzle_rgba_to_n32_unpremul; | 817 proc = &sample4; |
| 824 fastProc = &fast_swizzle_rgba_to_n32_unpremul; | 818 fastProc = © |
| 825 } | 819 } |
| 826 } | 820 } |
| 827 break; | 821 break; |
| 822 case kBGRA_8888_SkColorType: |
| 823 if (premultiply) { |
| 824 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 825 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgr
a_premul>; |
| 826 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_bgra_premul>; |
| 827 } else { |
| 828 proc = &swizzle_rgba_to_bgra_premul; |
| 829 fastProc = &fast_swizzle_rgba_to_bgra_premul; |
| 830 } |
| 831 } else { |
| 832 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 833 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgr
a_unpremul>; |
| 834 fastProc = &SkipLeading8888ZerosThen |
| 835 <fast_swizzle_rgba_to_bgra_unpremul>; |
| 836 } else { |
| 837 proc = &swizzle_rgba_to_bgra_unpremul; |
| 838 fastProc = &fast_swizzle_rgba_to_bgra_unpremul; |
| 839 } |
| 840 } |
| 841 break; |
| 828 default: | 842 default: |
| 829 return nullptr; | 843 return nullptr; |
| 830 } | 844 } |
| 831 break; | 845 break; |
| 832 case SkEncodedInfo::kBGR_Color: | 846 case SkEncodedInfo::kBGR_Color: |
| 833 switch (dstInfo.colorType()) { | 847 switch (dstInfo.colorType()) { |
| 834 case kN32_SkColorType: | 848 case kBGRA_8888_SkColorType: |
| 835 proc = &swizzle_bgrx_to_n32; | 849 proc = &swizzle_rgb_to_rgba; |
| 850 fastProc = &fast_swizzle_rgb_to_rgba; |
| 851 break; |
| 852 case kRGBA_8888_SkColorType: |
| 853 proc = &swizzle_rgb_to_bgra; |
| 854 fastProc = &fast_swizzle_rgb_to_bgra; |
| 836 break; | 855 break; |
| 837 case kRGB_565_SkColorType: | 856 case kRGB_565_SkColorType: |
| 838 proc = &swizzle_bgrx_to_565; | 857 proc = &swizzle_bgr_to_565; |
| 839 break; | 858 break; |
| 840 default: | 859 default: |
| 841 return nullptr; | 860 return nullptr; |
| 842 } | 861 } |
| 843 break; | 862 break; |
| 844 case SkEncodedInfo::kBGRX_Color: | 863 case SkEncodedInfo::kBGRX_Color: |
| 845 switch (dstInfo.colorType()) { | 864 switch (dstInfo.colorType()) { |
| 846 case kN32_SkColorType: | 865 case kBGRA_8888_SkColorType: |
| 847 proc = &swizzle_bgrx_to_n32; | 866 proc = &swizzle_rgb_to_rgba; |
| 867 break; |
| 868 case kRGBA_8888_SkColorType: |
| 869 proc = &swizzle_rgb_to_bgra; |
| 848 break; | 870 break; |
| 849 case kRGB_565_SkColorType: | 871 case kRGB_565_SkColorType: |
| 850 proc = &swizzle_bgrx_to_565; | 872 proc = &swizzle_bgr_to_565; |
| 851 break; | 873 break; |
| 852 default: | 874 default: |
| 853 return nullptr; | 875 return nullptr; |
| 854 } | 876 } |
| 855 break; | 877 break; |
| 856 case SkEncodedInfo::kBGRA_Color: | 878 case SkEncodedInfo::kBGRA_Color: |
| 857 switch (dstInfo.colorType()) { | 879 switch (dstInfo.colorType()) { |
| 858 case kN32_SkColorType: | 880 case kBGRA_8888_SkColorType: |
| 859 if (premultiply) { | 881 if (premultiply) { |
| 860 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 882 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 861 proc = &SkipLeading8888ZerosThen<swizzle_bgra_to_n32
_premul>; | 883 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_rgb
a_premul>; |
| 862 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_bg
ra_to_n32_premul>; | 884 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_rgba_premul>; |
| 863 } else { | 885 } else { |
| 864 proc = &swizzle_bgra_to_n32_premul; | 886 proc = &swizzle_rgba_to_rgba_premul; |
| 865 fastProc = &fast_swizzle_bgra_to_n32_premul; | 887 fastProc = &fast_swizzle_rgba_to_rgba_premul; |
| 866 } | 888 } |
| 867 } else { | 889 } else { |
| 868 if (SkCodec::kYes_ZeroInitialized == zeroInit) { | 890 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 869 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_n32
_unpremul>; | 891 proc = &SkipLeading8888ZerosThen<sample4>; |
| 870 fastProc = &SkipLeading8888ZerosThen | 892 fastProc = &SkipLeading8888ZerosThen<copy>; |
| 871 <fast_swizzle_bgra_to_n32_unpremul>; | |
| 872 } else { | 893 } else { |
| 873 proc = &swizzle_bgra_to_n32_unpremul; | 894 proc = &sample4; |
| 874 fastProc = &fast_swizzle_bgra_to_n32_unpremul; | 895 fastProc = © |
| 875 } | 896 } |
| 876 } | 897 } |
| 877 break; | 898 break; |
| 899 case kRGBA_8888_SkColorType: |
| 900 if (premultiply) { |
| 901 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 902 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgr
a_premul>; |
| 903 fastProc = &SkipLeading8888ZerosThen<fast_swizzle_rg
ba_to_bgra_premul>; |
| 904 } else { |
| 905 proc = &swizzle_rgba_to_bgra_premul; |
| 906 fastProc = &fast_swizzle_rgba_to_bgra_premul; |
| 907 } |
| 908 } else { |
| 909 if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 910 proc = &SkipLeading8888ZerosThen<swizzle_rgba_to_bgr
a_unpremul>; |
| 911 fastProc = &SkipLeading8888ZerosThen |
| 912 <fast_swizzle_rgba_to_bgra_unpremul>; |
| 913 } else { |
| 914 proc = &swizzle_rgba_to_bgra_unpremul; |
| 915 fastProc = &fast_swizzle_rgba_to_bgra_unpremul; |
| 916 } |
| 917 } |
| 918 break; |
| 878 default: | 919 default: |
| 879 return nullptr; | 920 return nullptr; |
| 880 } | 921 } |
| 881 break; | 922 break; |
| 882 case SkEncodedInfo::kInvertedCMYK_Color: | 923 case SkEncodedInfo::kInvertedCMYK_Color: |
| 883 switch (dstInfo.colorType()) { | 924 switch (dstInfo.colorType()) { |
| 884 case kN32_SkColorType: | 925 case kRGBA_8888_SkColorType: |
| 885 proc = &swizzle_cmyk_to_n32; | 926 proc = &swizzle_cmyk_to_rgba; |
| 886 fastProc = &fast_swizzle_cmyk_to_n32; | 927 fastProc = &fast_swizzle_cmyk_to_rgba; |
| 928 break; |
| 929 case kBGRA_8888_SkColorType: |
| 930 proc = &swizzle_cmyk_to_bgra; |
| 931 fastProc = &fast_swizzle_cmyk_to_bgra; |
| 887 break; | 932 break; |
| 888 case kRGB_565_SkColorType: | 933 case kRGB_565_SkColorType: |
| 889 proc = &swizzle_cmyk_to_565; | 934 proc = &swizzle_cmyk_to_565; |
| 890 break; | 935 break; |
| 891 default: | 936 default: |
| 892 return nullptr; | 937 return nullptr; |
| 893 } | 938 } |
| 894 break; | 939 break; |
| 895 case SkEncodedInfo::kPreSwizzled_Color: | 940 case SkEncodedInfo::kPreSwizzled_Color: |
| 896 switch (dstInfo.colorType()) { | 941 switch (dstInfo.colorType()) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 } | 1027 } |
| 983 | 1028 |
| 984 return fAllocatedWidth; | 1029 return fAllocatedWidth; |
| 985 } | 1030 } |
| 986 | 1031 |
| 987 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { | 1032 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { |
| 988 SkASSERT(nullptr != dst && nullptr != src); | 1033 SkASSERT(nullptr != dst && nullptr != src); |
| 989 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, | 1034 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS
rcBPP, |
| 990 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); | 1035 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); |
| 991 } | 1036 } |
| OLD | NEW |