Skip to content

Commit

Permalink
Bug 1409440. r=tnikkel
Browse files Browse the repository at this point in the history
  • Loading branch information
aosmond committed Mar 27, 2018
1 parent 96160e3 commit 560a60c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions image/Downscaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@ Downscaler::CommitRow()
int32_t inLineToRead = filterOffset + mLinesInBuffer;
MOZ_ASSERT(mCurrentInLine <= inLineToRead, "Reading past end of input");
if (mCurrentInLine == inLineToRead) {
MOZ_RELEASE_ASSERT(mLinesInBuffer < mWindowCapacity, "Need more rows than capacity!");
mXFilter.ConvolveHorizontally(mRowBuffer.get(), mWindow[mLinesInBuffer++], mHasAlpha);
}

MOZ_ASSERT(mCurrentOutLine < mTargetSize.height,
"Writing past end of output");

while (mLinesInBuffer == filterLength) {
while (mLinesInBuffer >= filterLength) {
DownscaleInputLine();

if (mCurrentOutLine == mTargetSize.height) {
Expand Down Expand Up @@ -297,9 +298,14 @@ Downscaler::DownscaleInputLine()

// Shift the buffer. We're just moving pointers here, so this is cheap.
mLinesInBuffer -= diff;
mLinesInBuffer = max(mLinesInBuffer, 0);
for (int32_t i = 0; i < mLinesInBuffer; ++i) {
swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
mLinesInBuffer = min(max(mLinesInBuffer, 0), mWindowCapacity);

// If we already have enough rows to satisfy the filter, there is no need
// to swap as we won't be writing more before the next convolution.
if (filterLength > mLinesInBuffer) {
for (int32_t i = 0; i < mLinesInBuffer; ++i) {
swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions image/DownscalingFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,14 @@ class DownscalingFilter final : public SurfaceFilter
int32_t inputRowToRead = filterOffset + mRowsInWindow;
MOZ_ASSERT(mInputRow <= inputRowToRead, "Reading past end of input");
if (mInputRow == inputRowToRead) {
MOZ_RELEASE_ASSERT(mRowsInWindow < mWindowCapacity, "Need more rows than capacity!");
mXFilter.ConvolveHorizontally(mRowBuffer.get(), mWindow[mRowsInWindow++], mHasAlpha);
}

MOZ_ASSERT(mOutputRow < mNext.InputSize().height,
"Writing past end of output");

while (mRowsInWindow == filterLength) {
while (mRowsInWindow >= filterLength) {
DownscaleInputRow();

if (mOutputRow == mNext.InputSize().height) {
Expand Down Expand Up @@ -297,9 +298,14 @@ class DownscalingFilter final : public SurfaceFilter

// Shift the buffer. We're just moving pointers here, so this is cheap.
mRowsInWindow -= diff;
mRowsInWindow = std::max(mRowsInWindow, 0);
for (int32_t i = 0; i < mRowsInWindow; ++i) {
std::swap(mWindow[i], mWindow[filterLength - mRowsInWindow + i]);
mRowsInWindow = std::min(std::max(mRowsInWindow, 0), mWindowCapacity);

// If we already have enough rows to satisfy the filter, there is no need
// to swap as we won't be writing more before the next convolution.
if (filterLength > mRowsInWindow) {
for (int32_t i = 0; i < mRowsInWindow; ++i) {
std::swap(mWindow[i], mWindow[filterLength - mRowsInWindow + i]);
}
}
}

Expand Down

0 comments on commit 560a60c

Please sign in to comment.