fix TriColorShader to respect the paint's alpha
results can be seen in new gm: vertices_80
BUG=skia:
R=scroggo@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/270023002
git-svn-id: http://skia.googlecode.com/svn/trunk@14581 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h
index 9591f22..d5571df 100644
--- a/include/core/SkColorPriv.h
+++ b/include/core/SkColorPriv.h
@@ -181,6 +181,15 @@
return alpha + 1;
}
+/**
+ * Turn a 0..255 value into a 0..256 value, rounding up if the value is >= 0x80.
+ * This is slightly more accurate than SkAlpha255To256.
+ */
+static inline unsigned Sk255To256(U8CPU value) {
+ SkASSERT(SkToU8(value) == value);
+ return value + (value >> 7);
+}
+
/** Multiplify value by 0..256, and shift the result down 8
(i.e. return (value * alpha256) >> 8)
*/
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index a74e3c0..9347efe 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -2432,6 +2432,8 @@
return sizeof(TriColorShaderContext);
}
void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
+ const int alphaScale = Sk255To256(this->getPaintAlpha());
+
SkPoint src;
for (int i = 0; i < count; i++) {
@@ -2450,9 +2452,15 @@
scale0 = 0;
}
+ if (256 != alphaScale) {
+ scale0 = SkAlphaMul(scale0, alphaScale);
+ scale1 = SkAlphaMul(scale1, alphaScale);
+ scale2 = SkAlphaMul(scale2, alphaScale);
+ }
+
dstC[i] = SkAlphaMulQ(fColors[0], scale0) +
- SkAlphaMulQ(fColors[1], scale1) +
- SkAlphaMulQ(fColors[2], scale2);
+ SkAlphaMulQ(fColors[1], scale1) +
+ SkAlphaMulQ(fColors[2], scale2);
}
}