Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/effects/gradients/SkLinearGradient.cpp

Issue 2409583003: Apply linear gradient premul in 4f (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "Sk4fLinearGradient.h" 8 #include "Sk4fLinearGradient.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 #include "SkRefCnt.h" 10 #include "SkRefCnt.h"
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 rec -= 1; 520 rec -= 1;
521 SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1); 521 SkASSERT(rec[0].fPos >= 0 && rec[0].fPos <= 1);
522 SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1); 522 SkASSERT(rec[1].fPos >= 0 && rec[1].fPos <= 1);
523 SkASSERT(rec[0].fPos <= rec[1].fPos); 523 SkASSERT(rec[0].fPos <= rec[1].fPos);
524 } 524 }
525 return rec; 525 return rec;
526 } 526 }
527 527
528 template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) { 528 template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) {
529 SkPMColor c; 529 SkPMColor c;
530
531 #ifdef SK_SUPPORT_LEGACY_GRADIENT_PREMUL
530 SkNx_cast<uint8_t>(x).store(&c); 532 SkNx_cast<uint8_t>(x).store(&c);
531 if (apply_alpha) { 533 if (apply_alpha) {
532 c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c), 534 c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c),
533 SkGetPackedG32(c), SkGetPackedB32(c)); 535 SkGetPackedG32(c), SkGetPackedB32(c));
534 } 536 }
537 #else
538 Sk4f c4f255;
539 if (!apply_alpha) {
540 c4f255 = x;
541 } else {
542 // We have to pin, due to dithering bias.
543 c4f255 = Sk4f::Min(Sk4f::Max(x, Sk4f(0)), Sk4f(255));
reed1 2016/10/10 18:20:17 does the store() call also pin? Why don't we have
f(malita) 2016/10/10 18:33:18 Good question. Doesn't look like it pins, just tr
544 const float scale = c4f255[SkPM4f::A] * 1.f / 255;
545 c4f255 *= Sk4f(scale, scale, scale, 1);
546 }
547 SkNx_cast<uint8_t>(c4f255).store(&c);
548 #endif
535 return c; 549 return c;
536 } 550 }
537 551
538 template <bool apply_alpha> void fill(SkPMColor dst[], int count, 552 template <bool apply_alpha> void fill(SkPMColor dst[], int count,
539 const Sk4f& c4, const Sk4f& c4other) { 553 const Sk4f& c4, const Sk4f& c4other) {
540 sk_memset32_dither(dst, trunc_from_255<apply_alpha>(c4), 554 sk_memset32_dither(dst, trunc_from_255<apply_alpha>(c4),
541 trunc_from_255<apply_alpha>(c4other), count); 555 trunc_from_255<apply_alpha>(c4other), count);
542 } 556 }
543 557
544 template <bool apply_alpha> void fill(SkPMColor dst[], int count, const Sk4f& c4 ) { 558 template <bool apply_alpha> void fill(SkPMColor dst[], int count, const Sk4f& c4 ) {
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r); 774 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r);
761 } 775 }
762 } else { 776 } else {
763 if (fApplyAlphaAfterInterp) { 777 if (fApplyAlphaAfterInterp) {
764 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r); 778 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r);
765 } else { 779 } else {
766 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er); 780 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er);
767 } 781 }
768 } 782 }
769 } 783 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698