some modes need clamping due to numerical imprecision

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1710453003

TBR=

Review URL: https://codereview.chromium.org/1710453003
This commit is contained in:
reed 2016-02-17 18:02:49 -08:00 committed by Commit bot
parent e2412d5738
commit 576af8f0cc

View File

@ -320,8 +320,10 @@ static Sk4f color_4f(const Sk4f& s, const Sk4f& d) {
float Sb = sb; float Sb = sb;
SetLum(&Sr, &Sg, &Sb, sa * da, Lum(dr, dg, db) * sa); 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), Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Sr, Sg, Sb),
sa + da - sa * da); 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) { 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; float Db = db;
SetLum(&Dr, &Dg, &Db, sa * da, Lum(sr, sg, sb) * da); 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), Sk4f res = color_alpha(s * inv_alpha(d) + d * inv_alpha(s) + set_argb(0, Dr, Dg, Db),
sa + da - sa * da); 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); return Sk4f::Load(pm4.fVec);
} }
template <Sk4f (blend)(const Sk4f&, const Sk4f&)> SkPM4f proc_4f(const SkPM4f& s, const SkPM4f& d) { static void assert_unit(const SkPM4f& r) {
SkPM4f r = as_pm4f(blend(as_4f(s), as_4f(d)));
#ifdef SK_DEBUG #ifdef SK_DEBUG
const float min = 0; const float min = 0;
const float max = 1; 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); SkASSERT(r.fVec[i] >= min && r.fVec[i] <= max);
} }
#endif #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; return r;
} }