Bug 739969 - Port patch from bug 633627 to use fixed point division instead of integer. r=jmuizelaar

This commit is contained in:
Joe Drew 2012-04-01 15:16:33 -04:00
parent eea30008c1
commit 55e22fdd09

View File

@ -77,6 +77,11 @@ BoxBlurHorizontal(unsigned char* aInput,
int32_t boxSize = aLeftLobe + aRightLobe + 1;
bool skipRectCoversWholeRow = 0 >= aSkipRect.x &&
aWidth <= aSkipRect.XMost();
if (boxSize == 1) {
memcpy(aOutput, aInput, aWidth*aRows);
return;
}
PRUint32 reciprocal = (PRUint64(1) << 32)/boxSize;
for (int32_t y = 0; y < aRows; y++) {
// Check whether the skip rect intersects this row. If the skip
@ -89,7 +94,7 @@ BoxBlurHorizontal(unsigned char* aInput,
continue;
}
int32_t alphaSum = 0;
uint32_t alphaSum = 0;
for (int32_t i = 0; i < boxSize; i++) {
int32_t pos = i - aLeftLobe;
// See assertion above; if aWidth is zero, then we would have no
@ -123,7 +128,7 @@ BoxBlurHorizontal(unsigned char* aInput,
int32_t last = max(tmp, 0);
int32_t next = min(tmp + boxSize, aWidth - 1);
aOutput[aWidth * y + x] = alphaSum / boxSize;
aOutput[aWidth * y + x] = (PRUint64(alphaSum)*reciprocal) >> 32;
alphaSum += aInput[aWidth * y + next] -
aInput[aWidth * y + last];
@ -150,6 +155,11 @@ BoxBlurVertical(unsigned char* aInput,
int32_t boxSize = aTopLobe + aBottomLobe + 1;
bool skipRectCoversWholeColumn = 0 >= aSkipRect.y &&
aRows <= aSkipRect.YMost();
if (boxSize == 1) {
memcpy(aOutput, aInput, aWidth*aRows);
return;
}
PRUint32 reciprocal = (PRUint64(1) << 32)/boxSize;
for (int32_t x = 0; x < aWidth; x++) {
bool inSkipRectX = x >= aSkipRect.x &&
@ -159,7 +169,7 @@ BoxBlurVertical(unsigned char* aInput,
continue;
}
int32_t alphaSum = 0;
uint32_t alphaSum = 0;
for (int32_t i = 0; i < boxSize; i++) {
int32_t pos = i - aTopLobe;
// See assertion above; if aRows is zero, then we would have no
@ -189,7 +199,7 @@ BoxBlurVertical(unsigned char* aInput,
int32_t last = max(tmp, 0);
int32_t next = min(tmp + boxSize, aRows - 1);
aOutput[aWidth * y + x] = alphaSum/boxSize;
aOutput[aWidth * y + x] = (PRUint64(alphaSum)*reciprocal) >> 32;
alphaSum += aInput[aWidth * next + x] -
aInput[aWidth * last + x];