aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Reed <reed@google.com>2010-03-12 14:22:51 -0500
committerMike Reed <reed@google.com>2010-03-12 14:22:51 -0500
commit4ffbc6172403ee38fc70608377ce78c9db00394a (patch)
treed04eb3706773a2a56e58d8942a35e3915fd02e9a
parentd7d0da62bf31ccc5550f526fc10c01cd24f81af9 (diff)
downloadskia-4ffbc6172403ee38fc70608377ce78c9db00394a.tar.gz
improve precision of blend
fixes http://b/issue?id=2136225 Change-Id: Ifa01a04406e1b53ffbd12a29a81445eeb60f0e60
-rw-r--r--src/effects/SkAvoidXfermode.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/effects/SkAvoidXfermode.cpp b/src/effects/SkAvoidXfermode.cpp
index d26039cec9..97bfeae0b2 100644
--- a/src/effects/SkAvoidXfermode.cpp
+++ b/src/effects/SkAvoidXfermode.cpp
@@ -116,6 +116,10 @@ static SkPMColor SkFourByteInterp(SkPMColor src, SkPMColor dst, unsigned scale)
return SkPackARGB32(a, r, g, b);
}
+static inline unsigned Accurate255To256(unsigned x) {
+ return x + (x >> 7);
+}
+
void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
const SkAlpha aa[])
{
@@ -140,14 +144,14 @@ void SkAvoidXfermode::xfer32(SkPMColor dst[], const SkPMColor src[], int count,
// now reverse d if we need to
d = MAX + (d ^ mask) - mask;
SkASSERT((unsigned)d <= 255);
- d = SkAlpha255To256(d);
+ d = Accurate255To256(d);
d = scale_dist_14(d, mul, sub);
SkASSERT(d <= 256);
if (d > 0) {
if (NULL != aa) {
- d = SkAlphaMul(d, SkAlpha255To256(*aa++));
+ d = SkAlphaMul(d, Accurate255To256(*aa++));
if (0 == d) {
continue;
}
@@ -198,7 +202,7 @@ void SkAvoidXfermode::xfer16(uint16_t dst[], const SkPMColor src[], int count,
if (d > 0) {
if (NULL != aa) {
- d = SkAlphaMul(d, SkAlpha255To256(*aa++));
+ d = SkAlphaMul(d, Accurate255To256(*aa++));
if (0 == d) {
continue;
}
@@ -239,7 +243,7 @@ void SkAvoidXfermode::xfer4444(uint16_t dst[], const SkPMColor src[], int count,
if (d > 0) {
if (NULL != aa) {
- d = SkAlphaMul(d, SkAlpha255To256(*aa++));
+ d = SkAlphaMul(d, Accurate255To256(*aa++));
if (0 == d) {
continue;
}