Fix the sum of alpha = 254 instead of 255 by rounding

This patch is a subpatch from https://codereview.chromium.org/2471133002/

I created this CL mainly for Florin to land before he rebaseline the Chrome
layout tests. (Landing the whole patch of 2471133002 would be nice but most
people already left for the weekend so I'd rather not take the risk to break
the Skia during the weekend.)

BUG=skia:

TBR=reed@google.com, mtklein@google.com, fmalita@chromium.org
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2483523002

Review-Url: https://codereview.chromium.org/2483523002
This commit is contained in:
liyuqian 2016-11-05 06:34:22 -07:00 committed by Commit bot
parent 2478c73bb8
commit 525e13c1d3
2 changed files with 10 additions and 5 deletions

View File

@ -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;

View File

@ -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) {