OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkPM4fPriv.h" | 8 #include "SkPM4fPriv.h" |
9 #include "SkUtils.h" | 9 #include "SkUtils.h" |
10 #include "SkXfermode.h" | 10 #include "SkXfermode.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 #ifdef SK_PMCOLOR_IS_RGBA | 434 #ifdef SK_PMCOLOR_IS_RGBA |
435 Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb), SkGetPackedB16(rg
b), 0); | 435 Sk4i rgbi = Sk4i(SkGetPackedR16(rgb), SkGetPackedG16(rgb), SkGetPackedB16(rg
b), 0); |
436 #else | 436 #else |
437 Sk4i rgbi = Sk4i(SkGetPackedB16(rgb), SkGetPackedG16(rgb), SkGetPackedR16(rg
b), 0); | 437 Sk4i rgbi = Sk4i(SkGetPackedB16(rgb), SkGetPackedG16(rgb), SkGetPackedR16(rg
b), 0); |
438 #endif | 438 #endif |
439 return SkNx_cast<float>(rgbi) * Sk4f(1.0f/31, 1.0f/63, 1.0f/31, 0); | 439 return SkNx_cast<float>(rgbi) * Sk4f(1.0f/31, 1.0f/63, 1.0f/31, 0); |
440 } | 440 } |
441 | 441 |
442 template <DstType D> | 442 template <DstType D> |
443 void src_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[
]) { | 443 void src_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t lcd[
]) { |
444 const Sk4f s4 = Sk4f::Load(src->fVec); | 444 const Sk4f s4 = src->to4f_pmorder(); |
445 | 445 |
446 if (D == kLinear_Dst) { | 446 if (D == kLinear_Dst) { |
447 // operate in bias-255 space for src and dst | 447 // operate in bias-255 space for src and dst |
448 const Sk4f s4bias = s4 * Sk4f(255); | 448 const Sk4f s4bias = s4 * Sk4f(255); |
449 for (int i = 0; i < count; ++i) { | 449 for (int i = 0; i < count; ++i) { |
450 uint16_t rgb = lcd[i]; | 450 uint16_t rgb = lcd[i]; |
451 if (0 == rgb) { | 451 if (0 == rgb) { |
452 continue; | 452 continue; |
453 } | 453 } |
454 Sk4f d4bias = to_4f(dst[i]); | 454 Sk4f d4bias = to_4f(dst[i]); |
(...skipping 11 matching lines...) Expand all Loading... |
466 } | 466 } |
467 } | 467 } |
468 | 468 |
469 template <DstType D> | 469 template <DstType D> |
470 void src_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t lcd
[]) { | 470 void src_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t lcd
[]) { |
471 for (int i = 0; i < count; ++i) { | 471 for (int i = 0; i < count; ++i) { |
472 uint16_t rgb = lcd[i]; | 472 uint16_t rgb = lcd[i]; |
473 if (0 == rgb) { | 473 if (0 == rgb) { |
474 continue; | 474 continue; |
475 } | 475 } |
476 Sk4f s4 = Sk4f::Load(src[i].fVec); | 476 Sk4f s4 = src[i].to4f_pmorder(); |
477 Sk4f d4 = load_dst<D>(dst[i]); | 477 Sk4f d4 = load_dst<D>(dst[i]); |
478 dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MAS
K << SK_A32_SHIFT); | 478 dst[i] = store_dst<D>(lerp(s4, d4, lcd16_to_unit_4f(rgb))) | (SK_A32_MAS
K << SK_A32_SHIFT); |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 template <DstType D> | 482 template <DstType D> |
483 void srcover_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t
lcd[]) { | 483 void srcover_1_lcd(uint32_t dst[], const SkPM4f* src, int count, const uint16_t
lcd[]) { |
484 const Sk4f s4 = Sk4f::Load(src->fVec); | 484 const Sk4f s4 = src->to4f_pmorder(); |
485 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); | 485 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); |
486 | 486 |
487 for (int i = 0; i < count; ++i) { | 487 for (int i = 0; i < count; ++i) { |
488 uint16_t rgb = lcd[i]; | 488 uint16_t rgb = lcd[i]; |
489 if (0 == rgb) { | 489 if (0 == rgb) { |
490 continue; | 490 continue; |
491 } | 491 } |
492 Sk4f d4 = load_dst<D>(dst[i]); | 492 Sk4f d4 = load_dst<D>(dst[i]); |
493 Sk4f r4 = s4 + d4 * dst_scale; | 493 Sk4f r4 = s4 + d4 * dst_scale; |
494 r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb)); | 494 r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb)); |
495 dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT); | 495 dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT); |
496 } | 496 } |
497 } | 497 } |
498 | 498 |
499 template <DstType D> | 499 template <DstType D> |
500 void srcover_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t
lcd[]) { | 500 void srcover_n_lcd(uint32_t dst[], const SkPM4f src[], int count, const uint16_t
lcd[]) { |
501 for (int i = 0; i < count; ++i) { | 501 for (int i = 0; i < count; ++i) { |
502 uint16_t rgb = lcd[i]; | 502 uint16_t rgb = lcd[i]; |
503 if (0 == rgb) { | 503 if (0 == rgb) { |
504 continue; | 504 continue; |
505 } | 505 } |
506 Sk4f s4 = Sk4f::Load(src[i].fVec); | 506 Sk4f s4 = src[i].to4f_pmorder(); |
507 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); | 507 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); |
508 Sk4f d4 = load_dst<D>(dst[i]); | 508 Sk4f d4 = load_dst<D>(dst[i]); |
509 Sk4f r4 = s4 + d4 * dst_scale; | 509 Sk4f r4 = s4 + d4 * dst_scale; |
510 r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb)); | 510 r4 = lerp(r4, d4, lcd16_to_unit_4f(rgb)); |
511 dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT); | 511 dst[i] = store_dst<D>(r4) | (SK_A32_MASK << SK_A32_SHIFT); |
512 } | 512 } |
513 } | 513 } |
514 | 514 |
515 SkXfermode::LCD32Proc SkXfermode::GetLCD32Proc(uint32_t flags) { | 515 SkXfermode::LCD32Proc SkXfermode::GetLCD32Proc(uint32_t flags) { |
516 SkASSERT((flags & ~7) == 0); | 516 SkASSERT((flags & ~7) == 0); |
517 flags &= 7; | 517 flags &= 7; |
518 | 518 |
519 const LCD32Proc procs[] = { | 519 const LCD32Proc procs[] = { |
520 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>, | 520 srcover_n_lcd<kSRGB_Dst>, src_n_lcd<kSRGB_Dst>, |
521 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>, | 521 srcover_1_lcd<kSRGB_Dst>, src_1_lcd<kSRGB_Dst>, |
522 | 522 |
523 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>, | 523 srcover_n_lcd<kLinear_Dst>, src_n_lcd<kLinear_Dst>, |
524 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>, | 524 srcover_1_lcd<kLinear_Dst>, src_1_lcd<kLinear_Dst>, |
525 }; | 525 }; |
526 return procs[flags]; | 526 return procs[flags]; |
527 } | 527 } |
OLD | NEW |