diff --git a/src/core/SkAntiRun.h b/src/core/SkAntiRun.h index 8214e28d5b..5ac0e62a6c 100644 --- a/src/core/SkAntiRun.h +++ b/src/core/SkAntiRun.h @@ -21,6 +21,11 @@ public: int16_t* fRuns; uint8_t* fAlpha; + // Return 0-255 given 0-256 + static inline SkAlpha CatchOverflow(int alpha) { + return alpha - (alpha >> 8); + } + /// Returns true if the scanline contains only a single run, /// of alpha value 0. bool empty() const { @@ -79,7 +84,7 @@ public: runs += x; x = 0; do { - alpha[0] = SkToU8(alpha[0] + maxValue); + alpha[0] = SkToU8(CatchOverflow(alpha[0] + maxValue)); int n = runs[0]; SkASSERT(n <= middleCount); alpha += n; diff --git a/src/core/SkScan_AAAPath.cpp b/src/core/SkScan_AAAPath.cpp index 3325249833..91b6e397ae 100644 --- a/src/core/SkScan_AAAPath.cpp +++ b/src/core/SkScan_AAAPath.cpp @@ -83,9 +83,9 @@ number of scan lines in our algorithm is only about 3 + H while the /////////////////////////////////////////////////////////////////////////////// -inline void addAlpha(SkAlpha& alpha, SkAlpha delta) { - SkASSERT(alpha + (int)delta <= 0xFF); - alpha += delta; +static inline void addAlpha(SkAlpha& alpha, SkAlpha delta) { + SkASSERT(alpha + (int)delta <= 256); + alpha = SkAlphaRuns::CatchOverflow(alpha + (int)delta); } class AdditiveBlitter : public SkBlitter { @@ -481,7 +481,7 @@ static inline SkAlpha partialTriangleToAlpha(SkFixed a, SkFixed b) { } static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkFixed partialHeight) { - return (alpha * partialHeight) >> 16; + return (alpha * partialHeight + SK_FixedHalf) >> 16; } static inline SkAlpha getPartialAlpha(SkAlpha alpha, SkAlpha fullAlpha) {