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

Unified Diff: src/core/SkXfermode.cpp

Issue 1710453003: some modes need clamping due to numerical imprecision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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/core/SkXfermode.cpp
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index 22881c6cfe94d63d3a5a5e6b3f95f9ad82a5481e..8b28f1b5150a8e03811c6863e2ef277b23952d1c 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -320,8 +320,10 @@ static Sk4f color_4f(const Sk4f& s, const Sk4f& d) {
float Sb = sb;
SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa);
- return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb),
- sa + da - sa * da);
+ Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb),
+ sa + da - sa * da);
+ // Can return tiny negative values ...
+ return Sk4f::Max(res, Sk4f(0));
}
static Sk4f luminosity_4f(const Sk4f& s, const Sk4f& d) {
@@ -340,8 +342,10 @@ static Sk4f luminosity_4f(const Sk4f& s, const Sk4f& d) {
float Db = db;
SetLum(&Dr, &Dg, &Db, sa * da, Lum(sr, sg, sb) * da);
- return color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db),
- sa + da - sa * da);
+ Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db),
+ sa + da - sa * da);
+ // Can return tiny negative values ...
+ return Sk4f::Max(res, Sk4f(0));
}
///////////////////////////////////////////////////////////////////////////////
@@ -921,8 +925,7 @@ static Sk4f as_4f(const SkPM4f& pm4) {
return Sk4f::Load(pm4.fVec);
}
-template <Sk4f (blend)(const Sk4f&, const Sk4f&)> SkPM4f proc_4f(const SkPM4f& s, const SkPM4f& d) {
- SkPM4f r = as_pm4f(blend(as_4f(s), as_4f(d)));
+static void assert_unit(const SkPM4f& r) {
#ifdef SK_DEBUG
const float min = 0;
const float max = 1;
@@ -930,6 +933,13 @@ template <Sk4f (blend)(const Sk4f&, const Sk4f&)> SkPM4f proc_4f(const SkPM4f& s
SkASSERT(r.fVec[i] >= min && r.fVec[i] <= max);
}
#endif
+}
+
+template <Sk4f (blend)(const Sk4f&, const Sk4f&)> SkPM4f proc_4f(const SkPM4f& s, const SkPM4f& d) {
+ assert_unit(s);
+ assert_unit(d);
+ SkPM4f r = as_pm4f(blend(as_4f(s), as_4f(d)));
+ assert_unit(r);
return r;
}
« 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