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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkLinearGradient.cpp
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index a249ae4ac82c2195ce2e559978cf057ce0a8377a..b6bafbf6b0dae40d440a27fcd0d1911ee26c6ec6 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -527,11 +527,25 @@ find_backward(const SkLinearGradient::LinearGradientContext::Rec rec[], float ti
template <bool apply_alpha> SkPMColor trunc_from_255(const Sk4f& x) {
SkPMColor c;
+
+#ifdef SK_SUPPORT_LEGACY_GRADIENT_PREMUL
SkNx_cast<uint8_t>(x).store(&c);
if (apply_alpha) {
c = SkPreMultiplyARGB(SkGetPackedA32(c), SkGetPackedR32(c),
SkGetPackedG32(c), SkGetPackedB32(c));
}
+#else
+ Sk4f c4f255;
+ if (!apply_alpha) {
+ c4f255 = x;
+ } else {
+ // We have to pin, due to dithering bias.
+ 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
+ const float scale = c4f255[SkPM4f::A] * 1.f / 255;
+ c4f255 *= Sk4f(scale, scale, scale, 1);
+ }
+ SkNx_cast<uint8_t>(c4f255).store(&c);
+#endif
return c;
}
« 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